When no margin detected, reserve a bit more space for comments
This commit is contained in:
1 parent
e7094d850e
commit
78a7b7679c
17 files changed
+357
-28
No files matched your search
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
import pymupdf
|
||||
|
||||
from copienator.commands.splitting_int import _prepare_split_pages
|
||||
from copienator.annotation_layout import page_parts, save_parts
|
||||
|
||||
# Percentages emitted by the GUI have six decimal places. Recover exact page
|
||||
# boundaries despite rounding, without turning nearby in-page cuts into breaks.
|
||||
@@ -35,6 +36,7 @@ def cut_position(heights: list[float], percent: float) -> tuple[int, float]:
|
||||
|
||||
def split_pdf(source: Path, percent: float, first_path: Path, second_path: Path) -> None:
|
||||
"""Preserve whole pages; clip only the page actually crossed by the cut."""
|
||||
parts = page_parts(source)
|
||||
with pymupdf.open(source) as document, pymupdf.open() as first, pymupdf.open() as second:
|
||||
index, offset = cut_position([page.rect.height for page in document], percent)
|
||||
if index:
|
||||
@@ -55,3 +57,11 @@ def split_pdf(source: Path, percent: float, first_path: Path, second_path: Path)
|
||||
second.insert_pdf(document, from_page=index + 1)
|
||||
first.save(first_path)
|
||||
second.save(second_path)
|
||||
first_parts = [dict(part) for part in parts[:index + bool(offset)]]
|
||||
second_parts = [dict(part) for part in parts[index:]]
|
||||
if offset and 'crop_points' in parts[index]:
|
||||
x0, y0, x1, y1 = parts[index]['crop_points']
|
||||
first_parts[-1]['crop_points'] = [x0, y0, x1, y0 + offset]
|
||||
second_parts[0]['crop_points'] = [x0, y0 + offset, x1, y1]
|
||||
save_parts(first_path, first_parts)
|
||||
save_parts(second_path, second_parts)
|
||||
Reference in new issue
Block a user