-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Output pdf has wrong colour, incorrect translation of markup, and wrong scaling #1615
Comments
I've looked quickly and here are my conclusions: from pypdf import PdfReader, PdfWriter, Transformation, PageObject, PaperSize
from pypdf.generic import RectangleObject
reader = PdfReader("graph_letter.pdf")
page = reader.pages[0]
writer = PdfWriter()
A4_w = PaperSize.A4.width
A4_h = PaperSize.A4.height
# resize page to fit *inside* A4
h = float(page.mediabox.height)
w = float(page.mediabox.width)
scale_factor = min(A4_h/h, A4_w/w)
print(scale_factor, A4_w/2 - w*scale_factor/2 , A4_h/2 - h*scale_factor/2)
# prepare A4 blank page
page_A4 = writer.add_blank_page(width = A4_w, height = A4_h)
page_A4.merge_transformed_page(
page,
Transformation().scale(scale_factor,scale_factor).translate(
A4_w/2-w*scale_factor/2,
A4_h/2-h*scale_factor/2)
)
writer.write("graph_letter_output.pdf") Other issue detected during the test the source Annots seems to be modified, not being able to merge into a new page. |
Your suggested code works better now. Thank you. However, the colour issue is still present. Like you said, the colour is the same in Adobe Acrobat, but it is different in mac's Preview and also when i open the pdf in Chrome browser (colour is white) and also when i view in Google drive. The input file does not have this problem so the output file is also expected to be the same. |
from #1607 (comment) (@zain910128) The original input file that i provided is now converted properly and looks fine in all PDF viewers. Then i tried with a new input file which is very similar and has one extra page. Attached here for reference: The output of this file has colours all wrong in mac's Preview and google drive and the browser's pdf viewer, but fine in Adobe acrobat. So I think we have to reopen this issue. This may be related to my other issue here: |
fixes py-pdf#1615 "/N" attributes wrongly ignored
The color issue has been understand and fixed : During the copy, the field "/N" in the ICCBased attribute was not correctly copied (wrongly ignored) |
Is this fix available in the latest version if i do a pip install ? |
No it has still to be merged and released |
pypdf==3.50 was just released 🎉 |
yes but the PR was not part of it... wait for next version 😉 |
Oh, damn 😅 🙈 I'm sorry 🙈 |
I am converting a PDF to A4 paper size and the output pdf has several bugs:
The input file is:
graph_letter.pdf
The output file is:
graph_letter_output.pdf
A side by side comparison is:
I am using pypdf-3.4.0 in Google Colab.
The code used is:
Please let me know if I am doing something wrong.
The text was updated successfully, but these errors were encountered: