Fixing PDF EOF Errors with PyPDF

Brett Bowman bnbowman at gmail.com
Mon Nov 15 00:30:38 CET 2010


Hey all, I'm trying to read a library of my company's PDFs, but about a
third of them can't be opened.  PyPDF (v1.12) spits out this error:

pyPdf.utils.PdfReadError: EOF marker not found

I searched for the answer via google, but all I found was this link:
http://lindaocta.com/?tag=pypdf.  She suggests fixing the problem by
appending an EOF marker like so:

def fixPdf(pdfFile):
    try:
        fileOpen = file(pdfFile, "a")
        fileOpen.write("%%EOF")
        fileOpen.close()
        return "Fixed"
    except Exception, e:
        return "Unable to open file: %s with error: %s" % (pdfFile, str(e))

Which appears to successfully append all of the files, as the exception is
never triggered and "Fixed" always returned,
but subsequent attempts to open the files all failed.  Yet all of those
files can be open successfully with Adobe Acrobat Reader.
Is this code inorrect or is there some other way to correct this error?  Or
does the code depend on the system?
(I'm using Windows XP, but I believe the author was using a *nix)

Sincerely,
Brett Bowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101114/cf037c21/attachment.html>


More information about the Python-list mailing list