pdf 增加和删除页面
pdf 增加和删除页面
打印几十篇论文,含有彩图页面需要彩打装订。一篇一篇论文打印太慢,想到处理如下,不知道有没有更好的办法。
合并多个pdf
用adobe acrobat pro合并多个pdf论文。合并文档后,适当位置添加空白页,确保论文第一面在奇数页。
找出彩打页面编号
统计需要彩打页面的pdf页码编号(双面打印注意奇数偶数面相邻一页),录入excel,粘贴到txt文件中,注意页码号减1,python中序号从0开始,或者修改下python代码中的list。
用python提取需要的页面
需要已安装PyPDF2模块
pip install PyPDF2安装
如下代码提取需要的页面
from PyPDF2 import PdfFileReader, PdfFileWriter
def ReadTxtName(rootdir):
lines = []
with open(rootdir, 'r') as file_to_read:
while True:
line = file_to_read.readline()
if not line:
break
line = line.strip('\n')
lines.append(line)
return lines
resultpath='需要提取的页面编号.txt' # 编号-1
lineslist=ReadTxtName(resultpath)
readfile=r"源文件.pdf"
outfile=r"需要提取的页面.pdf"
pages_to_keep = [int(x) for x in lineslist]# page numbering starts from 0
infile = PdfFileReader(readfile, 'rb')
output = PdfFileWriter()
for i in pages_to_keep:
p = infile.getPage(i)
output.addPage(p)
with open(outfile, 'wb') as f:
output.write(f)
这样就可以快速生成需要彩色打印的部分
还有更好的办法么
posted on 2021-03-25 19:53 MultiSimOpt 阅读(216) 评论(0) 收藏 举报
浙公网安备 33010602011771号