Skip to main content

PageBuilder

Struct PageBuilder 

Source
pub struct PageBuilder<'a> { /* private fields */ }
Expand description

A page being built.

Implementations§

Source§

impl<'a> PageBuilder<'a>

Source

pub fn add_text( &mut self, text: &str, x: f32, y: f32, font_name: &str, font_size: f32, ) -> &mut Self

Add text to the page.

Source

pub fn add_embedded_text( &mut self, text: &str, x: f32, y: f32, font_resource_name: &str, font_size: f32, ) -> &mut Self

Add Unicode text on a page using a previously-registered embedded TrueType font. The font must have been registered with PdfWriter::register_embedded_font first; the returned resource name is what font_resource_name should be (e.g. "EF1").

Glyph IDs are looked up via the font’s cmap and buffered into a structured crate::writer::content_stream::ContentStreamOp::ShowEmbeddedText op carrying the font resource name. Hex emission is deferred to PdfWriter::finish, which runs crate::fonts::subset_font_bytes on each embedded font and uses the resulting crate::fonts::GlyphRemapper to renumber every original GID in the content stream into its subset-local index — so FontFile2, /W, ToUnicode, and the content stream all agree on the subset GID space.

Source

pub fn add_shaped_embedded_text( &mut self, text: &str, x: f32, y: f32, font_resource_name: &str, font_size: f32, direction: Direction, ) -> &mut Self

Available on crate feature system-fonts only.

Add Unicode text on a page using the harfrust shaper. Required for any complex script (Arabic, Hebrew, Devanagari) where add_embedded_text’s naive char→glyph cmap lookup produces the wrong glyphs (no contextual forms, no ligatures, no RTL reordering).

direction controls visual reordering — pass crate::writer::font_shaping::Direction::Rtl for Arabic/ Hebrew runs after BiDi segmentation.

On any error (unknown resource, unparseable face) this is a silent no-op for the same reason as add_embedded_text: a missing-glyph symptom is easier to debug than a panic.

Source

pub fn add_element(&mut self, element: &ContentElement) -> &mut Self

Add a content element to the page.

Text elements whose FontSpec.name matches a font registered via PdfWriter::register_embedded_font_as are routed through add_embedded_text (Type-0 hex emission) so that CJK / Cyrillic / Greek / etc. render with the embedded subset. All other elements fall through to the default base-14 content-stream path.

Source

pub fn add_elements(&mut self, elements: &[ContentElement]) -> &mut Self

Add multiple content elements. Each element is routed through add_element so the embedded-font dispatch applies per-element.

Source

pub fn draw_rect( &mut self, x: f32, y: f32, width: f32, height: f32, ) -> &mut Self

Draw a rectangle on the page.

Source

pub fn fill_rect_colored( &mut self, x: f32, y: f32, width: f32, height: f32, r: f32, g: f32, b: f32, ) -> &mut Self

Fill a rectangle with the given RGB color, then restore the fill color to black.

Source

pub fn set_fill_color(&mut self, r: f32, g: f32, b: f32) -> &mut Self

Set the current fill (non-stroking) color. Affects subsequent text and fill ops.

Source

pub fn draw_hline_colored( &mut self, x: f32, y: f32, width: f32, thickness: f32, r: f32, g: f32, b: f32, ) -> &mut Self

Draw a horizontal line segment with the given RGB stroke color and thickness.

Add a link annotation to the page.

§Arguments
  • link - The link annotation to add

Add a URI link annotation to the page.

§Arguments
  • rect - The clickable area in page coordinates
  • uri - The target URL

Add an internal page link annotation.

§Arguments
  • rect - The clickable area in page coordinates
  • page - The target page index (0-based)
Source

pub fn add_text_markup(&mut self, markup: TextMarkupAnnotation) -> &mut Self

Add a text markup annotation.

Source

pub fn highlight(&mut self, rect: Rect, quad_points: Vec<[f64; 8]>) -> &mut Self

Add a highlight annotation.

§Arguments
  • rect - Bounding rectangle
  • quad_points - QuadPoints defining the text area (each is 8 f64 values)
Source

pub fn highlight_rect(&mut self, rect: Rect) -> &mut Self

Add a highlight annotation from a simple rectangle.

