[英]PDFKit & PyPDF2 - Could not read malformed PDF file
我正面臨從 pdfkit.from_file(filename, 'w+') 生成的 pdf 文件的問題。 其中文件名是一個 html 文件。
從 html 文件生成 PDF 文件后,將它們與以下代碼合並:
merger = PdfFileMerger()
for pdf in input_files: merger.append(pdf)
merger.write(output_stream) merger.close()
這就是我遇到錯誤的地方:
File "/home/finrpt/finrpt/finrpt_py/htm_gen.py", line 193, in pdf_cat
input = PdfFileReader(f)
File "/home/finrpt/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1084, in __init__
self.read(stream)
File "/home/finrpt/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1697, in read
line = self.readNextEndLine(stream)
File "/home/finrpt/.local/lib/python3.6/site-packages/PyPDF2/pdf.py", line 1937, in readNextEndLine
raise utils.PdfReadError("Could not read malformed PDF file")
PyPDF2.utils.PdfReadError: Could not read malformed PDF file
對此問題的任何建議或指示將不勝感激。 謝謝!
如果 PDF 文檔不符合 PDF 文檔的基本結構,則它是格式錯誤的。 問題可能出在 html->pdf 轉換過程中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.