PDFKit & PyPDF2 - 无法读取格式错误的 PDF 文件



我面临从pdfkit.from_file(文件名,'w+'(生成的pdf文件的问题。其中filename是一个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转换过程。

最新更新