I attempted to follow Getting PDF Version using Python to extract the version from a PDF file and unfortunately resulted in an error code.
I'm new to Python and have no idea how to fix this. I can view the PDF file in something like Notepad and see that it is the first line and something like %PDF-1.4 but don't know how to extract it.
The code I used was as follows:
from PyPDF2 import PdfReader
doc = PdfReader(filepath)
doc.stream.seek(0) # Necessary since the comment is ignored for the PDF analysis
print(doc.stream.readline().decode())
I expected the result to be: %PDF-1.4
I received the error code: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte