#[non_exhaustive]pub enum AnnotSpec {
#[non_exhaustive] Highlight {
rect: Rect,
color: Color,
quads: Vec<Quad>,
contents: Option<String>,
},
#[non_exhaustive] Text {
rect: Rect,
color: Color,
contents: Option<String>,
icon: Name,
open: bool,
},
#[non_exhaustive] Square {
rect: Rect,
color: Color,
contents: Option<String>,
border: AnnotBorder,
interior: Option<Color>,
},
#[non_exhaustive] Underline {
rect: Rect,
color: Color,
quads: Vec<Quad>,
contents: Option<String>,
},
#[non_exhaustive] StrikeOut {
rect: Rect,
color: Color,
quads: Vec<Quad>,
contents: Option<String>,
},
#[non_exhaustive] Squiggly {
rect: Rect,
color: Color,
quads: Vec<Quad>,
contents: Option<String>,
},
#[non_exhaustive] Ink {
rect: Rect,
color: Color,
strokes: Vec<Vec<Point>>,
contents: Option<String>,
border: AnnotBorder,
},
#[non_exhaustive] FreeText {
rect: Rect,
color: Color,
contents: String,
da: String,
align: Option<Alignment>,
},
#[non_exhaustive] Circle {
rect: Rect,
color: Color,
contents: Option<String>,
border: AnnotBorder,
interior: Option<Color>,
},
#[non_exhaustive] Line {
rect: Rect,
color: Color,
start: Point,
end: Point,
contents: Option<String>,
border: AnnotBorder,
line_endings: Option<(LineEndingStyle, LineEndingStyle)>,
interior: Option<Color>,
},
#[non_exhaustive] Link {
rect: Rect,
action: AnnotLinkAction,
contents: Option<String>,
color: Option<Color>,
border: AnnotBorder,
highlight: AnnotLinkHighlight,
},
#[non_exhaustive] Caret {
rect: Rect,
color: Color,
contents: Option<String>,
},
}Expand description
What kind of annotation to create and attach to a page.
This is the write payload for add_annotation. The ISO subtype
spelling itself is pdfrum_doc::Subtype (also re-exported from the
facade): reading an annotation yields Subtype, while building one takes
an AnnotSpec variant that carries the keys that subtype needs.
Each variant carries the keys Rotero’s write_annotations needs today.
Appearance streams are generated when the subtype has a generator.
Prefer the associated constructors (highlight, text, …) over spelling
every field at the call site.
use pdfrum::{Color, Document, MarkupKind, MarkupSpec, Rect, SaveOptions};
let doc = Document::open("tests/fixtures/hello_world.pdf")?;
let mut edit = doc.edit();
let rect = Rect::new(72.0, 700.0, 200.0, 720.0);
edit.add_annotation(
0,
MarkupSpec::new(MarkupKind::Highlight, rect, Color::from_rgb8(255, 230, 0)).contents("note"),
)?;
let mut bytes = Vec::new();
edit.write_to(&mut bytes, &SaveOptions::default())?;Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]Highlight
A highlight over one or more text runs (/Subtype /Highlight).
/QuadPoints is required and must hold at least one quadrilateral.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Text
A sticky-note text annotation (/Subtype /Text).
Defaults to /Name /Comment and /Open false (see TextSpec).
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Square
A square / area annotation (/Subtype /Square).
Writes /BS with AnnotBorder (default width 2, solid) and
/Type /Border.
Fields
This variant is marked as non-exhaustive
border: AnnotBorderBorder style dictionary (/BS).
#[non_exhaustive]Underline
An underline over one or more text runs (/Subtype /Underline).
/QuadPoints is required and must hold at least one quadrilateral.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]StrikeOut
A strike-out over one or more text runs (/Subtype /StrikeOut).
/QuadPoints is required and must hold at least one quadrilateral.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Squiggly
A squiggly underline over one or more text runs (/Subtype /Squiggly).
/QuadPoints is required and must hold at least one quadrilateral.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Ink
Freehand ink strokes (/Subtype /Ink).
Writes /InkList as an array of strokes (each a flat array of x,y
pairs) and /BS from AnnotBorder (no /Type /Border, matching
prior Ink writes).
Fields
This variant is marked as non-exhaustive
border: AnnotBorderBorder style dictionary (/BS).
#[non_exhaustive]FreeText
A free-text annotation (/Subtype /FreeText).
/Contents and /DA are both required. See DEFAULT_DA for a
common appearance string.
Fields
This variant is marked as non-exhaustive
da: StringDefault appearance string (/DA), e.g. DEFAULT_DA.
#[non_exhaustive]Circle
A circle / ellipse annotation (/Subtype /Circle).
Writes /BS like AnnotSpec::Square (includes /Type /Border).
Appearance is generated when the circle AP pipeline is available.
Fields
This variant is marked as non-exhaustive
border: AnnotBorderBorder style dictionary (/BS).
#[non_exhaustive]Line
A straight line (/Subtype /Line) with endpoints /L.
Appearance strokes between the endpoints using /BS width and /C,
with optional /LE endings and /IC interior fill for closed endings.
Fields
This variant is marked as non-exhaustive
border: AnnotBorderBorder style dictionary (/BS).
line_endings: Option<(LineEndingStyle, LineEndingStyle)>Optional line endings (/LE start, end). None omits /LE
(prior behaviour).
#[non_exhaustive]Link
A link annotation (/Subtype /Link) with a typed /A action.
Appearance honours /BS / /C. /H is written for viewer click
feedback only — see AnnotLinkHighlight.
See AnnotLinkAction for URI, GoTo, and named-destination forms.
Fields
This variant is marked as non-exhaustive
action: AnnotLinkActionAction dictionary payload (/A).
border: AnnotBorderBorder style dictionary (/BS). Default width 1, solid.
highlight: AnnotLinkHighlightHighlight mode (/H). Default AnnotLinkHighlight::Invert.
#[non_exhaustive]Caret
A caret / insertion-point annotation (/Subtype /Caret).
Appearance draws a simple caret mark inside /Rect.
Fields
This variant is marked as non-exhaustive
Implementations§
Source§impl AnnotSpec
impl AnnotSpec
Sourcepub fn with_contents(self, contents: impl Into<String>) -> Self
pub fn with_contents(self, contents: impl Into<String>) -> Self
Sets /Contents on variants that take optional contents.
AnnotSpec::FreeText already requires contents at construction; this
leaves it unchanged.
use pdfrum_edit::{AnnotSpec, TextSpec};
use kurbo::Rect;
use peniko::Color;
let spec: AnnotSpec = TextSpec::new(Rect::new(0.0, 0.0, 1.0, 1.0), Color::from_rgb8(255, 255, 0))
.contents("sticky")
.into();
assert!(matches!(
spec,
AnnotSpec::Text {
contents: Some(ref c),
..
} if c == "sticky"
));Sourcepub fn with_meta(self, meta: AnnotMeta) -> AnnotWrite
pub fn with_meta(self, meta: AnnotMeta) -> AnnotWrite
Attach author (/T), unique name (/NM), and/or modification date (/M).
Sets the annotation author (/T).
Sourcepub fn with_name(self, name: impl Into<String>) -> AnnotWrite
pub fn with_name(self, name: impl Into<String>) -> AnnotWrite
Sets the annotation unique name (/NM), typically a stable id.
Sourcepub fn with_modified(self, modified: impl Into<String>) -> AnnotWrite
pub fn with_modified(self, modified: impl Into<String>) -> AnnotWrite
Sets /M from a PDF date string (e.g. from crate::pdf_date).
Sourcepub fn with_flags(self, flags: AnnotFlags) -> AnnotWrite
pub fn with_flags(self, flags: AnnotFlags) -> AnnotWrite
Sets /F annotation flags (default when omitted is Print).
use pdfrum_doc::AnnotFlags;
use pdfrum_edit::{AnnotSpec, TextSpec};
use kurbo::Rect;
use peniko::Color;
let write = TextSpec::new(Rect::new(0.0, 0.0, 1.0, 1.0), Color::from_rgb8(255, 255, 0))
.flags(AnnotFlags::PRINT | AnnotFlags::NO_ZOOM);
assert_eq!(write.meta.flags, Some(AnnotFlags::PRINT | AnnotFlags::NO_ZOOM));Sourcepub fn with_opacity(self, opacity: f32) -> AnnotWrite
pub fn with_opacity(self, opacity: f32) -> AnnotWrite
Sets /CA, the constant opacity, from 0.0 to 1.0.
Applies to every subtype: the generator folds it into the appearance’s
/ExtGState, so a translucent highlight is written the same way an
opaque one is.
use pdfrum_edit::{AnnotSpec, MarkupKind, MarkupSpec};
use kurbo::Rect;
use peniko::Color;
let spec = MarkupSpec::new(
MarkupKind::Highlight,
Rect::new(0.0, 0.0, 10.0, 2.0),
Color::from_rgb8(255, 255, 0),
);
let write = AnnotSpec::from(spec).with_opacity(0.4);
assert_eq!(write.meta.opacity, Some(0.4));Trait Implementations§
Source§impl From<AnnotSpec> for AnnotWrite
impl From<AnnotSpec> for AnnotWrite
Source§impl From<CircleSpec> for AnnotSpec
impl From<CircleSpec> for AnnotSpec
Source§fn from(b: CircleSpec) -> Self
fn from(b: CircleSpec) -> Self
Source§impl From<FreeTextSpec> for AnnotSpec
impl From<FreeTextSpec> for AnnotSpec
Source§fn from(b: FreeTextSpec) -> Self
fn from(b: FreeTextSpec) -> Self
Source§impl From<MarkupSpec> for AnnotSpec
impl From<MarkupSpec> for AnnotSpec
Source§fn from(b: MarkupSpec) -> Self
fn from(b: MarkupSpec) -> Self
Source§impl From<SquareSpec> for AnnotSpec
impl From<SquareSpec> for AnnotSpec
Source§fn from(b: SquareSpec) -> Self
fn from(b: SquareSpec) -> Self
impl StructuralPartialEq for AnnotSpec
Auto Trait Implementations§
impl Freeze for AnnotSpec
impl RefUnwindSafe for AnnotSpec
impl Send for AnnotSpec
impl Sync for AnnotSpec
impl Unpin for AnnotSpec
impl UnsafeUnpin for AnnotSpec
impl UnwindSafe for AnnotSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.