我正在尝试将 pdf 的第一页和第二页强加到第 1 页。第一页将在第二页之上,强加在第一页上。
问题是页面没有修剪或合并。最后一页强加于倒数第二个,就是这样。
from PyPDF2 import PdfFileReader, PdfFileWriter
output = PdfFileWriter()
file_name = '81plots.pdf'
file = PdfFileReader(open(file_name, 'rb'))
i = 1
for i in range(file.getNumPages()):
page = file.getPage(i-1)
page.trimBox.LowerLeft = (0, 395.28422)
page.trimBox.LowerRight = (1459.75542, 395.28422)
page.trimBox.UpperLeft = (0, 790.56844)
page.trimBox.UpperRight = (1459.75542, 790.56844)
page_step = file.getPage(i)
page_step.trimBox.LowerLeft = (0,0)
page_step.trimBox.LowerRight = (1459.75542, 0)
page_step.trimBox.UpperLeft = (0, 395.28422)
page_step.trimBox.UpperRight = (1459.75542, 395.28422)
page.mergePage(page_step)
output.addPage(page)
outfile = 'testfile.pdf'
with open(outfile, 'wb') as file:
output.write(file)