I am using below to combine separate PDF files, into a single PDF.
It works fine however leaving all the PDFs open. How can I close the PDF files involved when the scripts ends (i.e. 4 files including the aaa, bbb, ccc and abc)?
Such as f.clos()
but I have no idea how to insert here.
from pyPdf import PdfFileWriter, PdfFileReader
def append_pdf(input,output):
[output.addPage(input.getPage(page_num)) for page_num in range(input.numPages)]
output = PdfFileWriter()
append_pdf(PdfFileReader(file("C:\\aaa.pdf","rb")),output)
append_pdf(PdfFileReader(file("c:\\bbb.pdf","rb")),output)
append_pdf(PdfFileReader(file("c:\\ccc.pdf","rb")),output)
output.write(file("c:\\abc.pdf ","wb"))
The problem is that when I tried to delete the files, Windows pops up:
the action can't be completed because the files is open in pythonw
(I am using Python 2.76 so changed the line in Robᵩ's 1st attempt to inputFile.close()
).