pub struct PdfDocument { /* private fields */ }Expand description
High-level PDF document handle.
Implementations§
Source§impl PdfDocument
impl PdfDocument
Sourcepub fn open_with_processing_limits(
data: impl Into<PdfData>,
limits: ProcessingLimits,
) -> Result<Self>
pub fn open_with_processing_limits( data: impl Into<PdfData>, limits: ProcessingLimits, ) -> Result<Self>
Open a PDF from bytes with processing limits.
Sourcepub fn open_with_password(
data: impl Into<PdfData>,
password: &str,
) -> Result<Self>
pub fn open_with_password( data: impl Into<PdfData>, password: &str, ) -> Result<Self>
Open a password-protected PDF.
Sourcepub fn open_with_password_and_processing_limits(
data: impl Into<PdfData>,
password: &str,
limits: ProcessingLimits,
) -> Result<Self>
pub fn open_with_password_and_processing_limits( data: impl Into<PdfData>, password: &str, limits: ProcessingLimits, ) -> Result<Self>
Open a password-protected PDF with processing limits.
Sourcepub fn set_settings(&mut self, settings: InterpreterSettings)
pub fn set_settings(&mut self, settings: InterpreterSettings)
Set interpreter settings (font resolver, cmap resolver, etc.).
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
Number of pages.
Sourcepub fn page_geometry(&self, index: usize) -> Result<PageGeometry>
pub fn page_geometry(&self, index: usize) -> Result<PageGeometry>
Get the geometry of a page.
Sourcepub fn render_page(
&self,
index: usize,
options: &RenderOptions,
) -> Result<RenderedPage>
pub fn render_page( &self, index: usize, options: &RenderOptions, ) -> Result<RenderedPage>
Render a single page.
If the document contains an XFA template, it is automatically flattened to static PDF content before rendering. This prevents the “Please wait” placeholder page that Adobe Reader would show when rendering an XFA PDF with a conventional renderer. If flattening fails, rendering falls back to the original document as a best-effort path.
Sourcepub fn render_page_with_config(
&self,
index: usize,
config: &RenderConfig,
) -> Result<RenderedPage>
pub fn render_page_with_config( &self, index: usize, config: &RenderConfig, ) -> Result<RenderedPage>
Render a single page using the high-level render config.
XFA documents are auto-flattened before rendering (same as render_page).
If flattening fails, rendering falls back to the original document.
Sourcepub fn render_page_cmyk(&self, index: usize, dpi: u32) -> Result<RenderedPage>
pub fn render_page_cmyk(&self, index: usize, dpi: u32) -> Result<RenderedPage>
Render a single page to a CMYK buffer.
Sourcepub fn render_all(&self, options: &RenderOptions) -> Vec<RenderedPage>
pub fn render_all(&self, options: &RenderOptions) -> Vec<RenderedPage>
Render all pages, in parallel when the parallel feature is enabled.
Sourcepub fn render_all_with_config(&self, config: &RenderConfig) -> Vec<RenderedPage>
pub fn render_all_with_config(&self, config: &RenderConfig) -> Vec<RenderedPage>
Render all pages using the high-level render config.
Sourcepub fn thumbnail(
&self,
index: usize,
options: &ThumbnailOptions,
) -> Result<RenderedPage>
pub fn thumbnail( &self, index: usize, options: &ThumbnailOptions, ) -> Result<RenderedPage>
Generate a thumbnail for a single page.
Sourcepub fn thumbnails_all(&self, options: &ThumbnailOptions) -> Vec<RenderedPage>
pub fn thumbnails_all(&self, options: &ThumbnailOptions) -> Vec<RenderedPage>
Generate thumbnails for all pages, in parallel when the parallel feature is enabled.
Sourcepub fn extract_text(&self, index: usize) -> Result<String>
pub fn extract_text(&self, index: usize) -> Result<String>
Extract text from a page as a single string.
Sourcepub fn extract_text_blocks(&self, index: usize) -> Result<Vec<TextBlock>>
pub fn extract_text_blocks(&self, index: usize) -> Result<Vec<TextBlock>>
Extract structured text blocks from a page.
Sourcepub fn extract_all_text_blocks(&self) -> Vec<Vec<TextBlock>>
pub fn extract_all_text_blocks(&self) -> Vec<Vec<TextBlock>>
Extract structured text blocks from all pages, reusing interpreter settings.
Sourcepub fn extract_acroform_text(&self) -> String
pub fn extract_acroform_text(&self) -> String
Extract text values from AcroForm fields, including push-button captions.
Returns a single string concatenating all non-empty field values separated by newlines. Useful when the document stores its readable content in form field values rather than (or in addition to) page content streams.
Sourcepub fn extract_all_text(&self) -> String
pub fn extract_all_text(&self) -> String
Extract all text from the document: page content streams plus AcroForm field values. Mirrors pdftotext behaviour.
Sourcepub fn search_text(&self, query: &str) -> Vec<usize>
pub fn search_text(&self, query: &str) -> Vec<usize>
Simple text search: returns page indices containing the query string.
Sourcepub fn info(&self) -> DocumentInfo
pub fn info(&self) -> DocumentInfo
Extract document metadata.
Sourcepub fn bookmarks(&self) -> Vec<BookmarkItem>
pub fn bookmarks(&self) -> Vec<BookmarkItem>
Extract document outline / bookmarks.
Sourcepub fn ocr_page(
&self,
index: usize,
backend: &dyn OcrBackend,
dpi: f64,
) -> Result<OcrResult>
pub fn ocr_page( &self, index: usize, backend: &dyn OcrBackend, dpi: f64, ) -> Result<OcrResult>
Run OCR on a page and return the recognized text and word positions.
The page is rendered at dpi (default 150) before recognition.
Pass any [OcrBackend] implementation; use [OcrsBackend::try_default]
to load the pure-Rust ocrs engine from the standard model paths.
§Example
use pdf_engine::{PdfDocument, OcrsBackend, RenderOptions};
let doc = PdfDocument::open(std::fs::read("scan.pdf").unwrap()).unwrap();
let backend = OcrsBackend::try_default().unwrap();
let result = doc.ocr_page(0, &backend, 150.0_f64).unwrap();
println!("{}", result.text);Auto Trait Implementations§
impl Freeze for PdfDocument
impl !RefUnwindSafe for PdfDocument
impl Send for PdfDocument
impl Sync for PdfDocument
impl Unpin for PdfDocument
impl UnsafeUnpin for PdfDocument
impl !UnwindSafe for PdfDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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