Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Rewrite an unsigned file in full when saving after deleting pages (#3407)

srt8hellcat2-uid149d2332079
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 68fc076b9..fefa778af 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -3945,6 +3945,11 @@ impl Session {
// Signed documents are only ever saved incrementally: an edit that needs a full rewrite
// (applying redactions, changing security, sanitizing) would invalidate the signatures.
// So does any edit to a file rebuilt from object headers: it has no chain to append to.
+ // Deleted pages are freed, but an incremental save keeps them (and their text) in the
+ // earlier revision and the file does not shrink (#3407): rewrite an unsigned file in full.
+ if !signed && matches!(edit, Edit::DeletePages { .. }) {
+ next.require_full_save();
+ }
let rewrites = |c: &pdfcraft_cos::Document| c.full_save_required() || c.encryption_changed();
if signed && ((rewrites(&next) && !rewrites(&editor.cos)) || (next.is_modified() && next.revisions().is_empty())) {
return Err(EditError::SignedRewrite(edit.label().to_string()));