Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented May 1, 2021

Resolves #3565

The issue reports that the resolution argument when saving PDFs does not appear correctly when opening the resulting PDF in commercial software.

Crunching the numbers, this is because of rounding that is used by Pillow when saving a PDF.

MediaBox=[
0,
0,
int(width * 72.0 / resolution),
int(height * 72.0 / resolution),
],
Contents=contents_refs[pageNumber],
)
#
# page contents
page_contents = b"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
int(width * 72.0 / resolution),
int(height * 72.0 / resolution),
)

Searching for whether rounding needs to be used, I'm able to use GIMP to export a PDF with MediaBox float values, and I see an example at https://books.google.com.au/books?id=JJN_BAAAQBAJ&pg=PA102#v=onepage&q&f=false. As for page_contents, I see float values on page 287 of https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf

So this PR removes the rounding.

@hugovk hugovk merged commit 0836e38 into python-pillow:master May 2, 2021
@radarhere radarhere deleted the pdf_float branch May 2, 2021 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save as PDF with resolution/dpi float dpi result

2 participants