Skip to content

Instantly share code, notes, and snippets.

@IvanaGyro
Created October 20, 2023 05:39
Show Gist options
  • Save IvanaGyro/c0d39cca5ac05fe60a202c83655ca530 to your computer and use it in GitHub Desktop.
Save IvanaGyro/c0d39cca5ac05fe60a202c83655ca530 to your computer and use it in GitHub Desktop.
Combine two A5 PDF pages to one A4 PDF page.
from pathlib import Path
from pikepdf import *
a5_pdf_path = Path('A5_PDF_PATH')
a4_output_path = Path('A4_OUTPUT_PATH')
a4_pdf = Pdf.new()
a4_pdf.add_blank_page(page_size=(595, 842))
destination_page = a4_pdf.pages[0]
with Pdf.open(a5_pdf_path) as a5_pdf:
a5_page = a5_pdf.pages[0]
a5_trimbox = Rectangle(a5_page.trimbox)
destination_page.add_overlay(a5_page, a5_trimbox)
y_offset = 421
a5_trimbox.lly += y_offset
a5_trimbox.ury += y_offset
destination_page.add_overlay(a5_page, a5_trimbox)
a4_pdf.save(a4_output_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment