first working POC

This commit is contained in:
fleaz 2024-10-16 19:45:14 +02:00
parent 6952fa1a5b
commit 972fffa031

27
main.py Executable file
View file

@ -0,0 +1,27 @@
#! /usr/bin/env python3
from pypdf import PdfWriter, PdfReader, Transformation
from pypdf.generic import RectangleObject
with open("input.pdf", "rb") as in_f:
reader = PdfReader(in_f)
writer = PdfWriter()
numPages = len(reader.pages)
if numPages != 1:
exit(1)
page = reader.pages[0].rotate(90)
page = reader.pages[0]
left = 20
bottom = 450
right = 570
# calculate last value to get a 3:2 rectangle
top = bottom+((right-left)/3)*2
page.mediabox = RectangleObject((left, bottom,right,top))
writer.add_page(page)
with open("out.pdf", "wb") as fh:
writer.write(fh)