import fitz # PyMuPDF
def check_pdf_integrity(pdf_path):
try:
with fitz.open(pdf_path) as document:
_ = document.load_page(0)
return True
except Exception as e:
print(f"PDF文件损坏: {e}")
return False # 文件已损坏
if __name__ == "__main__":
pdf_path = r'I:\000移交\1.岩土工程勘察报告.pdf'
if check_pdf_integrity(pdf_path):
print(f"{pdf_path} is not corrupted.")
else:
print(f"{pdf_path} is corrupted.")
Python快速检查PDF文件是否损坏
于 2024-07-09 16:58:44 首次发布