3

What I am looking to do in pyPDF is create a script that will generate a 17x11 PDF "canvas", add the 1st PDF to the left side, and the 2nd PDF to the right side.

My initial question is: What is the method to generate an output PDF that does not share the dimensions of the original PDFs? IE: How do I generate a 17x11 PDF?

My PDF guide

jumbopap
  • 3,969
  • 5
  • 27
  • 47

2 Answers2

2
input1 = PdfFileReader(open('pdf1.pdf', 'rb'))
page1 = input1.getPage(0)

input2 = PdfFileReader(open('pdf2.pdf', 'rb'))
page2 = input2.getPage(0)

page3 = PageObject.createBlankPage(None, 17*72, 11*72)
#create a blankPage size is 17*11,1 inch equal 72 px

page3.mergeScaledTranslatedPage(page1, 1, 0, 0)

#merge your pdf1 and pdf2 into the blank canvas
page3.mergeScaledTranslatedPage(page2, 1, 8.5*72, 0)
Jam lau
  • 21
  • 2
1

Use PyPDF2 with the PageObject Class.

It has a page1.mergeRotatedTranslatedPage(page2, rotation, tx, ty, expand=True) command. With expand=True the page1 will be extended.

See my answer to another question: Python PyPDF2 join pages

Community
  • 1
  • 1
Lageos
  • 183
  • 1
  • 9