pub struct AnnotationBuilder { /* private fields */ }Expand description
Builder for creating a PDF annotation and adding it to a document.
§Example
use pdf_annot::builder::{AnnotationBuilder, AnnotSubtype, AnnotRect};
let mut doc = lopdf::Document::with_version("1.7");
// ... add pages ...
let annot_id = AnnotationBuilder::new(AnnotSubtype::Square, AnnotRect::new(100.0, 200.0, 300.0, 400.0))
.color(1.0, 0.0, 0.0)
.border_width(2.0)
.contents("A red square")
.build(&mut doc)
.unwrap();Implementations§
Source§impl AnnotationBuilder
impl AnnotationBuilder
Sourcepub fn new(subtype: AnnotSubtype, rect: AnnotRect) -> Self
pub fn new(subtype: AnnotSubtype, rect: AnnotRect) -> Self
Create a new annotation builder for the given subtype and rectangle.
Sourcepub fn free_text(rect: AnnotRect, text: &str, font_size: f64) -> Self
pub fn free_text(rect: AnnotRect, text: &str, font_size: f64) -> Self
Create a FreeText annotation with the given text and font size.
Sourcepub fn sticky_note(rect: AnnotRect, icon: TextIcon) -> Self
pub fn sticky_note(rect: AnnotRect, icon: TextIcon) -> Self
Create a Text (sticky note) annotation.
Sourcepub fn stamp(rect: AnnotRect, name: StampName) -> Self
pub fn stamp(rect: AnnotRect, name: StampName) -> Self
Create a Stamp annotation with a standard stamp name.
Sourcepub fn stamp_custom(rect: AnnotRect, name: &str) -> Self
pub fn stamp_custom(rect: AnnotRect, name: &str) -> Self
Create a Stamp annotation with a custom name.
Sourcepub fn link_uri(rect: AnnotRect, uri: &str) -> Self
pub fn link_uri(rect: AnnotRect, uri: &str) -> Self
Create a Link annotation with a URI action.
Sourcepub fn link_dest(rect: AnnotRect, dest: &str) -> Self
pub fn link_dest(rect: AnnotRect, dest: &str) -> Self
Create a Link annotation with a named destination.
Sourcepub fn line(x1: f64, y1: f64, x2: f64, y2: f64) -> Self
pub fn line(x1: f64, y1: f64, x2: f64, y2: f64) -> Self
Create a Line annotation between two points.
Automatically pads the bounding rect so it is never zero-area.
Sourcepub fn ink(rect: AnnotRect, strokes: Vec<Vec<f64>>) -> Self
pub fn ink(rect: AnnotRect, strokes: Vec<Vec<f64>>) -> Self
Create an Ink annotation from stroke paths.
Sourcepub fn polygon(rect: AnnotRect, vertices: Vec<f64>) -> Self
pub fn polygon(rect: AnnotRect, vertices: Vec<f64>) -> Self
Create a Polygon annotation from vertices.
Sourcepub fn polyline(rect: AnnotRect, vertices: Vec<f64>) -> Self
pub fn polyline(rect: AnnotRect, vertices: Vec<f64>) -> Self
Create a PolyLine annotation from vertices.
Sourcepub fn interior_color(self, r: f64, g: f64, b: f64) -> Self
pub fn interior_color(self, r: f64, g: f64, b: f64) -> Self
Set the interior (fill) color for annotations that support it.
Sourcepub fn border_width(self, width: f64) -> Self
pub fn border_width(self, width: f64) -> Self
Set the border/stroke width.
Sourcepub fn alignment(self, q: i64) -> Self
pub fn alignment(self, q: i64) -> Self
Set text alignment for FreeText annotations (0=left, 1=center, 2=right).
Sourcepub fn line_endings(self, start: LineEnding, end: LineEnding) -> Self
pub fn line_endings(self, start: LineEnding, end: LineEnding) -> Self
Set line endings for Line annotations.
Sourcepub fn quad_points(self, points: Vec<f64>) -> Self
pub fn quad_points(self, points: Vec<f64>) -> Self
Set QuadPoints for text markup annotations.
Each quadrilateral is defined by 8 values in page coordinates:
[x1,y1, x2,y2, x3,y3, x4,y4] where the points define the
corners of the marked text region. Multiple quads can be
concatenated for multi-line selections.
Sourcepub fn quad_points_from_rect(self, rect: &AnnotRect) -> Self
pub fn quad_points_from_rect(self, rect: &AnnotRect) -> Self
Set QuadPoints from a simple rectangle (single quad).
Sourcepub fn appearance(
self,
f: impl FnOnce(&mut AppearanceStreamBuilder) + 'static,
) -> Self
pub fn appearance( self, f: impl FnOnce(&mut AppearanceStreamBuilder) + 'static, ) -> Self
Provide a custom appearance builder closure.
Sourcepub fn build(self, doc: &mut Document) -> Result<ObjectId, AnnotBuildError>
pub fn build(self, doc: &mut Document) -> Result<ObjectId, AnnotBuildError>
Build the annotation, add it to the document, and return the annotation object ID.
This creates the annotation dictionary, generates the appearance stream,
and adds both as objects to the document. The annotation is NOT automatically
added to any page’s /Annots array — use add_to_page for that.
Auto Trait Implementations§
impl Freeze for AnnotationBuilder
impl !RefUnwindSafe for AnnotationBuilder
impl !Send for AnnotationBuilder
impl !Sync for AnnotationBuilder
impl Unpin for AnnotationBuilder
impl UnsafeUnpin for AnnotationBuilder
impl !UnwindSafe for AnnotationBuilder
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more