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

BUG: page.mediabox not updating correctly when merging #636

Closed
felle9900 opened this issue Aug 23, 2021 · 8 comments
Closed

BUG: page.mediabox not updating correctly when merging #636

felle9900 opened this issue Aug 23, 2021 · 8 comments
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

Comments

@felle9900
Copy link

felle9900 commented Aug 23, 2021

I cropped a 2 page business card PDF file so most of the bleed and cropmarks where cut of.
I wanted my card to have a Trim Size of 85 x 55 mm and have a bleed of 2.5 mm.
Doing so - when I place 2 cards right next to each other, I have a 5 mm gap. This is what I want.

The cropping looked like It was doing ok, I opened the cropped pdf and it looked fine.
BUT when I try placing this cropped pdf, suddenly its placing the pages like it was never cropped!
Its placing the full original mediaBox size. Theres a bug in there somehow...
I even tried placing the cropped pdf in indesign and "brew" a new identical pdf, to se if it was a bug in the file.
The indesign pdf imported correctly showing the file as intended.

@FraPsiZeta
Copy link

I had the same problem, cropping a pdf changing mediaBox (or TrimBox or cropBox) attributes seems to work fine, saving the cropped page as a new PDF show the cropped image as intended, but merging the cropped pdf (even the one saved on file) keeps adding the original uncropped image.

@felle9900
Copy link
Author

Yeah I had to make a edit in pdf.py (pypdf2) to finally get what I wanted.

@MartinThoma
Copy link
Member

Could you make a pr with the fix? Maybe also with a unit test that shows the issue?

@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 6, 2022
@felle9900
Copy link
Author

I'm not that into githubs features yet :) But this is what I altered, in the "pdf.py" file in PyPDF2 for it to work with my needs:

Add this after line 2280 (indented) (if page1Content is not None:)

        if page2.mediaBox.getWidth() == page2.trimBox.getWidth():
            print("PyPDF2: mediaBox is equal to trimBox")
            page2Content = ContentStream(page2Content, self.pdf)
            page2Content.operations.insert(0, [map(FloatObject, [float(page2.trimBox.getLowerLeft_x()), float(page2.trimBox.getLowerLeft_y()), float(page2.trimBox.getWidth()), float(page2.trimBox.getHeight())]), "re"])
            page2Content.operations.insert(1, [[], "W"])
            page2Content.operations.insert(2, [[], "n"])
        elif page2.mediaBox.getWidth() > page2.trimBox.getWidth():
            print("PyPDF2: mediaBox is greater than trimBox")
            page2Content = ContentStream(page2Content, self.pdf)
            bleed = float(7.086614175)
            page2Content.operations.insert(0, [map(FloatObject, [float(page2.trimBox.getLowerLeft_x()) - bleed, float(page2.trimBox.getLowerLeft_y()) - bleed, float(page2.trimBox.getWidth()) + bleed + bleed, float(page2.trimBox.getHeight()) + bleed + bleed]), "re"])
            page2Content.operations.insert(1, [[], "W"])
            page2Content.operations.insert(2, [[], "n"])

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue May 16, 2022
tracked in py-pdf#636

thee smaller box between cropBox is and  trimBox(== mediaBox by default) is used
@MartinThoma MartinThoma changed the title page.mediaBox not updating correctly page.mediaBox not updating correctly when merging Jul 29, 2022
@MartinThoma MartinThoma changed the title page.mediaBox not updating correctly when merging BUG: page.mediabox not updating correctly when merging Aug 6, 2022
@Lars147
Copy link

Lars147 commented Feb 22, 2023

This is not fixed by the recent release, right?

@pubpub-zz
Copy link
Collaborator

Yes It should. as you were at the author can you close it with the reference to the good PR ? (I'm delegating now 😁)

@Lars147
Copy link

Lars147 commented Feb 23, 2023

Yes It should. as you were at the author can you close it with the reference to the good PR ? (I'm delegating now 😁)

I am sorry but I do not understand what you are referring to with "as you were at the author".

Unfortunately, I was not able to merge a cropped pdf in the desired way.

I upgraded to Release 3.4.1, where it is using the cropbox instead of trimbox for merging. However, when merging the cropped PDF it was still showing this unwanted result.

I am happy to prepare an example if desired.

@pubpub-zz
Copy link
Collaborator

this is closed by #1567

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
Projects
None yet
Development

No branches or pull requests

5 participants