We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 trying to scale a PDF to a specific size, the objects inside do not scale properly, leaving a background that should not be visible.
It has been tested in multiple environments:
Python 3.13 with pypdf 5.1.0 and 5.2.0 Python 3.12 with various versions starting from 4.1.0
from pypdf import PageObject, Transformation, PdfReader, PdfWriter, PaperSize from pypdf.papersizes import Dimensions def main( size: Dimensions = PaperSize.A5): reader = PdfReader('bug.pdf') pages: list[PageObject] = reader.pages scaled_pages: list[PageObject] = [] for page in pages: new_page = PageObject.create_blank_page( width=size.width, height=size.height, ) sx = size.width / float(page.mediabox.width) sy = size.height / float(page.mediabox.height) transformation = Transformation().scale(sx=sx, sy=sy) new_page.merge_transformed_page(page, transformation) scaled_pages.append(new_page) writer = PdfWriter() for page in scaled_pages: writer.add_page(page) with open('example.pdf', 'wb') as file: writer.write(file) main()
bug.pdf
The text was updated successfully, but these errors were encountered:
Thanks for the report. This is a known limitation as element like images usually remain unaffected of the cm operation.
cm
I am not completely sure how feasible an automated solution would be, but you are of course invited to propose a proper solution for this.
Sorry, something went wrong.
No branches or pull requests
When trying to scale a PDF to a specific size, the objects inside do not scale properly, leaving a background that should not be visible.
Environment
It has been tested in multiple environments:
Code + PDF
bug.pdf
The text was updated successfully, but these errors were encountered: