Skip to main content

PdfDocument

Struct PdfDocument 

Source
pub struct PdfDocument { /* private fields */ }
Expand description

An open PDF document.

The document owns the PDF bytes for its whole lifetime (PDFium requires the backing buffer to stay valid while the document is open). Dropping the document releases the PDFium handle and, if forms were enabled, the form-fill environment first (in the order PDFium requires).

§Thread safety

PdfDocument is Send + Sync: every method serializes through the process-wide FFI lock. Sharing one document across threads is safe; calls will not run in parallel.

Implementations§

Source§

impl PdfDocument

Source

pub fn page_count(&self) -> usize

Number of pages.

Source

pub fn page(&self, index: usize) -> Result<PdfPage<'_>>

Opens page index (0-based).

Source

pub fn pages(&self) -> impl Iterator<Item = Result<PdfPage<'_>>>

Iterates over all pages, opening each lazily.

Source

pub fn page_size(&self, index: usize) -> Result<PageSize>

Page size in points without loading the page — cheap for dimension surveys of large documents.

Source

pub fn form_type(&self) -> FormType

The document’s interactive form type (cheap; does not initialize form rendering).

Source

pub fn enable_form_rendering(&self) -> Result<()>

Initializes PDFium’s form-fill environment so RenderConfig::form_fields can draw AcroForm field appearances.

Idempotent. Pages opened after this call participate in form rendering; enable forms before opening pages you intend to render.

Source

pub fn forms_enabled(&self) -> bool

Whether enable_form_rendering has been called successfully.

Source

pub fn permissions(&self) -> Permissions

Document permissions from the encryption dictionary. Unencrypted documents report all permissions granted.

Source

pub fn security_handler_revision(&self) -> Option<i32>

Security handler revision (2/3/4/5/6), or None for unencrypted documents.

Source

pub fn pdf_version(&self) -> Option<i32>

PDF file version as reported by the header, times ten (14 = PDF 1.4, 17 = PDF 1.7, 20 = PDF 2.0). None if unavailable.

Source

pub fn metadata(&self, tag: MetadataTag) -> Option<String>

A standard metadata field, or None when absent/empty.

Source

pub fn page_label(&self, index: usize) -> Option<String>

The page label for index (e.g. “iv”, “A-2”), or None when the document defines no label for it.

Trait Implementations§

Source§

impl Debug for PdfDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PdfDocument

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for PdfDocument

Source§

impl Sync for PdfDocument

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