PDF #合并 #PDF合并
#! python3# combinePdfs.py - Combines all the PDFs in the current working directory into # a single PDF.import osimport PyPDF2# Get all the PDF filenames.# file_path = './13-pdf-word/.'pdfFiles = []for filename in os.listdir('.'): if filename.endswith('.pdf'): pdfFiles.append(filename)pdfFiles.sort()pdfWriter = PyPDF2.PdfFileWriter()# Loop through all the PDF files.for filename in pdfFiles: pdfFileObj = open(filename, 'rb') pdfReader = PyPDF2.PdfFileReader(pdfFileObj) # Loop through all the pages (except the first) and add them. for pageNum in range(1, pdfReader.numPages): pageObj = pdfReader.getPage(pageNum) pdfWriter.addPage(pageObj)# Save the resulting PDF to a file.pdfOutput = open('allminutes.pdf', 'wb')pdfWriter.write(pdfOutput)print("combined ok!")pdfOutput.close()