问题描述
我正面临从pdfkit.from_file(filename,'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转换过程中。