Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EOF marker not found - How to fix in PyPDF and PyPDF2?

Tags:

python

pdf

pypdf

I'm attempting to combine a few PDF files into a single PDF file using Python. I've tried both PyPDF and PyPDF2 - on some files, they both throw this same error:

PdfReadError: EOF marker not found

Here's my code (page_files) is a list of PDF file paths to combine:

from PyPDF2 import PdfReader, PdfWriter

writer = PdfWriter()
for path in ["example1.pdf", "example2.pdf"]:
    reader = PdfReader(path)            
    for page in reader.pages:
        writer.add_page(page)            

with open("out.pdf", "wb") as fp:
    writer.write(fp)

I've read a few StackOverflow threads on the topic, but none contain a solution that works. If you've successfully combined PDF files using Python, I'd love to hear how.

like image 585
nerdburn Avatar asked Jan 31 '26 14:01

nerdburn


1 Answers

You were running in an issue of PyPDF2 which was solved with PR #321. The fix was released in PyPDF2==1.27.8 (released on 2022-04-21).

like image 62
Martin Thoma Avatar answered Feb 02 '26 06:02

Martin Thoma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!