Skip to main content

flatten

Function flatten 

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

Bakes the page’s annotation appearances into its content and removes the annotations, the reference implementation’s way: one form XObject FFT<n> (the first such name free in the page’s /XObject resources), its box the crop box, drawing each appearance stream through the matrix that lands its box on the annotation’s rectangle; the page’s own content wrapped in q … Q with the form’s Do after it; /MediaBox and /CropBox normalized and written; the retired widgets pruned from the interactive form, which goes when it empties. A widget another page also lists keeps the form.

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

let doc = Document::open("tests/fixtures/annotiter.pdf")?;
let mut edit = doc.edit();
assert_eq!(edit.flatten(0, FlattenMode::Display)?, Flattened::Done);
let mut flat = Vec::new();
edit.write_to(&mut flat, &SaveOptions::default())?;

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

§Errors

When page is out of range or the document has no catalog.