Skip to main content

flatten_document

Function flatten_document 

Source
pub fn flatten_document(
    edit: &mut EditDoc<'_>,
    limits: &Limits,
    mode: FlattenMode,
    diags: &mut Diagnostics,
) -> Result<Flattened, Error>
Expand description

Flattens every page, the way a caller who wants “no annotations left” means it.

flatten takes one page, so doing the whole document by hand means a loop that also re-prunes /AcroForm once per page. This does the loop once.

Answers Flattened::Done when any page had something to draw, and Flattened::NothingToDo only when no page did — so an empty answer means the document had no annotations anywhere, not that the last page happened to have none.

A page that fails stops the walk and returns its error; pages before it keep their edits, which are already in edit.

use pdfrum::{Document, FlattenMode, Flattened, SaveOptions};

let doc = Document::open("tests/fixtures/annotiter.pdf")?;
let mut edit = doc.edit();
assert_eq!(edit.flatten_document(FlattenMode::Display)?, Flattened::Done);

let plain = Document::open("tests/fixtures/hello_world.pdf")?;
assert_eq!(
    plain.edit().flatten_document(FlattenMode::Display)?,
    Flattened::NothingToDo,
);

§Errors

As flatten, for the first page that raises one.