Skip to main content

PdfDocument

Struct PdfDocument 

Source
pub struct PdfDocument {
    pub inner: PDDocument,
}
Expand description

Context-oriented facade for intuitive, modern PDF processing.

Fields§

§inner: PDDocument

Implementations§

Source§

impl PdfDocument

Source

pub fn create() -> Self

Creates a new, blank PDF document.

Source

pub fn open(path: impl AsRef<Path>) -> PdfResult<Self>

Opens a PDF document from a file path.

Source

pub fn open_from_bytes(bytes: &[u8]) -> PdfResult<Self>

Opens a PDF document from in-memory bytes.

Source

pub fn add_blank_page(&mut self, size: PDRectangle) -> usize

Adds a blank page with the specified dimensions (e.g. PDRectangle::A4).

Source

pub fn page_count(&self) -> usize

Returns the total number of pages.

Source

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

Sets the document title in metadata.

Source

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

Sets the document author in metadata.

Source

pub fn draw_on_page<F>( &mut self, page_index: usize, mode: AppendMode, f: F, ) -> PdfResult<()>

Draws onto a page using a closure that receives a PDPageContentStream.

Source

pub fn stamp(&self) -> Stamper

Returns a fluent Stamper for watermarking, headers/footers, and rubber stamps.

Source

pub fn watermark(&mut self, text: impl Into<String>) -> PdfResult<()>

Applies a simple diagonal text watermark across all pages.

Source

pub fn sign(&mut self, signer: Signer) -> PdfResult<Vec<u8>>

Digitally signs the document using the given Signer and returns signed PDF bytes.

Source

pub fn extract_text(&self) -> PdfResult<String>

Extracts all text from the document.

Source

pub fn merge(&mut self, other: &PdfDocument) -> PdfResult<()>

Merges another document into this document.

Source

pub fn split_single_pages(&self) -> PdfResult<Vec<PdfDocument>>

Splits this document into individual 1-page documents.

Source

pub fn flatten_forms(&mut self) -> PdfResult<()>

Flattens all interactive form fields into static page contents.

Source

pub fn save(&mut self, path: impl AsRef<Path>) -> PdfResult<()>

Saves the document to a file path.

Source

pub fn to_bytes(&mut self) -> PdfResult<Vec<u8>>

Saves the document to an in-memory byte vector.

Trait Implementations§

Source§

impl Default for PdfDocument

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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
§

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

§

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.

§

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

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

§

fn vzip(self) -> V