Generates QuadPoints automatically from the rectangle.

Source

pub fn underline(&mut self, rect: Rect, quad_points: Vec<[f64; 8]>) -> &mut Self

Add an underline annotation.

Source

pub fn underline_rect(&mut self, rect: Rect) -> &mut Self

Add an underline annotation from a simple rectangle.

Source

pub fn strikeout(&mut self, rect: Rect, quad_points: Vec<[f64; 8]>) -> &mut Self

Add a strikeout annotation.

Source

pub fn strikeout_rect(&mut self, rect: Rect) -> &mut Self

Add a strikeout annotation from a simple rectangle.

Source

pub fn squiggly(&mut self, rect: Rect, quad_points: Vec<[f64; 8]>) -> &mut Self

Add a squiggly underline annotation.

Source

pub fn squiggly_rect(&mut self, rect: Rect) -> &mut Self

Add a squiggly underline annotation from a simple rectangle.

Source

pub fn add_text_note(&mut self, note: TextAnnotation) -> &mut Self

Add a text annotation (sticky note).

Source

pub fn sticky_note( &mut self, rect: Rect, contents: impl Into<String>, ) -> &mut Self

Add a sticky note annotation with default Note icon.

§Arguments
  • rect - The position and size for the icon (typically 24x24)
  • contents - The text content of the note
Source

pub fn comment(&mut self, rect: Rect, contents: impl Into<String>) -> &mut Self

Add a comment annotation (speech bubble icon).

Source

pub fn text_note_with_icon( &mut self, rect: Rect, contents: impl Into<String>, icon: TextAnnotationIcon, ) -> &mut Self

Add a text annotation with a specific icon.

§Arguments
  • rect - The position and size for the icon
  • contents - The text content of the note
  • icon - The icon to display
Source

pub fn add_freetext(&mut self, freetext: FreeTextAnnotation) -> &mut Self

Add a FreeText annotation.

Source

pub fn textbox(&mut self, rect: Rect, contents: impl Into<String>) -> &mut Self

Add a text box annotation.

§Arguments
  • rect - The position and size of the text box
  • contents - The text content
Source

pub fn textbox_styled( &mut self, rect: Rect, contents: impl Into<String>, font: &str, size: f32, ) -> &mut Self

Add a text box with specific font and size.

§Arguments
  • rect - The position and size of the text box
  • contents - The text content
  • font - Font name (Helvetica, Times, Courier)
  • size - Font size in points
Source

pub fn textbox_centered( &mut self, rect: Rect, contents: impl Into<String>, ) -> &mut Self

Add a centered text box.

Source

pub fn callout( &mut self, rect: Rect, contents: impl Into<String>, callout_points: Vec<f64>, ) -> &mut Self

Add a callout annotation (text box with leader line).

§Arguments
  • rect - The position and size of the text box
  • contents - The text content
  • callout_points - Leader line coordinates [x1,y1, x2,y2] or [x1,y1, x2,y2, x3,y3]
Source

pub fn typewriter( &mut self, rect: Rect, contents: impl Into<String>, ) -> &mut Self

Add a typewriter annotation (plain text without border).

Source

pub fn add_line(&mut self, line: LineAnnotation) -> &mut Self

Add a Line annotation.

Source

pub fn line(&mut self, start: (f64, f64), end: (f64, f64)) -> &mut Self

Add a simple line from start to end.

Source

pub fn arrow(&mut self, start: (f64, f64), end: (f64, f64)) -> &mut Self

Add a line with an arrow at the end.

Source

pub fn double_arrow(&mut self, start: (f64, f64), end: (f64, f64)) -> &mut Self

Add a double-headed arrow line.

Source

pub fn line_with_endings( &mut self, start: (f64, f64), end: (f64, f64), start_ending: LineEndingStyle, end_ending: LineEndingStyle, ) -> &mut Self

Add a line with custom line endings.

Source

pub fn add_shape(&mut self, shape: ShapeAnnotation) -> &mut Self

Add a Shape annotation.

Source

pub fn rectangle(&mut self, rect: Rect) -> &mut Self

Add a rectangle annotation.

Source

pub fn rectangle_filled( &mut self, rect: Rect, stroke: (f32, f32, f32), fill: (f32, f32, f32), ) -> &mut Self

