Skip to content
Advertisement

Why does this Traceback error come up in Python?

I am writing something that merges a PDF (in a Supplement folder) with many PDFs (in an Input folder) then saves them into an Output folder. This seems to work once taking the first PDF in the Input folder, merging it with the PDF in the Supplement folder, and saving it into the Output folder without issue. But then gives me a Traceback error and does not continue.

Seems like some issue with the for loop but I cannot seem to figure out why.

JavaScript

The error I am getting is below:

JavaScript

Edit: To be clear, the output should be many PDFs (1 per file in the Input). Each file in the Input gets the Supplement PDF merged with it then saved to Output. I re-read my post and noticed that might not have been clear.

Advertisement

Answer

You need to create a new PdfFileMerger object each time through the loop, to merge the base file with the current file in the loop.

JavaScript

os.path.join() should be used rather than string concatenation to combine directories and filenames.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement