gpt4 book ai didi

python - 如何更正此错误 PyPDF2.utils.PdfReadError : Cannot read an empty file

转载 作者:行者123 更新时间:2023-12-04 04:09:33 26 4
gpt4 key购买 nike

我有这段返回错误的代码

packet = io.BytesIO()

c = canvas.Canvas(packet)
packet.seek(0)
new_pdf = PdfFileReader(packet)
template = PdfFileReader(open('path_to_template'), "rb")
output = PdfFileWriter()
page = template.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
outputStream = open(output_path, "wb")
output.write(outputStream)
outputStream.close()

这是细节错误

PyPDF2.utils.PdfReadError: Cannot read an empty file

最佳答案

我在尝试合并现有 pdf 模板上的文本时遇到了同样的错误。就我而言,问题是我没有保存 Canvas 。尝试添加

c.save()

之前

new_pdf = PdfFileReader(数据包)

关于python - 如何更正此错误 PyPDF2.utils.PdfReadError : Cannot read an empty file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61989105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com