【发布时间】:2023-01-04 06:07:15
【问题描述】:
我尝试附加一个 PDF
from PyPDF2 import PdfMerger
attachment = 'C:/Users/John Doe/Desktop/test.pdf'
merger = PdfMerger()
merger.append(attachment)
它给了我这个错误。
"C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\python.exe" "C:\Users\Joe Medina\Desktop\Joseph\Geoscope\Binders\tests.py"
incorrect startxref pointer(1)
Traceback (most recent call last):
File "C:\Users\Joe Medina\Desktop\Joseph\Geoscope\Binders\tests.py", line 10, in <module>
merger.append(attachment)
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_utils.py", line 390, in wrapper
return func(*args, **kwargs)
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_merger.py", line 283, in append
self.merge(len(self.pages), fileobj, outline_item, pages, import_outline)
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_utils.py", line 390, in wrapper
return func(*args, **kwargs)
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_merger.py", line 174, in merge
pages = (0, len(reader.pages))
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_page.py", line 2033, in __len__
return self.length_function()
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_reader.py", line 446, in _get_num_pages
self._flatten()
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\_reader.py", line 1074, in _flatten
catalog = self.trailer[TK.ROOT].get_object()
File "C:\Users\Joe Medina\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\generic\_data_structures.py", line 149, in __getitem__
return dict.__getitem__(self, key).get_object()
KeyError: '/Root'
Process finished with exit code 1
我可以合并所有 PDF,除了一些特殊情况,比如这个。
奇怪的是,当我将 PDF“另存为”成同名的 PDF 时,程序运行正常。当我保存它们时,PDF 版本是一样的。
知道是什么原因造成的吗?
【问题讨论】:
-
听起来像是 PyPDF2 错误。您是否尝试过提交错误报告?
-
还没有。我再等几天再提交报告。
标签: python-3.x pypdf