Skip to main content

AnnotationBuilder

Struct AnnotationBuilder 

Source
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

Source

pub fn new(subtype: AnnotSubtype, rect: AnnotRect) -> Self

Create a new annotation builder for the given subtype and rectangle.

Source

pub fn free_text(rect: AnnotRect, text: &str, font_size: f64) -> Self

Create a FreeText annotation with the given text and font size.

Source

pub fn sticky_note(rect: AnnotRect, icon: TextIcon) -> Self

Create a Text (sticky note) annotation.

Source

pub fn stamp(rect: AnnotRect, name: StampName) -> Self

Create a Stamp annotation with a standard stamp name.

Source

pub fn stamp_custom(rect: AnnotRect, name: &str) -> Self

Create a Stamp annotation with a custom name.

Create a Link annotation with a URI action.

Create a Link annotation with a named destination.

Source

pub fn square(rect: AnnotRect) -> Self

Create a Square annotation.

Source

pub fn circle(rect: AnnotRect) -> Self

Create a Circle annotation.

Source

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.

Source

pub fn ink(rect: AnnotRect, strokes: Vec<Vec<f64>>) -> Self

Create an Ink annotation from stroke paths.

Source

pub fn polygon(rect: AnnotRect, vertices: Vec<f64>) -> Self

Create a Polygon annotation from vertices.

Source

pub fn polyline(rect: AnnotRect, vertices: Vec<f64>) -> Self

Create a PolyLine annotation from vertices.

Source

pub fn highlight(rect: AnnotRect) -> Self

Create a Highlight markup annotation.

Source

pub fn underline(rect: AnnotRect) -> Self

Create an Underline markup annotation.

Source

pub fn strikeout(rect: AnnotRect) -> Self

Create a StrikeOut markup annotation.

Source

pub fn squiggly(rect: AnnotRect) -> Self

Create a Squiggly markup annotation.

Source

pub fn color(self, r: f64, g: f64, b: f64) -> Self

Set the annotation color (RGB, 0.0–1.0).

Source

pub fn interior_color(self, r: f64, g: f64, b: f64) -> Self

Set the interior (fill) color for annotations that support it.

Source

pub fn opacity(self, alpha: f64) -> Self

Set the opacity (CA/ca, 0.0–1.0).

Source

pub fn border_width(self, width: f64) -> Self

Set the border/stroke width.

Source

pub fn contents(self, text: impl Into<String>) -> Self

Set the /Contents text.

Source

pub fn flags(self, flags: u32) -> Self

Set the annotation flags (raw u32).

Source

pub fn alignment(self, q: i64) -> Self

Set text alignment for FreeText annotations (0=left, 1=center, 2=right).

Source

pub fn line_endings(self, start: LineEnding, end: LineEnding) -> Self

Set line endings for Line annotations.

Source

pub fn dash(self, pattern: Vec<f64>) -> Self

Set a dash pattern for stroked annotations.

Source

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.

Source

pub fn quad_points_from_rect(self, rect: &AnnotRect) -> Self

Set QuadPoints from a simple rectangle (single quad).

Source

pub fn appearance( self, f: impl FnOnce(&mut AppearanceStreamBuilder) + 'static, ) -> Self

Provide a custom appearance builder closure.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V