32 lines
959 B
Python
32 lines
959 B
Python
import fitz # PyMuPDF
|
|
|
|
LETTER_WIDTH = 792 # 11 inches at 72 points per inch
|
|
LETTER_HEIGHT = 612 # 8.5 inches at 72 points per inch
|
|
BOTTOM_MARGIN = 60
|
|
|
|
def adjust_layout(input_path, output_path, shift_amount, bottom_margin=BOTTOM_MARGIN):
|
|
doc = fitz.open(input_path)
|
|
new_doc = fitz.open()
|
|
|
|
for page in doc:
|
|
rect = page.rect
|
|
|
|
# Keep original width, enforce standard height
|
|
new_rect = fitz.Rect(0, 0, LETTER_WIDTH, LETTER_HEIGHT)
|
|
new_page = new_doc.new_page(width=new_rect.width, height=new_rect.height)
|
|
|
|
# Shift original content down by shift_amount
|
|
# Clip it back to fit on a Letter-sized page
|
|
content_rect = fitz.Rect(
|
|
0,
|
|
shift_amount,
|
|
rect.width,
|
|
rect.height + shift_amount - bottom_margin,
|
|
)
|
|
|
|
new_page.show_pdf_page(content_rect, doc, page.number)
|
|
|
|
new_doc.save(output_path)
|
|
new_doc.close()
|
|
doc.close()
|