Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pdf merging
#1
I am trying to make my pdf appear as page 1 being the upper half of first page, and page 2 being the lower half of first page and so on.

Currently my code just moves page 2 onto page 1 completely overlaying what was on page 1 previously.

If anyone has any suggestions on how to achieve this I'd greatly appreciate it!

from PyPDF2 import PdfFileReader, PdfFileWriter


output = PdfFileWriter()

file_name = '81plots.pdf'

file1 = PdfFileReader(open(file_name, 'rb'))
file2 = PdfFileReader(open(file_name, 'rb'))

i = 0
for i in range(file1.getNumPages()-1):
    page = file1.getPage(i)
    page.mergePage(file2.getPage(i+1))
    output.addPage(page)

outfile = 'testfile.pdf'

with open(outfile, 'wb') as file:
    output.write(file)
Reply
#2
Just guessing, would it be in the The Destination Class attributes?
see: http://pybrary.net/pyPdf/pythondoc-pyPdf.pdf.html
I know this is PyPdf and not PyPDF2, but PyPDF2's documentation points to it.
Reply
#3
If anyone is wondering the solution. I figured out by using mergeTranslatedPage() function, and by setting the mediaBox() function large enough to fit both of my pdf pages.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020