добавлено содержание
This commit is contained in:
parent
69a38caa79
commit
758cf53f93
12
pdf_merge.py
12
pdf_merge.py
@ -92,6 +92,7 @@ def merge(config_path: Path) -> None:
|
||||
|
||||
writer = PdfWriter()
|
||||
total_added = 0
|
||||
bookmarks: list[tuple[str, int]] = [] # (label, 0-based page index в результате)
|
||||
|
||||
for i, step in enumerate(steps, 1):
|
||||
if "file" not in step:
|
||||
@ -113,10 +114,13 @@ def merge(config_path: Path) -> None:
|
||||
print(f"Шаг {i} ({step['file']}): {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
label = step.get("label", "")
|
||||
if label:
|
||||
bookmarks.append((label, total_added))
|
||||
|
||||
for idx in indices:
|
||||
writer.add_page(reader.pages[idx])
|
||||
|
||||
label = step.get("label", "")
|
||||
label_str = f" [{label}]" if label else ""
|
||||
print(
|
||||
f" + {step['file']}{label_str}: "
|
||||
@ -125,6 +129,12 @@ def merge(config_path: Path) -> None:
|
||||
)
|
||||
total_added += len(indices)
|
||||
|
||||
# Добавляем закладки (содержание в боковой панели PDF-ридера)
|
||||
if bookmarks:
|
||||
for bm_label, page_idx in bookmarks:
|
||||
writer.add_outline_item(bm_label, page_idx)
|
||||
print(f"\n Содержание: {len(bookmarks)} закладок")
|
||||
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_path, "wb") as out:
|
||||
writer.write(out)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user