我对这个问题进行了很多搜索,但没有找到任何确切的解决方案,这就是我问这个问题的原因......
这是我使用 PyPDF2 在 python 中合并两个 pdf 文件的代码:
import os
from PyPDF2 import PdfFileReader, PdfFileMerger
files_dir = "/Users/ajayvictor/"
pdf_files = [f for f in os.listdir(files_dir) if f.endswith("pdf")]
merger = PdfFileMerger()
for filename in pdf_files:
merger.append(PdfFileReader(os.path.join(files_dir, filename), "rb"))
merger.write(os.path.join(files_dir, "merged_full.pdf"))
我在解释此代码时遇到的错误是:
Traceback (most recent call last):
File "newtest.py", line 9, in <module>
merger.append(PdfFileReader(os.path.join(files_dir, filename), "rb"))
File "/Library/Python/2.7/site-packages/PyPDF2/merger.py", line 203, in append
self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
File "/Library/Python/2.7/site-packages/PyPDF2/merger.py", line 151, in merge
outline = pdfr.getOutlines()
File "/Library/Python/2.7/site-packages/PyPDF2/pdf.py", line 1362, in getOutlines
outline = self._buildOutline(node)
File "/Library/Python/2.7/site-packages/PyPDF2/pdf.py", line 1449, in _buildOutline
raise utils.PdfReadError("Unexpected destination %r" % dest)
PyPDF2.utils.PdfReadError: Unexpected destination '/__WKANCHOR_2'