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


Messages In This Thread
Pdf merging - by shaynehansen - Jul-20-2017, 03:23 PM
RE: Pdf merging - by Larz60+ - Jul-20-2017, 06:30 PM
RE: Pdf merging - by shaynehansen - Jul-21-2017, 05:16 PM

Forum Jump:

User Panel Messages

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