- Demonter les pages : couper en 2 sans reordonner (sous Delivretiser) - Masquage visuel : selection au curseur sur l'apercu + plage de pages - Regles horizontale/verticale en mm (menu Affichage) - Fonds perdus : filigrane rouge pour visualiser les bleeds - Reperes de coupe : marques a l'exterieur (page agrandie), 2 traits/coin - Numerotation : couleur configurable via selecteur - Decalage : Trim & Shift renomme en francais, creep -> chasse - Recadrages multiples cumulatifs (plages differentes) - Fix spinbox format personnalise (fleches aleatoires) - Fix combo livret : option Automatique preservee Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""Moteur Masquage (Masking Tape) — rectangles blancs."""
|
|
|
|
from pypdf import PdfReader, PdfWriter
|
|
from reportlab.pdfgen import canvas
|
|
from .pdf_utils import get_page_size
|
|
import io
|
|
|
|
|
|
def apply_masking(input_path, output_path, rectangles, apply_to="all"):
|
|
"""Appliquer des rectangles blancs de masquage.
|
|
|
|
rectangles: liste de dicts {"x": pt, "y": pt, "width": pt, "height": pt}
|
|
apply_to: "all", "even", "odd", un numero de page (int, 1-based),
|
|
ou une liste d'indices (0-based)
|
|
"""
|
|
reader = PdfReader(input_path)
|
|
writer = PdfWriter()
|
|
|
|
for i, page in enumerate(reader.pages):
|
|
page_num = i + 1
|
|
|
|
should_apply = False
|
|
if apply_to == "all":
|
|
should_apply = True
|
|
elif apply_to == "even":
|
|
should_apply = page_num % 2 == 0
|
|
elif apply_to == "odd":
|
|
should_apply = page_num % 2 != 0
|
|
elif isinstance(apply_to, int):
|
|
should_apply = page_num == apply_to
|
|
elif isinstance(apply_to, list):
|
|
should_apply = i in apply_to
|
|
|
|
if should_apply and rectangles:
|
|
w, h = get_page_size(page)
|
|
packet = io.BytesIO()
|
|
c = canvas.Canvas(packet, pagesize=(w, h))
|
|
c.setFillColorRGB(1, 1, 1)
|
|
c.setStrokeColorRGB(1, 1, 1)
|
|
|
|
for rect in rectangles:
|
|
c.rect(rect["x"], rect["y"], rect["width"], rect["height"],
|
|
fill=1, stroke=0)
|
|
|
|
c.showPage()
|
|
c.save()
|
|
packet.seek(0)
|
|
|
|
overlay_reader = PdfReader(packet)
|
|
page.merge_page(overlay_reader.pages[0])
|
|
|
|
writer.add_page(page)
|
|
|
|
with open(output_path, "wb") as f:
|
|
writer.write(f)
|
|
return output_path
|