Hello. I am trying to perform the simplest combination of two pdf-files using the PyPDF2 library, code:

 directory = 'pdfs' files = os.listdir(directory) merger = PdfFileMerger() for filename in files: merger.append(fileobj=open(os.path.join(directory, filename), 'rb')) merger.write(open(os.path.join(directory, 'book.pdf'), 'wb')) 

However, the error takes off:

 Traceback (most recent call last): File "C:\Python36-32\projects\mergePDF\merge.py", line 10, in <module> merger.append(fileobj=open(os.path.join(directory, filename), 'rb')) File "C:\Python36-32\lib\site-packages\PyPDF2\merger.py", line 203, in append self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks) File "C:\Python36-32\lib\site-packages\PyPDF2\merger.py", line 133, in merge pdfr = PdfFileReader(fileobj, strict=self.strict) File "C:\Python36-32\lib\site-packages\PyPDF2\pdf.py", line 1084, in __init__ self.read(stream) File "C:\Python36-32\lib\site-packages\PyPDF2\pdf.py", line 1689, in read stream.seek(-1, 2) OSError: [Errno 22] Invalid argument 

Google on this error, but alas, all solutions to the problem did not lead to success.

  • what happens if you call: pdfcat -o book.pdf pdfs\* ? - jfs
  • pdfcat -o book .pdf projects \ mergePDF \ pdfs \ * SyntaxError: invalid syntax (for this selects the letters that I designated in bold) - Cenzor
  • This is the command that should be executed on the command line (besides, it probably needs to be [trivially] adapted so that it starts). The purpose of the launch: get an error from the question. - jfs

0