1. 程式人生 > >想用python處理PDF怎麼辦?

想用python處理PDF怎麼辦?

import PyPDF2 as pdf

inputfile = "/path/to/your/pdf/file" outputfile = "/path/to/your/new/pdf/file" reader = pdf.PdfFileReader(inputfile) pages = [num1, num2, num3, ..., numn] getpages = list()

for i in pages:     page = reader.getPage(i-1) #page number starts with 0     getpages.append(page) writer = pdf.PdfFileWriter()

for page in getpages:

writer.addPage(page)

with open(outputfile,'a+') as fh:

writer.write(fh)