第13章 从多个PDF中合并选择的页面

xiaoxiao2021-03-01  33

import os,PyPDF2 path = "E:\\04.AutomationProject\\PracticePython\\" pdfWriter = PyPDF2.PdfFileWriter() for currentFolder,subFoders,fileNames in os.walk(path): for fileName in fileNames: if fileName.endswith(".pdf"): filePath = os.path.join(currentFolder, fileName) print(filePath) pdfFile = open(filePath,'rb') pdfReader = PyPDF2.PdfFileReader(pdfFile) if pdfReader.isEncrypted: pdfReader.decrypt("swordFish") for pageNum in range(1,pdfReader.numPages): pdfWriter.addPage(pdfReader.getPage(pageNum)) pdfOutFile = open("1111.pdf",'wb') pdfWriter.write(pdfOutFile) pdfOutFile.close() print("====Done====")
转载请注明原文地址: https://www.6miu.com/read-4200021.html

最新回复(0)