【发布时间】:2022-12-26 15:26:45
【问题描述】:
I am currently merging two pages into a single page in PyPDF3 but I need to draw a line in the middle of the two pages. Is this possible? Below is the sample code for reference. Thanks in advance!
from PyPDF3 import PdfFileWriter, PdfFileReader
from PyPDF3.pdf import PageObject
pdf_file = "Plan.pdf"
inputPDF = PdfFileReader(open(pdf_file, "rb"), strict=False)
outputPDF = PdfFileWriter()
for x in range(0, inputPDF.numPages, 2):
page1 = inputPDF.getPage(x).rotateClockwise(90)
page2 = inputPDF.getPage(x + 1).rotateClockwise(90)
total_width = max([page1.mediaBox.upperRight[0],page2.mediaBox.upperRight[0]])
total_height = page1.mediaBox.upperRight[1] + page2.mediaBox.upperRight[1]
new_page = PageObject.createBlankPage(None, total_width, total_height)
new_page.mergeTranslatedPage(page1, 0, page1.mediaBox.upperRight[1])
new_page.mergeTranslatedPage(page2, 0, 0)
outputPDF.addPage(new_page.rotateCounterClockwise(90))
outputFile = "Merged_Plan.pdf"
outputPDF.write(open(outputFile, "wb"))
【问题讨论】: