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

Adding multiple blank pages is not supported. #1102

Closed
LethalLuggage opened this issue Jul 12, 2022 · 2 comments
Closed

Adding multiple blank pages is not supported. #1102

LethalLuggage opened this issue Jul 12, 2022 · 2 comments

Comments

@LethalLuggage
Copy link

LethalLuggage commented Jul 12, 2022

I was attempting to add a blank page every 3 pages for the purpose of splitting off letters for double-sided printing. In doing so Adobe would give me an error once I reached the second blank page.

I've isolated it to the blank pages being duplicated in the child list at the top of the pdf file. Since the blank pages themselves appear to generate properly, it appears to be an issue with where it generates the child element linkages for the document.

Notably I also learned that this is fixable by making sure every blank page has a unique size. If you use two unique sizes, it will error after reaching the first duplicated size.

Environment

Which environment were you using when you encountered the problem?
Python 3.10.0

$ python -m platform
Windows-10-10.0.19043-SP0

$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.5.0

Code + PDF

This is a minimal, complete example that shows the issue:

from PyPDF2 import PdfWriter, PdfReader

pdf_writer = PdfWriter()
pdf_in = PdfReader('inputfile.pdf')
pdf_writer.add_page(pdf_in.pages[0])
pdf_writer.add_blank_page()
pdf_writer.add_blank_page()

with open("outputfile.pdf", "wb") as out_file:
    pdf_writer.write(out_file)

Any PDF file appears to display this issue. Notably you need to load the file in adobe reader/acrobat. It loads fine in chrome, but Adobe Reader gives an error code of 14 and says it's expecting a dict object.

Binary file example

This is the correct code list of kids for my 10 letter document (40 pages total with the blank pages)

1 0 obj
<<
/Type /Pages
/Count 40
/Kids [ 3 0 R 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R 10 0 R 11 0 R 12 0 R 13 0 R 14 0 R 15 0 R 16 0 R 17 0 R 18 0 R 19 0 R 20 0 R 21 0 R 22 0 R 23 0 R 24 0 R 25 0 R 26 0 R 27 0 R 28 0 R 29 0 R 30 0 R 31 0 R 32 0 R 33 0 R 34 0 R 35 0 R 36 0 R 37 0 R 38 0 R 39 0 R 40 0 R 41 0 R 42 0 R ]
>>
endobj

This is the code that my script output for the 10 letter document (note all the 42 0 R repeats).
After modifying the 42 0 R to be a sequence instead of repeating (the objects that were created below were all correctly numbered, just not this child list), the pdf displayed fine:

<<
/Type /Pages
/Count 40
/Kids [ 3 0 R 4 0 R 5 0 R 42 0 R 7 0 R 8 0 R 9 0 R 42 0 R 11 0 R 12 0 R 13 0 R 42 0 R 15 0 R 16 0 R 17 0 R 42 0 R 19 0 R 20 0 R 21 0 R 42 0 R 23 0 R 24 0 R 25 0 R 42 0 R 27 0 R 28 0 R 29 0 R 42 0 R 31 0 R 32 0 R 33 0 R 42 0 R 35 0 R 36 0 R 37 0 R 42 0 R 39 0 R 40 0 R 41 0 R 42 0 R ]
>>
endobj
@LethalLuggage
Copy link
Author

Also of note I can't add a single page from the source document twice. It throws the same error.

@Hatell
Copy link
Contributor

Hatell commented Jul 14, 2022

Hi, seems that adobe reader/acrobat doesn't like if same page is referred more than one time.

I can't find from documentation that is not allowed. Can you test if this #1105 change resolves issue?

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

No branches or pull requests

2 participants