I get a File via a HTTP-Upload and need to be sure its a pdf-file. Programing Language is Python, but this should not matter.
I thought of the follow
It looks like pdfminer.six is a maintained project (the others, including the one below, seem dead).
ReportLab is another one (mistakenly marked as dead by me)
Since apparently neither PyPdf
nor is available anymore, the current solution I found (as of 2015) is to use PyPDF2 and catch exceptions (and possibly analyze getDocumentInfo())ReportLab
import PyPDF2
with open("testfile.txt", "w") as f:
f.write("hello world!")
try:
PyPDF2.PdfFileReader(open("testfile.txt", "rb"))
except PyPDF2.utils.PdfReadError:
print("invalid PDF file")
else:
pass