I have been creating a Python program using PyPdf2 to merge multiple pdf files.
Here is the code
import os
from PyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.endswith('pdf'):
merger.append(item)
merger.write('completed_file.pdf')
merger.close()
while running the code i encountered the following error:-
Traceback (most recent call last):
File "F:\Python folder\Pdf_Merger\main.py", line 10, in <module>
merger.append(item)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\merger.py", line 203, in append
self.merge(len(self.pages), fileobj, bookmark, pages, import_bookmarks)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\merger.py", line 151, in merge
outline = pdfr.getOutlines()
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1362, in getOutlines
outline = self._buildOutline(node)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1444, in _buildOutline
outline = self._buildDestination(title, dest)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\pdf.py", line 1425, in _buildDestination
return Destination(title, page, typ, *array)
File "F:\Python folder\Pdf_Merger\venv\lib\site-packages\PyPDF2\generic.py", line 1065, in __init__
raise utils.PdfReadError("Unknown Destination Type: %r" % typ)
PyPDF2.utils.PdfReadError: Unknown Destination Type: 0
Process finished with exit code 1
Note - I ensured that none of the pdf file is protected with password.