Python操作PDF重复N次(PyPDF2)
环境
代码
from PyPDF2 import PdfFileReader
from PyPDF2 import PdfFileWriter
def repeatPDF(pdfname):
outname = pdfname + '_out'
readFile = r'C:\Users\14215\Desktop\\' + pdfname + '.pdf'
outFile = r'C:\Users\14215\Desktop\\' + outname + '.pdf'
pdfRes = PdfFileWriter()
pdfFileReader = PdfFileReader(open(readFile, 'rb'))
for i in range(0, 100):
for index in pdfFileReader.getPage():
pageObj = pdfFileReader.getPage(index)
pdfRes.addPage(pageObj)
pdfRes.write(open(outFile, 'wb'))
if __name__ == '__main__':
while True:
pdfname = input('请输入文件名(输入stop结束):')
if pdfname == 'stop':
break
repeatPDF(pdfname)
就mark一下,好像没人做过,或者是我的搜索方式不对
|