Add a filled rectangle annotation.

Source

pub fn circle(&mut self, rect: Rect) -> &mut Self

Add a circle/ellipse annotation.

Source

pub fn circle_filled( &mut self, rect: Rect, stroke: (f32, f32, f32), fill: (f32, f32, f32), ) -> &mut Self

Add a filled circle/ellipse annotation.

Source

pub fn add_polygon(&mut self, polygon: PolygonAnnotation) -> &mut Self

Add a Polygon or PolyLine annotation.

Source

pub fn polygon(&mut self, vertices: Vec<(f64, f64)>) -> &mut Self

Add a closed polygon annotation.

Source

pub fn polygon_filled( &mut self, vertices: Vec<(f64, f64)>, stroke: (f32, f32, f32), fill: (f32, f32, f32), ) -> &mut Self

Add a filled polygon annotation.

Source

pub fn polyline(&mut self, vertices: Vec<(f64, f64)>) -> &mut Self

Add an open polyline annotation.

Source

pub fn add_ink(&mut self, ink: InkAnnotation) -> &mut Self

Add an Ink annotation (freehand drawing).

Source

pub fn ink(&mut self, stroke: Vec<(f64, f64)>) -> &mut Self

Add a freehand stroke annotation.

§Arguments
  • stroke - List of (x, y) points forming the stroke path
Source

pub fn freehand(&mut self, strokes: Vec<Vec<(f64, f64)>>) -> &mut Self

Add a freehand drawing with multiple strokes.

§Arguments
  • strokes - List of strokes, each being a list of (x, y) points
Source

pub fn ink_styled( &mut self, stroke: Vec<(f64, f64)>, color: (f32, f32, f32), line_width: f32, ) -> &mut Self

Add a styled ink annotation.

§Arguments
  • stroke - List of (x, y) points
  • color - RGB color tuple
  • line_width - Line width in points
Source

pub fn add_stamp(&mut self, stamp: StampAnnotation) -> &mut Self

Add a Stamp annotation.

Source

pub fn stamp(&mut self, rect: Rect, stamp_type: StampType) -> &mut Self

Add a stamp annotation with the given type.

§Arguments
  • rect - Position and size of the stamp
  • stamp_type - The type of stamp to display
Source

pub fn stamp_approved(&mut self, rect: Rect) -> &mut Self

Add an “Approved” stamp.

Source

pub fn stamp_draft(&mut self, rect: Rect) -> &mut Self

Add a “Draft” stamp.

Source

pub fn stamp_confidential(&mut self, rect: Rect) -> &mut Self

Add a “Confidential” stamp.

Source

pub fn stamp_final(&mut self, rect: Rect) -> &mut Self

Add a “Final” stamp.

Source

pub fn stamp_not_approved(&mut self, rect: Rect) -> &mut Self

Add a “Not Approved” stamp.

Source

pub fn stamp_for_comment(&mut self, rect: Rect) -> &mut Self

Add a “For Comment” stamp.

Source

pub fn stamp_custom(&mut self, rect: Rect, name: impl Into<String>) -> &mut Self

Add a custom stamp.

§Arguments
  • rect - Position and size of the stamp
  • name - Custom stamp name
Source

pub fn add_popup(&mut self, popup: PopupAnnotation) -> &mut Self

Add a Popup annotation.

Source

pub fn popup(&mut self, rect: Rect, open: bool) -> &mut Self

Add a popup window for annotations.

Source

pub fn add_caret(&mut self, caret: CaretAnnotation) -> &mut Self

Add a Caret annotation.

Source

pub fn caret(&mut self, rect: Rect) -> &mut Self

Add a caret (text insertion marker).

Source

pub fn caret_paragraph(&mut self, rect: Rect) -> &mut Self

Add a caret with paragraph symbol.

Source

pub fn caret_with_comment( &mut self, rect: Rect, comment: impl Into<String>, ) -> &mut Self

Add a caret with a comment.

Source

pub fn add_file_attachment( &mut self, file: FileAttachmentAnnotation, ) -> &mut Self

Add a FileAttachment annotation.

Source

pub fn file_attachment( &mut self, rect: Rect, file_name: impl Into<String>, ) -> &mut Self

