I try to merge PDFs I have downloaded from Google Drive and I get this error:
ValueError: invalid literal for int() with base 10: b'F-1.4'
This does not happen when I merge PDFs that I generated with Keynote.
The full error reads like this:
Traceback (most recent call last):
File "weekly_meeting.py", line 36, in <module>
file_path = sort_pdf(path)
File "weekly_meeting.py", line 15, in sort_pdf
pdf_merger.append(file)
File "/usr/local/lib/python3.6/site-packages/PyPDF2/merger.py", line 203, in append
self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
File "/usr/local/lib/python3.6/site-packages/PyPDF2/merger.py", line 151, in merge
outline = pdfr.getOutlines()
File "/usr/local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1346, in getOutlines
lines = catalog["/Outlines"]
File "/usr/local/lib/python3.6/site-packages/PyPDF2/generic.py", line 516, in __getitem__
return dict.__getitem__(self, key).getObject()
File "/usr/local/lib/python3.6/site-packages/PyPDF2/generic.py", line 178, in getObject
return self.pdf.getObject(self).getObject()
File "/usr/local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1599, in getObject
idnum, generation = self.readObjectHeader(self.stream)
File "/usr/local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1667, in readObjectHeader
return int(idnum), int(generation)
ValueError: invalid literal for int() with base 10: b'F-1.4'
I tried
- opening the PDF Files - they are normal working PDF
- exporting them with Preview, again as PDF - they still produce the error
- other PDFs - they seem to work fine
This is my code, the problems seems to be the pdf_merger.append(file):
def sort_pdf(path):
pdf_merger = PdfFileMerger()
if (os.path.isdir(path)):
head, file_name = os.path.split(path)
os.chdir(path)
chronology = ["OVERVIEW", "CUSTOMER", "PROJECT", "PERSONAL"]
for prefix in chronology:
for file in glob.glob(prefix + "*.pdf"):
pdf_merger.append(file)
file_path = path + "/" + file_name + ".pdf"
with open(file_path, 'wb') as result:
pdf_merger.write(result)
return file_path
I expected the output to be a sorted and combined PDF, which I already have achieved with other documents.