将一个pdf文件自动等间距分割为多个文件。可以分开以后用有道翻译逐个翻译英文文献。
from PyPDF2 import PdfFileWriter, PdfFileReader
start_page = 0
end_page = 4
page_no_split = 1
fp_read_file = open('F:\\a\\barlow.pdf', "rb")
pdf_file = PdfFileReader(fp_read_file )
print('总页数为:')
pdf_pages_len = pdf_file.getNumPages()
print(pdf_pages_len)
for page in range(0,pdf_pages_len,4):
output = PdfFileWriter()
for i in range(start_page, end_page):
output.addPage(pdf_file.getPage(i))
start_page+=4
end_page+=4
if pdf_pages_len<end_page:
end_page=pdf_pages_len
outputStream = open('F:' + "\\"+"分割后的PDF" + "\\"+"a" + "\\"+ "barlow"+ str(page_no_split)+"部分"+ ".pdf", "wb")
output.write(outputStream)
page_no_split+=1
outputStream.close()
fp_read_file.close()
|