Add a file attachment annotation.

Source

pub fn file_attachment_paperclip( &mut self, rect: Rect, file_name: impl Into<String>, ) -> &mut Self

Add a file attachment with paperclip icon.

Source

pub fn add_redact(&mut self, redact: RedactAnnotation) -> &mut Self

Add a Redact annotation.

Source

pub fn redact(&mut self, rect: Rect) -> &mut Self

Add a redact annotation.

Source

pub fn redact_with_text( &mut self, rect: Rect, overlay_text: impl Into<String>, ) -> &mut Self

Add a redact annotation with overlay text.

Source

pub fn set_tab_order(&mut self, order: char) -> &mut Self

Set the page’s /Tabs entry, declaring the tab-navigation order for form fields and annotations. 'R' = row order (top- to-bottom, left-to-right), 'C' = column order (left-to-right, top-to-bottom), 'S' = structure order (requires tagged PDF — only meaningful once Bundle F lands). #393 Bundle D-4.

Source

pub fn set_page_open_script(&mut self, script: impl Into<String>) -> &mut Self

Set a JavaScript action to run when this page is opened (/AA /O).

Source

pub fn set_page_close_script(&mut self, script: impl Into<String>) -> &mut Self

Set a JavaScript action to run when this page is closed (/AA /C).

Source

pub fn add_text_field(&mut self, field: TextFieldWidget) -> &mut Self

Add a text field to the page.

§Arguments
  • field - The text field widget to add
Source

pub fn text_field(&mut self, name: impl Into<String>, rect: Rect) -> &mut Self

Add a text field with builder pattern.

Source

pub fn add_checkbox(&mut self, checkbox: CheckboxWidget) -> &mut Self

Add a checkbox to the page.

§Arguments
  • checkbox - The checkbox widget to add
Source

pub fn checkbox(&mut self, name: impl Into<String>, rect: Rect) -> &mut Self

Add a checkbox with builder pattern.

Source

pub fn add_radio_group(&mut self, group: RadioButtonGroup) -> &mut Self

Add a radio button group to the page.

Note: All buttons in the group are added to this page.

§Arguments
  • group - The radio button group to add
Source

pub fn add_combo_box(&mut self, combo: ComboBoxWidget) -> &mut Self

Add a combo box (dropdown) to the page.

§Arguments
  • combo - The combo box widget to add
Source

pub fn add_list_box(&mut self, list: ListBoxWidget) -> &mut Self

Add a list box to the page.

§Arguments
  • list - The list box widget to add
Source

pub fn add_push_button(&mut self, button: PushButtonWidget) -> &mut Self

Add a push button to the page.

§Arguments
  • button - The push button widget to add
Source

pub fn add_signature_field(&mut self, widget: SignatureWidget) -> &mut Self

Add an unsigned signature placeholder field to the page.

Source

pub fn signature_field( &mut self, name: impl Into<String>, rect: Rect, ) -> &mut Self

Convenience method: add an unsigned signature placeholder by name and rect.

Source

pub fn add_annotation<A: Into<Annotation>>( &mut self, annotation: A, ) -> &mut Self

Add any annotation type to the page.

This is a generic method that accepts any type that can be converted to an Annotation enum, including all the specific annotation types.

§Example
use pdf_oxide::writer::{LinkAnnotation, Annotation};
use pdf_oxide::geometry::Rect;

let link = LinkAnnotation::uri(
    Rect::new(72.0, 720.0, 100.0, 12.0),
    "https://example.com",
);

let mut writer = PdfWriter::new();
let mut page = writer.add_page(612.0, 792.0);
page.add_annotation(link);
Source

pub fn finish(self) -> &'a mut PdfWriter

Finish building this page and return to the writer.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for PageBuilder<'a>

§

impl<'a> Freeze for PageBuilder<'a>

§

impl<'a> RefUnwindSafe for PageBuilder<'a>

§

impl<'a> Send for PageBuilder<'a>

§

impl<'a> Sync for PageBuilder<'a>

§

impl<'a> Unpin for PageBuilder<'a>

§

impl<'a> UnsafeUnpin for PageBuilder<'a>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Ungil for T
where T: Send,