pub struct Document { /* private fields */ }Expand description
A parsed PDF document. Load once, then rasterize pages on demand.
Implementations§
Source§impl Document
impl Document
Sourcepub fn load(bytes: Vec<u8>) -> Result<Self, PdfError>
pub fn load(bytes: Vec<u8>) -> Result<Self, PdfError>
Parse a PDF document from its raw bytes.
§Errors
Returns PdfError::Parse if the bytes are not a readable PDF, or
PdfError::Encrypted if the document is password-protected.
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
The number of pages in the document.
Sourcepub fn render_page(
&self,
index: usize,
scale: f32,
) -> Result<RenderedPage, PdfError>
pub fn render_page( &self, index: usize, scale: f32, ) -> Result<RenderedPage, PdfError>
Rasterize page index (0-based) at scale (1.0 renders at the native
72-DPI size; 2.0 is twice as large) over an opaque white background,
producing straight RGBA8 pixels.
§Errors
Returns PdfError::PageOutOfRange if index >= self.page_count().
Sourcepub fn outline(&self) -> Vec<OutlineItem>
pub fn outline(&self) -> Vec<OutlineItem>
Extract the document’s navigation outline (bookmarks) as a tree.
Each entry maps to a 0-based page index where its destination can be
resolved. A document with no outline — or a malformed one — yields an empty
Vec rather than an error. Named destinations (/Names → /Dests name
trees) and remote/URI actions are not resolved: those entries keep their
title but report page = None.