Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When merging pages together, clip by trimBox, which would otherwise be ignored #240

Merged
merged 1 commit into from
Apr 16, 2022

Conversation

forrestv
Copy link
Contributor

Fixes #163

@MaxLeidlTEXSIB
Copy link

MaxLeidlTEXSIB commented May 25, 2021

This fix does not work if the trimBox doesn't start at (0, 0). In those cases the code has to look like this:

page2Content = ContentStream(page2Content, self.pdf)
page2Content.operations.insert(0, [map(FloatObject, [page2.trimBox.getLowerLeft_x(), page2.trimBox.getLowerLeft_y(), page2.trimBox.getWidth() - page2.trimBox.getLowerLeft_x(), page2.trimBox.getHeight() - page2.trimBox.getLowerLeft_y()]), "re"])
page2Content.operations.insert(1, [[], "W"])
page2Content.operations.insert(2, [[], "n"])

Otherwise the clip would be smaller than expected.

@forrestv
Copy link
Contributor Author

forrestv commented May 25, 2021

Hi @MaxLeidlTEXSIB. I don't think that's correct?

image

At least, that would be pretty surprising... e.g. can you explain why width = page2.trimBox.getWidth() - page2.trimBox.getLowerLeft_x() is correct? Maybe there's another bug somewhere that you're compensating for? Namely, something else setting trimBox improperly, swapping the upper right corner for the width/height.

@MaxLeidlTEXSIB
Copy link

After looking into it further, I found out that you are right, it was just compensating for a bug in my code. Since I was working with trimBoxes with their origin != (0, 0), I added a transformation to the pdf, moving it to that point, but I wasn't aware I also had to move the trimBox manually. With this change your code works perfectly, thank you for pointing it out 😄

@MartinThoma MartinThoma added the Tiny Pull requests that make a tiny change - and thus should be easy to merge label Apr 6, 2022
@MartinThoma MartinThoma merged commit c138f21 into py-pdf:main Apr 16, 2022
@MartinThoma MartinThoma added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label Apr 16, 2022
@MartinThoma
Copy link
Member

Thank you for the PR and sorry that it took so long - it will be part of the next release (some time this month)

MartinThoma added a commit that referenced this pull request Apr 18, 2022
Deprecations (DEP):
-  Remove support for Python 2.6 and older (#776)

New Features (ENH):
-  Extract document permissions (#320)

Bug Fixes (BUG):
-  Clip by trimBox when merging pages, which would otherwise be ignored (#240)
-  Add overwriteWarnings parameter PdfFileMerger (#243)
-  IndexError for getPage() of decryped file (#359)
-  Handle cases where decodeParms is an ArrayObject (#405)
-  Updated PDF fields don't show up when page is written (#412)
-  Set Linked Form Value (#414)
-  Fix zlib -5 error for corrupt files (#603)
-  Fix reading more than last1K for EOF (#642)
-  Acciental import

Robustness (ROB):
-  Allow extra whitespace before "obj" in readObjectHeader (#567)

Documentation (DOC):
-  Link to pdftoc in Sample_Code (#628)
-  Working with annotations (#764)
-  Structure history

Developer Experience (DEV):
-  Add issue templates (#765)
-  Add tool to generate changelog

Maintenance (MAINT):
-  Use grouped constants instead of string literals (#745)
-  Add error module (#768)
-  Use decorators for @staticmethod (#775)
-  Split long functions (#777)

Testing (TST):
-  Run tests in CI once with -OO Flags (#770)
-  Filling out forms (#771)
-  Add tests for Writer (#772)
-  Error cases (#773)
-  Check Error messages (#769)
-  Regression test for issue #88
-  Regression test for issue #327

Code Style (STY):
-  Make variable naming more consistent in tests

All changes: 1.27.5...1.27.6
VictorCarlquist pushed a commit to VictorCarlquist/PyPDF2 that referenced this pull request Apr 29, 2022
Deprecations (DEP):
-  Remove support for Python 2.6 and older (py-pdf#776)

New Features (ENH):
-  Extract document permissions (py-pdf#320)

Bug Fixes (BUG):
-  Clip by trimBox when merging pages, which would otherwise be ignored (py-pdf#240)
-  Add overwriteWarnings parameter PdfFileMerger (py-pdf#243)
-  IndexError for getPage() of decryped file (py-pdf#359)
-  Handle cases where decodeParms is an ArrayObject (py-pdf#405)
-  Updated PDF fields don't show up when page is written (py-pdf#412)
-  Set Linked Form Value (py-pdf#414)
-  Fix zlib -5 error for corrupt files (py-pdf#603)
-  Fix reading more than last1K for EOF (py-pdf#642)
-  Acciental import

Robustness (ROB):
-  Allow extra whitespace before "obj" in readObjectHeader (py-pdf#567)

Documentation (DOC):
-  Link to pdftoc in Sample_Code (py-pdf#628)
-  Working with annotations (py-pdf#764)
-  Structure history

Developer Experience (DEV):
-  Add issue templates (py-pdf#765)
-  Add tool to generate changelog

Maintenance (MAINT):
-  Use grouped constants instead of string literals (py-pdf#745)
-  Add error module (py-pdf#768)
-  Use decorators for @staticmethod (py-pdf#775)
-  Split long functions (py-pdf#777)

Testing (TST):
-  Run tests in CI once with -OO Flags (py-pdf#770)
-  Filling out forms (py-pdf#771)
-  Add tests for Writer (py-pdf#772)
-  Error cases (py-pdf#773)
-  Check Error messages (py-pdf#769)
-  Regression test for issue py-pdf#88
-  Regression test for issue py-pdf#327

Code Style (STY):
-  Make variable naming more consistent in tests

All changes: py-pdf/pypdf@1.27.5...1.27.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF Tiny Pull requests that make a tiny change - and thus should be easy to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: How to merge cropped PDF page with full pdf page in PyPDF?
3 participants