Search code examples
pythonodooodoo-9pypdf

Merge Two PDF by PyPDF2 but got error Unexpected destination '/__WKANCHOR_2'


from PyPDF2 import PdfFileMerger, PdfFileReader
filepath_list = ['/tmp/abc.pdf','/tmp/xyz.pdf']
merger = PdfFileMerger()
for file_name in filepath_list:
 with open(file_name, 'rb') as f:
    merger.append(f)

merger.write("result.pdf")

While merger 2 pdf by python code I got Error Unexpected destination '/__WKANCHOR_2' and I working with following code, please provide me solution


Solution

  • This is a temporary fix, when you pass in the file in the append method, pass in import_bookmarks=False. This works for me

    from PyPDF2 import PdfFileMerger, PdfFileReader
    filepath_list = ['/tmp/abc.pdf', '/tmp/xyz.pdf']
    merger = PdfFileMerger()
    for file_name in filepath_list:
     with open(file_name, 'rb') as f:
        merger.append(f, import_bookmarks=False )
    
    merger.write("result.pdf")