Python Forum
PyPDF2, merge.append(...) problem
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyPDF2, merge.append(...) problem
#1
Greetings everyone,
I was developing a program to add Metadata to several PDF Files I have using PyPDF2, more specifically with the PdfFileMerger module. when I try to append the pdf file to the PdfFileMerger instance so I can add metadata and write to a new file, I got an error. Have a look at the code below :

from PyPDF2 import PdfFileMerger

pdffile = open('Weather2015-2016.pdf','rb')
pdfmerge = PdfFileMerger()
pdfmerge.append(pdffile) #Already tried to add additional parameters :( bookmark=None, pages=None, import_bookmarks=True) , still not working
pdfmerge.addMetadata({'/Title':'Weather Conditions'})
pdffilefinal = open('New_Weather_Conditions.pdf','wb')
pdfmerge.write(pdffilefinal)
pdffile.close()
pdffilefinal.close()
Here's the Traceback :
Error:
Traceback (most recent call last):   File "PDF_Metadata_change.py", line 5, in <module>     pdfmerge.append(pdffile)   File "build/bdist.linux-i686/egg/PyPDF2/merger.py", line 203, in append   File "build/bdist.linux-i686/egg/PyPDF2/merger.py", line 151, in merge   File "build/bdist.linux-i686/egg/PyPDF2/pdf.py", line 1362, in getOutlines   File "build/bdist.linux-i686/egg/PyPDF2/pdf.py", line 1444, in _buildOutline   File "build/bdist.linux-i686/egg/PyPDF2/pdf.py", line 1425, in _buildDestination   File "build/bdist.linux-i686/egg/PyPDF2/generic.py", line 1059, in __init__ ValueError: need more than 0 values to unpack
I'm using py2.7 on linux
Reply
#2
Just found that the script is actually working with other PDF files, the problem was then in the PDF File, even so I do not understand why, because it has content on its pages and it's not corrupted.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PyPDF2 deprecation problem gowb0w 5 3,523 Sep-21-2023, 12:38 PM
Last Post: Pedroski55
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,388 Aug-07-2023, 05:32 AM
Last Post: DPaul
  Pypdf2 will not find text standenman 2 876 Feb-03-2023, 10:52 PM
Last Post: standenman
  pyPDF2 PDFMerger close pensding file japo85 2 2,339 Jul-28-2022, 09:49 AM
Last Post: japo85
  Problem in formulating append logic shantanu97 1 999 Jun-07-2022, 08:35 AM
Last Post: ibreeden
  PyPDF2 processing problem Pavel_47 6 9,639 May-04-2021, 06:58 AM
Last Post: chaitanya
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,522 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Problem with append list in loop michaelko03 0 1,638 Feb-16-2020, 07:04 PM
Last Post: michaelko03
  Problem with installing PyPDF2 Pavel_47 2 5,945 Nov-10-2019, 02:58 PM
Last Post: Pavel_47
  pyPDF2 nautilus columns modification AJBek 1 2,866 Jun-07-2019, 04:17 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020