I have an application that converts documents(tif, docx, xlsx, etc) to pdf files. After the documents are converted they are exported to other applications (DMS, Kofax, SharePoint, etc). During export sometimes the documents generate an error (file already open by an other application). How can i check the state of an PDF document with python. I ma trying some basic stuff here to see how i can write a test application (python) to check the documents that have generated an error. Below the simple code i test with. But if i open de pdf in a PDF Reader an then run the code the PDF opens without an error. Any advice on this. How can I check if a PDF file is already opened?
import PyPDF2
try:
pdf = PyPDF2.PdfFileReader(open("test.pdf", "rb"))
except PyPDF2.utils.PdfReadError:
print("invalid PDF file")
else:
print("Valid PDF!")
print(pdf.getDocumentInfo())