Skip to main content

PdfPage

Struct PdfPage 

Source
pub struct PdfPage {
    pub width: Length,
    pub height: Length,
    pub content: Vec<u8>,
    pub link_annotations: Vec<LinkAnnotation>,
}
Expand description

PDF page

Fields§

§width: Length

Page width

§height: Length

Page height

§content: Vec<u8>

Page content stream

§link_annotations: Vec<LinkAnnotation>

Link annotations on this page

Implementations§

Source§

impl PdfPage

Source

pub fn new(width: Length, height: Length) -> Self

Create a new PDF page

Add a link annotation to the page

§Arguments
  • x - X position (PDF coordinates: bottom-left origin)
  • y - Y position (PDF coordinates: bottom-left origin)
  • width - Width of the clickable area
  • height - Height of the clickable area
  • destination - Link destination (external URL or internal ID)
Source

pub fn add_text(&mut self, text: &str, x: Length, y: Length, font_size: Length)

Add text to the page using the default Helvetica font (F1)

Source

pub fn add_text_with_spacing( &mut self, text: &str, x: Length, y: Length, font_size: Length, letter_spacing: Option<Length>, word_spacing: Option<Length>, )

Add text to the page using the default Helvetica font (F1) with optional letter/word spacing

§Arguments
  • letter_spacing - Optional character spacing in points (Tc operator)
  • word_spacing - Optional word spacing in points (Tw operator)
Source

pub fn add_text_with_font( &mut self, text: &str, x: Length, y: Length, font_size: Length, font_index: usize, )

Add text to the page using a custom embedded font

§Arguments
  • text - The text to display
  • x - X position
  • y - Y position
  • font_size - Font size
  • font_index - Index of the embedded font (from embed_font)

Note: Character usage tracking must be done separately via FontManager::record_text

Source

pub fn add_text_with_font_and_spacing( &mut self, text: &str, x: Length, y: Length, font_size: Length, font_index: usize, letter_spacing: Option<Length>, word_spacing: Option<Length>, )

Add text to the page using a custom embedded font with optional letter/word spacing

§Arguments
  • text - The text to display
  • x - X position
  • y - Y position
  • font_size - Font size
  • font_index - Index of the embedded font (from embed_font)
  • letter_spacing - Optional character spacing in points (Tc operator)
  • word_spacing - Optional word spacing in points (Tw operator)
Source

pub fn add_text_with_font_tracked( &mut self, text: &str, x: Length, y: Length, font_size: Length, font_index: usize, font_manager: &mut FontManager, )

Add text to the page using a custom embedded font and track character usage

This is a convenience method that both adds the text and records character usage for subsetting.

§Arguments
  • text - The text to display
  • x - X position
  • y - Y position
  • font_size - Font size
  • font_index - Index of the embedded font (from embed_font)
  • font_manager - FontManager to record character usage
Source

pub fn add_background( &mut self, x: Length, y: Length, width: Length, height: Length, color: Color, )

Add background color to an area

Source

pub fn add_background_with_radius( &mut self, x: Length, y: Length, width: Length, height: Length, color: Color, border_radius: Option<[Length; 4]>, )

Add background color to an area with optional rounded corners

Source

pub fn add_background_with_opacity( &mut self, x: Length, y: Length, width: Length, height: Length, color: Color, border_radius: Option<[Length; 4]>, gs_index: usize, )

Add background color with opacity to an area with optional rounded corners

§Arguments
  • x, y - Bottom-left corner of the area (PDF coordinates)
  • width, height - Dimensions of the area
  • color - Fill color
  • border_radius - Optional corner radii
  • gs_index - Index of the ExtGState resource for opacity
Source

pub fn add_gradient_background( &mut self, x: Length, y: Length, width: Length, height: Length, gradient_index: usize, )

Add gradient background to an area

§Arguments
  • x, y - Bottom-left corner of the area (PDF coordinates)
  • width, height - Dimensions of the area
  • gradient_index - Index of the gradient in the document’s gradient list
Source

pub fn add_gradient_background_with_radius( &mut self, x: Length, y: Length, width: Length, height: Length, gradient_index: usize, border_radius: Option<[Length; 4]>, )

Add gradient background to an area with optional rounded corners

§Arguments
  • x, y - Bottom-left corner of the area (PDF coordinates)
  • width, height - Dimensions of the area
  • gradient_index - Index of the gradient in the document’s gradient list
  • border_radius - Optional corner radii [top-left, top-right, bottom-right, bottom-left]
Source

pub fn add_borders( &mut self, x: Length, y: Length, width: Length, height: Length, border_widths: [Length; 4], border_colors: [Color; 4], border_styles: [BorderStyle; 4], )

Add borders to an area

Source

pub fn add_borders_with_radius( &mut self, x: Length, y: Length, width: Length, height: Length, border_widths: [Length; 4], border_colors: [Color; 4], border_styles: [BorderStyle; 4], border_radius: Option<[Length; 4]>, )

Add borders to an area with optional rounded corners

Source

pub fn add_borders_with_opacity( &mut self, x: Length, y: Length, width: Length, height: Length, border_widths: [Length; 4], border_colors: [Color; 4], border_styles: [BorderStyle; 4], border_radius: Option<[Length; 4]>, gs_index: usize, )

Add borders with opacity to an area with optional rounded corners

Source

pub fn add_image( &mut self, image_index: usize, x: Length, y: Length, width: Length, height: Length, )

Add an image to the page

§Arguments
  • image_index - The index of the image XObject in the document’s image_xobjects list
  • x - X position in PDF coordinates (bottom-left origin)
  • y - Y position in PDF coordinates (bottom-left origin)
  • width - Display width
  • height - Display height
Source

pub fn add_rule( &mut self, x: Length, y: Length, width: Length, thickness: Length, color: Color, style: &str, )

Add a horizontal rule (line) to the page

§Arguments
  • x - Left edge x-coordinate
  • y - Bottom edge y-coordinate (PDF coordinate system)
  • width - Rule width
  • thickness - Line thickness
  • color - Line color
  • style - Line style (solid, dashed, dotted)
Source

pub fn save_clip_state( &mut self, x: Length, y: Length, width: Length, height: Length, ) -> Result<()>

Save graphics state and set clipping path

This method saves the current graphics state and establishes a rectangular clipping path. Content drawn after this call will be clipped to the specified rectangle until restore_clip_state() is called.

PDF operators used:

  • q: Save graphics state
  • re: Rectangle path
  • W: Set clipping path (intersect with current path)
  • n: End path without stroking or filling
§Arguments
  • x, y - Bottom-left corner of clipping rectangle (PDF coordinates)
  • width, height - Dimensions of clipping rectangle
§PDF Reference

See PDF specification section 8.5 for clipping path details.

Source

pub fn restore_clip_state(&mut self) -> Result<()>

Restore graphics state after clipping

This restores the graphics state that was saved by save_clip_state(), removing the clipping path.

PDF operator used:

  • Q: Restore graphics state

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, 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.