EOF marker not found while use PyPDF2 merge pdf file in python

DBDBDDB picture DBDBDDB · Jul 29, 2017 · Viewed 16k times · Source

When I use the following code

from PyPDF2 import PdfFileMerger

merge = PdfFileMerger()

    for newFile in nlst:
        merge.append(newFile)
    merge.write('newFile.pdf')

Something happened as following:

raise utils.PdfReadError("EOF marker not found")

PyPDF2.utils.PdfReadError: EOF marker not found

Anybody could tell me what happened? Thanks

Answer

PatrickF picture PatrickF · Jul 31, 2017

PDF is a file format, where a pdf parser normally starts reading the file by reading some global information located at the end of the file. At the very end of the document there needs to be a line with the content of

%%EOF

This is a marker, where the pdf parser knows, that the PDF document ends here and that the global information it needs, should be before this (a startxref section).

I guess, that the error message you see, means, that one of the input documents was truncated and is missing this %%EOF-marker.