Dec-11-2021, 06:22 AM
(This post was last modified: Dec-11-2021, 09:33 PM by snippsat.
Edit Reason: Added code tag
)
I want to create the Collate (merge) PDF files from page level pdf. When i am executing the below coding it showing below error message, but 4 pdf files available in the input file path. Please help us to resolve this issue. Thanks in Advance...
Error:FileNotFoundError: [Errno 2] No such file or directory: '0001.pdf'
import contextlib import PyPDF2 import os user_input = input("Enter the path of your file: ") filePath = user_input test = [] print(filePath) pdf_files_list = os.listdir(filePath) """ for pdf in pdf_files_list: test.append(os.path.splitext(pdf)[0]) pdf_files_list = os.path.splitext(pdf) print(pdf_files_list) """ print(pdf_files_list) with contextlib.ExitStack() as stack: pdf_merger = PyPDF2.PdfFileMerger() print(pdf_merger) pdf = os.path.join(filePath) print(pdf) files = [stack.enter_context(open(pdf, 'rb')) for pdf in pdf_files_list] print(files) for f in files: pdf_merger.append(f) with open('Merged-PDF.pdf', 'wb') as f: pdf_merger.write(f)