pub fn modify_annotation(
edit: &mut EditDoc<'_>,
page: impl Into<PageIndex>,
annot: ObjRef,
change: impl FnOnce(&mut Dict),
) -> Result<(), Error>Expand description
Edits an annotation’s dictionary in place, keeping every key change
does not touch, and regenerates its appearance.
This is the lossless counterpart to update_annotation: update rebuilds
the dictionary from a spec and drops what the spec does not model, while
modify clones the current dictionary, hands it to change, and writes it
back with its /Popup, reply threads, custom keys and the rest intact.
After change runs, /AP is removed and generated again by the generator
add_annotation uses, so a recolour (/C, /IC), reworded /Contents
or a new /DA shows. When the subtype has no generator (an unknown
subtype, say), the original /AP is kept rather than leaving the
annotation invisible. To move an annotation without regenerating its look,
use move_annotation.
use pdfrum_edit::{EditDoc, SquareSpec, add_annotation, modify_annotation};
use pdfrum_object::{Array, Name, Object};
use kurbo::Rect;
use peniko::Color;
let r = add_annotation(
&mut edit,
0,
SquareSpec::new(Rect::new(10.0, 10.0, 40.0, 40.0), Color::from_rgb8(255, 0, 0)),
)?;
modify_annotation(&mut edit, 0, r, |dict| {
dict.insert(
Name::from("C"),
Object::Array(Array::of([Object::Real(0.0), Object::Real(0.0), Object::Real(1.0)])),
);
})?;§Errors
Error::PageIndexOutOfRange/Error::InlinePagefor a bad pageError::AnnotNotOnPagewhenannotis not listed on that page