Move update length check before operations

This commit is contained in:
shamoon
2025-07-29 23:31:18 -04:00
parent 05f68f1522
commit 762d2da475

View File

@@ -528,6 +528,12 @@ def edit_pdf(
max_idx = max(op.get("doc", 0) for op in operations)
pdf_docs = [pikepdf.new() for _ in range(max_idx + 1)]
if update_document and len(pdf_docs) > 1:
logger.error(
"Update requested but multiple output documents specified",
)
return "ERROR"
for op in operations:
dst = pdf_docs[op.get("doc", 0)]
page = src.pages[op["page"] - 1]
@@ -536,11 +542,6 @@ def edit_pdf(
dst.pages[-1].rotate(op["rotate"], relative=True)
if update_document:
if len(pdf_docs) != 1:
logger.error(
"Update requested but multiple output documents specified",
)
return "ERROR"
pdf = pdf_docs[0]
pdf.remove_unreferenced_resources()
pdf.save(doc.source_path)