I'm using Python 3.8.5. I'm trying to write a short script that concatenates PDF files and learning from this Stack Overflow question, I'm trying to use PyPDF2
. Unfortunately, I can't seem to even create a PyPDF2.PdfFileReader
instance without crashing.
My code looks like this:
import pathlib
import PyPDF2
pdf_path = pathlib.Path('1.pdf')
with pdf_path.open('rb') as pdf_file:
reader = PyPDF2.PdfFileReader(pdf_file, strict=False)
When I try to run it, I get the following traceback:
Traceback (most recent call last):
File "C:\...\pdf\open_pdf.py", line 6, in <module>
reader = PyPDF2.PdfFileReader(pdf_file, strict=False)
File "C:\...\.virtualenvs\pdf-j0HnXL2B\lib\site-packages\PyPDF2\pdf.py", line 1084, in __init__
self.read(stream)
File "C:\...\.virtualenvs\pdf-j0HnXL2B\lib\site-packages\PyPDF2\pdf.py", line 1883, in read
stream.seek(-11, 1)
OSError: [Errno 22] Invalid argument
To help reproduce the problem, I created this GitHub repo with the above code and a sample PDF file.
What am I doing wrong?