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)

View File

@@ -0,0 +1,56 @@
import os
from pathlib import Path
# ==========================
# CONFIG
# ==========================
FOLDER_1 = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování")
FOLDER_2 = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování\MP")
TRIANGLE = ""
# Set to True for testing (no changes), False to really rename
DRY_RUN = True
def main():
# ---- Collect files in FOLDER_1 (top level only)
files_folder1 = [f for f in FOLDER_1.iterdir() if f.is_file()]
names_folder1 = {f.name.lower() for f in files_folder1}
# ---- Collect ALL files in FOLDER_2 (recursive)
files_folder2 = [f for f in FOLDER_2.rglob("*") if f.is_file()]
actions = [] # store what would be renamed
for file2 in files_folder2:
original_name = file2.name
lower_name = original_name.lower()
# Skip if already starts with ▲
if original_name.startswith(TRIANGLE):
continue
# Check if the filename exists in Folder 1
if lower_name in names_folder1:
new_name = TRIANGLE + original_name
new_path = file2.with_name(new_name)
actions.append((file2, new_path))
if DRY_RUN:
print(f"[DRY RUN] Would rename: {file2}{new_path}")
else:
print(f"Renaming: {file2}{new_path}")
file2.rename(new_path)
print("\n===============================")
if DRY_RUN:
print(f"DRY RUN COMPLETE — {len(actions)} file(s) would be renamed.")
else:
print(f"DONE — {len(actions)} file(s) renamed.")
print("===============================")
if __name__ == "__main__":
main()