-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Has MCVEA minimal, complete and verifiable example helps a lot to debug / understand feature requestsA minimal, complete and verifiable example helps a lot to debug / understand feature requestsMCVE in TestsThe MCVE was added to PyPDF2 test suiteThe MCVE was added to PyPDF2 test suiteis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Description
I'm trying to read a pdf file (of the simple pdf file)
but can't read pdf file: (Acrobat Reader program is open as normal.)
run pypdf2-test.py
$ python --version
Python 2.6.6
$ python ./pypdf2-test.py
Traceback (most recent call last):
File "./zz.py", line 3, in <module>
infile = PdfFileReader('source.pdf', 'rb')
File "/usr/lib/python2.6/site-packages/PyPDF2/pdf.py", line 1148, in __init__
self.read(stream)
File "/usr/lib/python2.6/site-packages/PyPDF2/pdf.py", line 1867, in read
idnum, generation = self.readObjectHeader(stream)
File "/usr/lib/python2.6/site-packages/PyPDF2/pdf.py", line 1731, in readObjectHeader
return int(idnum), int(generation)
ValueError: invalid literal for int() with base 10: 'n'$ cat ./pypdf2-test.py
from` PyPDF2 import PdfFileWriter, PdfFileReader
infile = PdfFileReader('source.pdf', 'rb')
output = PdfFileWriter()
for i in xrange(infile.getNumPages()):
p = infile.getPage(i)
if p.getContents(): # getContents is None if page is blank
output.addPage(p)
with open('newfile.pdf', 'wb') as f:
output.write(f)$ cat ./source.pdf (sample pdf file)
%PDF-1.1
1 0 obj
<<
/Type /Catalog
/Outlines 2 0 R
/Pages 3 0 R
/OpenAction 7 0 R
>>
endobj
2 0 obj
<<
/Type /Outlines
/Count 0
>>
endobj
3 0 obj
<<
/Type /Pages
/Kids [4 0 R]
/Count 1
>>
endobj
4 0 obj
<<
/Type /Page
/Parent 3 0 R
/MediaBox [0 0 612 792]
/Contents 5 0 R
/Resources <<
/ProcSet [/PDF /Text]
/Font << /F1 6 0 R >>
>>
>>
endobj
5 0 obj
<< /Length 56 >>
stream
BT /F1 12 Tf 100 700 Td 15 TL (test example) Tj ET
endstream
endobj
6 0 obj
<<
/Type /Font
/Subtype /Type1
/Name /F1
/BaseFont /Helvetica
/Encoding /MacRomanEncoding
>>
endobj
7 0 obj
<<
/Type /Action
/S /JavaScript
/JS (app.alert({cMsg: 'Hello alert', cTitle: 'Testing PDF', nIcon: 3});)
>>
endobj
xref
0 8
0000000000 65535 f
0000000012 00000 n
0000000109 00000 n
0000000165 00000 n
0000000234 00000 n
0000000439 00000 n
0000000553 00000 n
0000000677 00000 n
trailer
<<
/Size 8
/Root 1 0 R
>>
startxref
842
%%EOF
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Has MCVEA minimal, complete and verifiable example helps a lot to debug / understand feature requestsA minimal, complete and verifiable example helps a lot to debug / understand feature requestsMCVE in TestsThe MCVE was added to PyPDF2 test suiteThe MCVE was added to PyPDF2 test suiteis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF