From d4894fde957f793792bdcd2af660ad17d5075c89 Mon Sep 17 00:00:00 2001 From: "vladimir.buzalka" Date: Fri, 21 Nov 2025 16:56:11 +0100 Subject: [PATCH] Z230 --- ExtendtoA4/10 ExtendtoA4.py | 47 ++++++++++++++++ .../20 TaggDownloadedPrilohyFromMedevio.py | 56 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 ExtendtoA4/10 ExtendtoA4.py create mode 100644 RenameMedevioPrilohy/20 TaggDownloadedPrilohyFromMedevio.py diff --git a/ExtendtoA4/10 ExtendtoA4.py b/ExtendtoA4/10 ExtendtoA4.py new file mode 100644 index 0000000..4fd2fb5 --- /dev/null +++ b/ExtendtoA4/10 ExtendtoA4.py @@ -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) diff --git a/RenameMedevioPrilohy/20 TaggDownloadedPrilohyFromMedevio.py b/RenameMedevioPrilohy/20 TaggDownloadedPrilohyFromMedevio.py new file mode 100644 index 0000000..4564571 --- /dev/null +++ b/RenameMedevioPrilohy/20 TaggDownloadedPrilohyFromMedevio.py @@ -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()