This commit is contained in:
2025-11-21 16:56:11 +01:00
parent d43e502710
commit d4894fde95
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
import fitz
from pathlib import Path
# =========================================
# CONFIG
# =========================================
input_path = Path(r"u:\Dropbox\Ordinace\Dokumentace_ke_zpracování\A4 expand\mericka_rotated_inplace.pdf")
output_path = input_path.with_name(input_path.stem + "_A4.pdf")
A4_WIDTH = 595.28
A4_HEIGHT = 841.89
def place_on_a4(input_pdf: Path, output_pdf: Path):
src = fitz.open(input_pdf)
dst = fitz.open()
for page in src:
# Extract actual width & height of rotated page
w = page.rect.width
h = page.rect.height
# --- SCALE to A4 width ---
scale_factor = A4_WIDTH / w
new_w = A4_WIDTH
new_h = h * scale_factor
# Create A4 page
new_page = dst.new_page(width=A4_WIDTH, height=A4_HEIGHT)
# Center vertically
x = 0
y = (A4_HEIGHT - new_h) / 2
target_rect = fitz.Rect(x, y, x + new_w, y + new_h)
# Draw original PDF onto A4 page
new_page.show_pdf_page(target_rect, src, page.number)
dst.save(output_pdf)
dst.close()
src.close()
print("Saved A4 adapted:", output_pdf)
place_on_a4(input_path, output_path)