我正在使用 python 中的 pyPdf 库生成 PDF 文件。
生成文件并尝试打开它后,我将收到以下错误:不支持文件类型纯文本文档(文本/纯文本)
如果我用 .txt 重命名该文件并打开它,它将运行并显示我在文件中写入的内容。
这是代码:
from pyPdf import PdfFileWriter
output = PdfFileWriter()
outputStream = file("/home/documet_test.pdf","wb")
outputStream.write("Hello world")
outputStream.close()
我错过了什么?
最佳答案
使用reportlab库可以解决这个问题:
from reportlab.pdfgen import canvas
c = canvas.Canvas("hello.pdf")
c.drawString(100,750,"Welcome to Reportlab!")
c.save()
关于python - 使用 pyPdf 生成的 PDF 文件无法打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36216537/