Rust API Reference
PDF Oxide is a native Rust crate. The pdf_oxide crate is the source of truth for every other binding (Python, JavaScript/WASM, Go, C#, Java, and the C ABI). This page documents the public Rust surface for v0.3.69.
# Cargo.toml
[dependencies]
pdf_oxide = "0.3.69"
Optional features: rendering, signatures, ocr / ocr-tract, parallel, barcodes, office, tsa-client, fips, legacy-crypto.
use pdf_oxide::PdfDocument; // low-level open + extraction
use pdf_oxide::api::Pdf; // high-level create / open / edit / save
use pdf_oxide::writer::DocumentBuilder; // fluent PDF generation
For other languages, see the Python API Reference, Node.js API Reference or WASM API Reference, and Types & Enums.
Almost every fallible method returns pdf_oxide::Result<T> (an alias for Result<T, pdf_oxide::Error>). Signatures below elide trailing -> Result<...> wrapping only where noted.
pdf_oxide::api::Pdf is the unified high-level facade for creating, opening, extracting, editing, and saving PDFs. It lazily constructs a DocumentEditor on first edit/extract call, so most methods take &mut self.
use pdf_oxide::api::Pdf;
Creation
fn from_markdown(content: &str) -> Result<Self>
fn from_markdown_with_fonts(content: &str, fonts: &[(String, Vec<u8>)]) -> Result<Self>
fn from_html(content: &str) -> Result<Self>
fn from_html_css(html: &str, css: &str, font_bytes: Vec<u8>) -> Result<Self>
fn from_html_css_with_fonts(html: &str, css: &str, fonts: Vec<(String, Vec<u8>)>) -> Result<Self>
fn from_text(content: &str) -> Result<Self>
fn from_image(path: impl AsRef<Path>) -> Result<Self>
fn from_image_bytes(data: &[u8]) -> Result<Self>
fn from_images<P: AsRef<Path>>(paths: &[P]) -> Result<Self>
fn from_qrcode(data: &str) -> Result<Self>
fn from_qrcode_with_options(data: &str, options: &QrCodeOptions) -> Result<Self>
fn from_barcode(barcode_type: BarcodeType, data: &str) -> Result<Self>
fn from_barcode_with_options(barcode_type: BarcodeType, data: &str, options: &BarcodeOptions) -> Result<Self>
Build a new PDF from Markdown, HTML, HTML+CSS, plain text, one or more images, a QR code, or a 1D barcode. The *_with_fonts / *_css variants embed custom TTF/OTF fonts.
Opening
fn new() -> Self // empty in-memory PDF
fn open(path: impl AsRef<Path>) -> Result<Self> // open existing file
fn from_bytes(data: Vec<u8>) -> Result<Self> // open from memory
fn open_editor(path: impl AsRef<Path>) -> Result<DocumentEditor>
Document Info & Metadata
fn page_count(&mut self) -> Result<usize>
fn is_modified(&self) -> bool
fn source_path(&self) -> Option<&Path>
fn config(&self) -> &PdfConfig
fn editor(&mut self) -> Option<&mut DocumentEditor>
fn set_title(&mut self, title: impl Into<String>) -> Result<()>
fn set_author(&mut self, author: impl Into<String>) -> Result<()>
fn set_subject(&mut self, subject: impl Into<String>) -> Result<()>
fn set_keywords(&mut self, keywords: impl Into<String>) -> Result<()>
Text & Content Extraction
fn to_markdown(&mut self, page: usize) -> Result<String>
fn to_html(&mut self, page: usize) -> Result<String>
fn to_text(&mut self, page: usize) -> Result<String>
fn extract_spans(&mut self, page: usize) -> Result<Vec<TextSpan>>
fn extract_chars(&mut self, page: usize) -> Result<Vec<TextChar>>
fn extract_words(&mut self, page: usize) -> Result<Vec<Word>>
fn extract_text_lines(&mut self, page: usize) -> Result<Vec<TextLine>>
fn extract_rects(&mut self, page: usize) -> Result<Vec<PathContent>>
fn extract_lines(&mut self, page: usize) -> Result<Vec<PathContent>>
fn extract_tables(&mut self, page: usize) -> Result<Vec<Table>>
fn extract_tables_with_config(&mut self, page: usize, config: TableConfig) -> Result<Vec<Table>>
fn extract_images(&mut self, page: usize) -> Result<Vec<PdfImage>>
fn to_markdown_file(&mut self, path: impl AsRef<Path>) -> Result<()>
Region-Scoped Extraction
fn within(&mut self, page_index: usize, region: Rect) -> PdfPageRegion<'_>
fn extract_text_in_rect(&mut self, page: usize, rect: Rect) -> Result<String>
fn extract_words_in_rect(&mut self, page: usize, rect: Rect) -> Result<Vec<Word>>
fn extract_text_lines_in_rect(&mut self, page: usize, rect: Rect) -> Result<Vec<TextLine>>
fn extract_chars_in_rect(&mut self, page: usize, rect: Rect) -> Result<Vec<TextChar>>
fn extract_images_in_rect(&mut self, page: usize, rect: Rect) -> Result<Vec<PdfImage>>
fn extract_tables_in_rect(&mut self, page: usize, rect: Rect) -> Result<Vec<Table>>
within(...) returns a PdfPageRegion whose filter_mode(), extract_text(), extract_words(), extract_text_lines(), extract_chars(), extract_rects(), extract_lines(), extract_images(), and extract_tables() operate on a single clipping rectangle.
Search
fn search(&mut self, pattern: &str) -> Result<Vec<SearchResult>>
fn search_with_options(&mut self, pattern: &str, options: SearchOptions) -> Result<Vec<SearchResult>>
fn search_page(&mut self, page: usize, pattern: &str) -> Result<Vec<SearchResult>>
fn highlight_matches(&mut self, results: &[SearchResult], color: [f32; 3]) -> Result<()>
Rendering
fn render_page(&mut self, page_index: usize, options: Option<&RenderOptions>) -> Result<RenderedImage>
fn render_page_with_options(&mut self, page_index: usize, options: &RenderOptions) -> Result<RenderedImage>
fn render_page_to_file(&mut self, page: usize, path: impl AsRef<Path>) -> Result<()>
fn render_page_to_file_with_dpi(&mut self, page: usize, path: impl AsRef<Path>, dpi: u32) -> Result<()>
Requires the rendering feature.
Page Geometry
fn page_rotation(&mut self, page: usize) -> Result<i32>
fn set_page_rotation(&mut self, page: usize, degrees: i32) -> Result<()>
fn rotate_page(&mut self, page: usize, degrees: i32) -> Result<()>
fn rotate_all_pages(&mut self, degrees: i32) -> Result<()>
fn page_media_box(&mut self, page: usize) -> Result<[f32; 4]>
fn set_page_media_box(&mut self, page: usize, rect: [f32; 4]) -> Result<()>
fn page_crop_box(&mut self, page: usize) -> Result<Option<[f32; 4]>>
fn set_page_crop_box(&mut self, page: usize, rect: [f32; 4]) -> Result<()>
fn crop_margins(&mut self, left: f32, right: f32, top: f32, bottom: f32) -> Result<()>
Erase / Whiteout
fn erase_region(&mut self, page: usize, rect: [f32; 4]) -> Result<()>
fn erase_regions(&mut self, page: usize, rects: &[[f32; 4]]) -> Result<()>
fn clear_erase_regions(&mut self, page: usize)
Annotation & Form Flattening
fn flatten_page_annotations(&mut self, page: usize) -> Result<()>
fn flatten_all_annotations(&mut self) -> Result<()>
fn is_page_marked_for_flatten(&self, page: usize) -> bool
fn unmark_page_for_flatten(&mut self, page: usize)
fn flatten_forms_on_page(&mut self, page: usize) -> Result<()>
fn flatten_forms(&mut self) -> Result<()>
fn is_page_marked_for_form_flatten(&self, page: usize) -> bool
fn will_remove_acroform(&self) -> bool
Redaction
fn apply_page_redactions(&mut self, page: usize) -> Result<()>
fn apply_all_redactions(&mut self) -> Result<()>
fn is_page_marked_for_redaction(&self, page: usize) -> bool
fn unmark_page_for_redaction(&mut self, page: usize)
Form Data Export & Embedded Files
fn export_form_data_fdf(&mut self, output_path: impl AsRef<Path>) -> Result<()>
fn export_form_data_xfdf(&mut self, output_path: impl AsRef<Path>) -> Result<()>
fn embed_file(&mut self, name: &str, data: Vec<u8>) -> Result<()>
fn embed_file_with_options(&mut self, file: EmbeddedFile) -> Result<()>
fn pending_embedded_files(&self) -> &[EmbeddedFile]
fn clear_embedded_files(&mut self)
Image Manipulation
fn page_images(&mut self, page: usize) -> Result<Vec<ImageInfo>>
fn reposition_image(&mut self, page: usize, image_name: &str, x: f32, y: f32) -> Result<()>
fn resize_image(&mut self, page: usize, image_name: &str, width: f32, height: f32) -> Result<()>
fn set_image_bounds(&mut self, page: usize, image_name: &str, x: f32, y: f32, width: f32, height: f32) -> Result<()>
fn clear_image_modifications(&mut self, page: usize)
fn has_image_modifications(&self, page: usize) -> bool
Page Labels & XMP Metadata
fn page_labels(&mut self) -> Result<Vec<PageLabelRange>>
fn page_label(&mut self, page: usize) -> Result<String>
fn all_page_labels(&mut self) -> Result<Vec<String>>
fn xmp_metadata(&mut self) -> Result<Option<XmpMetadata>>
fn has_xmp_metadata(&mut self) -> Result<bool>
fn xmp_title(&mut self) -> Result<Option<String>>
fn xmp_creators(&mut self) -> Result<Vec<String>>
fn xmp_description(&mut self) -> Result<Option<String>>
fn xmp_creator_tool(&mut self) -> Result<Option<String>>
fn xmp_create_date(&mut self) -> Result<Option<String>>
fn xmp_modify_date(&mut self) -> Result<Option<String>>
fn xmp_producer(&mut self) -> Result<Option<String>>
DOM Access
fn page(&mut self, index: usize) -> Result<PdfPage>
fn save_page(&mut self, page: PdfPage) -> Result<()>
page(i) returns a DOM-like PdfPage for element-level editing (see PdfPage); save_page writes a modified page back.
Saving
fn as_bytes(&self) -> &[u8]
fn into_bytes(self) -> Vec<u8>
fn to_bytes(&mut self) -> Result<Vec<u8>>
fn save(&mut self, path: impl AsRef<Path>) -> Result<()>
fn save_as(&mut self, path: impl AsRef<Path>) -> Result<()>
fn save_to_bytes(&mut self) -> Result<Vec<u8>>
fn save_encrypted(&mut self, path: impl AsRef<Path>, user_password: &str, owner_password: &str) -> Result<()>
fn save_with_encryption(&mut self, path: impl AsRef<Path>, config: EncryptionConfig) -> Result<()>
PdfBuilder
pdf_oxide::api::PdfBuilder configures metadata, page size, margins, and typography before producing a Pdf.
use pdf_oxide::api::PdfBuilder;
use pdf_oxide::writer::PageSize;
fn new() -> Self
fn title(self, title: impl Into<String>) -> Self
fn author(self, author: impl Into<String>) -> Self
fn subject(self, subject: impl Into<String>) -> Self
fn keywords(self, keywords: impl Into<String>) -> Self
fn template(self, template: PageTemplate) -> Self
fn page_size(self, size: PageSize) -> Self
fn margin(self, margin: f32) -> Self
fn margins(self, left: f32, right: f32, top: f32, bottom: f32) -> Self
fn font_size(self, size: f32) -> Self
fn line_height(self, height: f32) -> Self
fn from_markdown(self, content: &str) -> Result<Pdf>
fn from_markdown_with_fonts(self, content: &str, fonts: &[(String, Vec<u8>)]) -> Result<Pdf>
fn from_html(self, content: &str) -> Result<Pdf>
fn from_text(self, content: &str) -> Result<Pdf>
fn from_image(self, path: impl AsRef<Path>) -> Result<Pdf>
fn from_image_bytes(self, data: &[u8]) -> Result<Pdf>
fn from_images<P: AsRef<Path>>(self, paths: &[P]) -> Result<Pdf>
fn from_image_data_multiple(self, images: Vec<ImageData>) -> Result<Pdf>
fn from_qrcode(self, data: &str) -> Result<Pdf>
fn from_qrcode_with_options(self, data: &str, options: &QrCodeOptions) -> Result<Pdf>
fn from_barcode(self, barcode_type: BarcodeType, data: &str) -> Result<Pdf>
fn from_barcode_with_options(self, barcode_type: BarcodeType, data: &str, options: &BarcodeOptions) -> Result<Pdf>
PdfDocument
pdf_oxide::PdfDocument is the low-level reader: opening, parsing, decryption, and all extraction primitives. It is &self-based and read-oriented; wrap it in a DocumentEditor (or use Pdf) to modify and save.
use pdf_oxide::PdfDocument;
Opening & Authentication
fn open(path: impl AsRef<Path>) -> Result<Self>
fn open_with_config(path: impl AsRef<Path>, config: impl Any) -> Result<Self>
fn from_bytes(data: Vec<u8>) -> Result<Self>
fn open_from_bytes(data: Vec<u8>) -> Result<Self>
fn authenticate(&self, password: &[u8]) -> Result<bool>
fn is_encrypted(&self) -> bool
fn is_authenticated(&self) -> bool
fn permissions(&self) -> Option<PdfPermissions>
Document Info
fn version(&self) -> (u8, u8)
fn page_count(&self) -> Result<usize>
fn page_count_u32(&self) -> u32
fn page_indices(&self) -> Range<usize>
fn document_producer(&self) -> Option<String>
fn document_creator(&self) -> Option<String>
fn trailer(&self) -> &Object
fn catalog(&self) -> Result<Object>
fn all_object_ids(&self) -> Vec<u32>
fn get_outline(&self) -> Result<Option<Vec<OutlineItem>>>
fn has_structure_tree(&self) -> bool
fn structure_tree(&self) -> Result<Option<StructTreeRoot>>
fn mark_info(&self) -> Result<MarkInfo>
fn prefers_structure_reading_order(&self) -> bool
fn has_text_layer(&self, page_index: usize) -> Result<bool>
fn warnings(&self) -> Vec<String>
fn take_warnings(&self) -> Vec<String>
Page Geometry
fn get_page(&self, page_index: usize) -> Result<Object>
fn get_page_info(&self, page_index: usize) -> Result<PageInfo>
fn get_page_media_box(&self, page_index: usize) -> Result<(f32, f32, f32, f32)>
fn get_page_rotation(&self, page_index: usize) -> Result<i32>
fn get_page_resources(&self, page_index: usize) -> Result<Object>
Text Extraction
fn extract_text(&self, page_index: usize) -> Result<String>
fn extract_text_with_options(&self, page_index: usize, options: TextExtractionOptions) -> Result<String>
fn extract_all_text(&self) -> Result<String>
fn extract_text_auto(&self, page: usize) -> Result<String>
fn extract_spans(&self, page_index: usize) -> Result<Vec<TextSpan>>
fn extract_spans_with_reading_order(&self, page_index: usize, order: ReadingOrder) -> Result<Vec<TextSpan>>
fn extract_spans_with_config(&self, page_index: usize, config: &TextPipelineConfig) -> Result<Vec<TextSpan>>
fn extract_chars(&self, page_index: usize) -> Result<Vec<TextChar>>
fn extract_words(&self, page_index: usize) -> Result<Vec<Word>>
fn extract_words_with_thresholds(&self, page_index: usize, word_gap: f32, line_gap: f32) -> Result<Vec<Word>>
fn extract_text_lines(&self, page_index: usize) -> Result<Vec<TextLine>>
fn extract_text_lines_with_thresholds(&self, page_index: usize, word_gap: f32, line_gap: f32) -> Result<Vec<TextLine>>
fn extract_page_text(&self, page_index: usize) -> Result<PageText>
fn extract_page_text_with_options(&self, page_index: usize, options: TextExtractionOptions) -> Result<PageText>
fn extract_structured(&self, page_index: usize) -> Result<StructuredPage>
fn extract_structured_with_column_mode(&self, page_index: usize, mode: ColumnMode) -> Result<StructuredPage>
fn page_font_stats(&self, page_index: usize) -> Result<PageFontStats>
Filtered & Region Extraction
fn extract_text_filtered(&self, page_index: usize, filter: RectFilterMode) -> Result<String>
fn extract_text_filtered_in_rect(&self, page_index: usize, rect: Rect, filter: RectFilterMode) -> Result<String>
fn extract_chars_filtered(&self, page_index: usize, filter: RectFilterMode) -> Result<Vec<TextChar>>
fn extract_text_in_rect(&self, page_index: usize, rect: Rect) -> Result<String>
fn extract_words_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<Word>>
fn extract_text_lines_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<TextLine>>
fn extract_chars_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<TextChar>>
fn extract_spans_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<TextSpan>>
fn extract_images_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<PdfImage>>
fn extract_tables_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<Table>>
fn extract_text_excluding_rects(&self, page_index: usize, rects: &[Rect]) -> Result<String>
fn extract_words_excluding_rects(&self, page_index: usize, rects: &[Rect]) -> Result<Vec<Word>>
fn extract_spans_excluding_rects(&self, page_index: usize, rects: &[Rect]) -> Result<Vec<TextSpan>>
Vector Paths & Tables
fn extract_paths(&self, page_index: usize) -> Result<Vec<PathContent>>
fn extract_rects(&self, page_index: usize) -> Result<Vec<PathContent>>
fn extract_lines(&self, page_index: usize) -> Result<Vec<PathContent>>
fn extract_paths_in_rect(&self, page_index: usize, rect: Rect) -> Result<Vec<PathContent>>
fn extract_tables(&self, page_index: usize) -> Result<Vec<Table>>
fn extract_tables_with_config(&self, page_index: usize, config: TableConfig) -> Result<Vec<Table>>
Images & Fonts
fn extract_images(&self, page_index: usize) -> Result<Vec<PdfImage>>
fn extract_images_to_files(&self, page_index: usize, output_dir: impl AsRef<Path>) -> Result<Vec<PathBuf>>
fn page_image_handles(&self, page_index: usize) -> Result<Vec<PdfImageHandle>>
fn get_page_content_data(&self, page_index: usize) -> Result<Vec<u8>>
fn extract_embedded_fonts(&self) -> Result<Vec<(String, Vec<u8>)>>
fn extract_embedded_fonts_with_unicode_maps(&self) -> Result<Vec<(String, Vec<u8>)>>
Optional Content (Layers)
fn get_layers(&self) -> Result<Vec<String>>
fn get_page_inks(&self, page_index: usize) -> Result<Vec<String>>
fn get_page_inks_deep(&self, page_index: usize) -> Result<Vec<String>>
Format Conversion
fn to_markdown(&self, page_index: usize, options: &ConversionOptions) -> Result<String>
fn to_markdown_all(&self, options: &ConversionOptions) -> Result<String>
fn to_html(&self, page_index: usize, options: &ConversionOptions) -> Result<String>
fn to_html_all(&self, options: &ConversionOptions) -> Result<String>
fn to_plain_text(&self, page_index: usize, options: &ConversionOptions) -> Result<String>
fn to_plain_text_all(&self, options: &ConversionOptions) -> Result<String>
fn to_docx(&self, path: impl AsRef<Path>) -> Result<()>
fn to_docx_bytes(&self) -> Result<Vec<u8>>
fn to_pptx(&self, path: impl AsRef<Path>) -> Result<()>
fn to_pptx_bytes(&self) -> Result<Vec<u8>>
fn to_xlsx(&self, path: impl AsRef<Path>) -> Result<()>
fn to_xlsx_bytes(&self) -> Result<Vec<u8>>
Whitespace / Header–Footer Cleanup
fn remove_headers(&self, threshold: f32) -> Result<usize>
fn remove_footers(&self, threshold: f32) -> Result<usize>
fn remove_artifacts(&self, threshold: f32) -> Result<usize>
fn erase_region(&self, page_index: usize, rect: Rect) -> Result<()>
fn clear_erase_regions(&self, page_index: usize) -> Result<()>
Classification & OCR Extraction
fn classify_page(&self, page: usize) -> Result<PageClassification>
fn classify_document(&self) -> Result<DocumentClassification>
fn extract_text_with_ocr(&self, page: usize, engine: &OcrEngine) -> Result<String>
fn extract_text_ocr_only(&self, page: usize, engine: &OcrEngine) -> Result<String>
fn extract_spans_with_ocr(&self, page: usize, engine: &OcrEngine) -> Result<Vec<TextSpan>>
fn to_markdown_with_ocr(&self, page: usize, options: &ConversionOptions, engine: &OcrEngine) -> Result<String>
OCR methods require the ocr (or ocr-tract) feature.
DocumentEditor
pdf_oxide::editor::DocumentEditor is the mutable editing layer behind Pdf: metadata, page operations, merging, forms, redaction, image manipulation, and saving. Obtain one with DocumentEditor::open(...), from_document, or Pdf::open_editor.
use pdf_oxide::editor::DocumentEditor;
Construction & Saving
fn open(path: impl AsRef<Path>) -> Result<Self>
fn from_document(source: PdfDocument) -> Result<Self>
fn from_bytes(data: Vec<u8>) -> Result<Self>
fn open_from_bytes(data: Vec<u8>) -> Result<Self>
fn save_to_bytes(&mut self) -> Result<Vec<u8>>
fn save_to_bytes_with_options(&mut self, options: SaveOptions) -> Result<Vec<u8>>
fn into_source(self) -> PdfDocument
fn source(&self) -> &PdfDocument
fn source_mut(&mut self) -> &mut PdfDocument
fn is_modified(&self) -> bool
fn version(&self) -> (u8, u8)
SaveOptions::full_rewrite(), SaveOptions::incremental(), and SaveOptions::with_encryption(config) control the save strategy.
Metadata
fn title(&mut self) -> Result<Option<String>>
fn set_title(&mut self, title: impl Into<String>)
fn author(&mut self) -> Result<Option<String>>
fn set_author(&mut self, author: impl Into<String>)
fn subject(&mut self) -> Result<Option<String>>
fn set_subject(&mut self, subject: impl Into<String>)
fn keywords(&mut self) -> Result<Option<String>>
fn set_keywords(&mut self, keywords: impl Into<String>)
fn producer(&mut self) -> Result<Option<String>>
fn set_producer(&mut self, producer: impl Into<String>)
fn creation_date(&mut self) -> Result<Option<String>>
fn set_creation_date(&mut self, date: impl Into<String>)
Page Operations
fn current_page_count(&self) -> usize
fn extract_pages(&mut self, pages: &[usize], output: impl AsRef<Path>) -> Result<()>
fn extract_pages_to_bytes(&mut self, pages: &[usize]) -> Result<Vec<u8>>
fn extract_page_ranges_to_bytes(&mut self, ranges: &[(usize, usize)]) -> Result<Vec<u8>>
fn select_pages(&mut self, pages: &[usize]) -> Result<()>
fn merge_from(&mut self, source_path: impl AsRef<Path>) -> Result<usize>
fn merge_from_bytes(&mut self, data: &[u8]) -> Result<usize>
fn merge_pages_from(&mut self, source_path: impl AsRef<Path>, pages: &[usize]) -> Result<usize>
fn add_image_bytes_to_page(&mut self, page_index: usize, png_bytes: &[u8], x: f32, y: f32, width: f32, height: f32) -> Result<()>
Page Geometry
fn get_page_rotation(&mut self, index: usize) -> Result<i32>
fn set_page_rotation(&mut self, index: usize, degrees: i32) -> Result<()>
fn rotate_page_by(&mut self, index: usize, degrees: i32) -> Result<()>
fn rotate_all_pages(&mut self, degrees: i32) -> Result<()>
fn get_page_media_box(&mut self, index: usize) -> Result<[f32; 4]>
fn set_page_media_box(&mut self, index: usize, box_: [f32; 4]) -> Result<()>
fn get_page_crop_box(&mut self, index: usize) -> Result<Option<[f32; 4]>>
fn set_page_crop_box(&mut self, index: usize, box_: [f32; 4]) -> Result<()>
fn crop_margins(&mut self, left: f32, right: f32, top: f32, bottom: f32) -> Result<()>
DOM Page Editing
fn get_page(&mut self, page_index: usize) -> Result<PdfPage>
fn save_page(&mut self, page: PdfPage) -> Result<()>
fn page_editor(&mut self, page_index: usize) -> Result<PageEditor>
fn edit_page<F>(&mut self, page_index: usize, f: F) -> Result<()>
fn get_page_content(&mut self, page_index: usize) -> Result<Option<StructureElement>>
fn set_page_content(&mut self, page_index: usize, content: StructureElement) -> Result<()>
fn modify_structure<F>(&mut self, page_index: usize, f: F) -> Result<()>
fn get_page_annotations(&mut self, page_index: usize) -> Result<Vec<AnnotationWrapper>>
fn has_modified_annotations(&self, page_index: usize) -> bool
Erase & Flatten
fn erase_region(&mut self, page: usize, rect: [f32; 4]) -> Result<()>
fn erase_regions(&mut self, page: usize, rects: &[[f32; 4]]) -> Result<()>
fn clear_erase_regions(&mut self, page: usize)
fn flatten_page_annotations(&mut self, page: usize) -> Result<()>
fn flatten_all_annotations(&mut self) -> Result<()>
fn flatten_forms_on_page(&mut self, page: usize) -> Result<()>
fn flatten_forms(&mut self) -> Result<()>
fn will_remove_acroform(&self) -> bool
fn flatten_warnings(&self) -> &[String]
Embedded Files
fn embed_file(&mut self, name: &str, data: Vec<u8>) -> Result<()>
fn embed_file_with_options(&mut self, file: EmbeddedFile) -> Result<()>
fn pending_embedded_files(&self) -> &[EmbeddedFile]
fn clear_embedded_files(&mut self)
XFA Forms
fn has_xfa(&mut self) -> Result<bool>
fn analyze_xfa(&mut self) -> Result<XfaAnalysis>
fn convert_xfa_to_acroform(&mut self, options: Option<XfaConversionOptions>) -> Result<Vec<u8>>
AcroForm Fields
fn get_form_fields(&mut self) -> Result<Vec<FormFieldWrapper>>
fn get_form_field_value(&mut self, name: &str) -> Result<Option<FormFieldValue>>
fn has_form_field(&mut self, name: &str) -> Result<bool>
fn add_form_field<W: FormFieldWidget>(&mut self, widget: W, page: usize) -> Result<()>
fn add_parent_field(&mut self, config: ParentFieldConfig) -> Result<()>
fn add_child_field<W: FormFieldWidget>(&mut self, widget: W, parent: &str, page: usize) -> Result<()>
fn set_form_field_value(&mut self, name: &str, value: FormFieldValue) -> Result<()>
fn remove_form_field(&mut self, name: &str) -> Result<()>
fn set_form_field_readonly(&mut self, name: &str, readonly: bool) -> Result<()>
fn set_form_field_required(&mut self, name: &str, required: bool) -> Result<()>
fn set_form_field_tooltip(&mut self, name: &str, tooltip: impl Into<String>) -> Result<()>
fn set_form_field_rect(&mut self, name: &str, rect: Rect) -> Result<()>
fn set_form_field_max_length(&mut self, name: &str, max_len: u32) -> Result<()>
fn set_form_field_alignment(&mut self, name: &str, alignment: u32) -> Result<()>
fn set_form_field_background_color(&mut self, name: &str, color: [f32; 3]) -> Result<()>
fn set_form_field_border_color(&mut self, name: &str, color: [f32; 3]) -> Result<()>
fn set_form_field_border_width(&mut self, name: &str, width: f32) -> Result<()>
fn set_form_field_default_appearance(&mut self, name: &str, da: impl Into<String>) -> Result<()>
fn set_form_field_flags(&mut self, name: &str, flags: u32) -> Result<()>
fn export_form_data_fdf(&mut self, output_path: impl AsRef<Path>) -> Result<()>
fn export_form_data_xfdf(&mut self, output_path: impl AsRef<Path>) -> Result<()>
Redaction
fn add_redaction(&mut self, page: usize, rect: [f32; 4], fill: Option<[f32; 3]>) -> Result<()>
fn redaction_count(&mut self, page: usize) -> Result<usize>
fn apply_page_redactions(&mut self, page: usize) -> Result<()>
fn apply_all_redactions(&mut self) -> Result<()>
fn apply_redactions_destructive(&mut self, opts: RedactionOptions) -> Result<RedactionReport>
fn sanitize_document(&mut self, opts: RedactionOptions) -> Result<RedactionReport>
Image Manipulation
fn get_page_images(&mut self, page: usize) -> Result<Vec<ImageInfo>>
fn reposition_image(&mut self, page: usize, image_name: &str, x: f32, y: f32) -> Result<()>
fn resize_image(&mut self, page: usize, image_name: &str, width: f32, height: f32) -> Result<()>
fn set_image_bounds(&mut self, page: usize, image_name: &str, x: f32, y: f32, width: f32, height: f32) -> Result<()>
fn clear_image_modifications(&mut self, page: usize)
fn has_image_modifications(&self, page: usize) -> bool
DocumentBuilder
pdf_oxide::writer::DocumentBuilder is the fluent, page-oriented PDF generation API. Each page is built with a FluentPageBuilder returned by page(), letter_page(), or a4_page().
use pdf_oxide::writer::{DocumentBuilder, PageSize};
Document Setup
fn new() -> Self
fn title(self, title: impl Into<String>) -> Self
fn author(self, author: impl Into<String>) -> Self
fn subject(self, subject: impl Into<String>) -> Self
fn keywords(self, keywords: impl Into<String>) -> Self
fn creator(self, creator: impl Into<String>) -> Self
fn tagged_pdf_ua1(self) -> Self
fn language(self, lang: impl Into<String>) -> Self
fn role_map(self, custom: impl Into<String>, standard: impl Into<String>) -> Self
fn metadata(self, metadata: DocumentMetadata) -> Self
fn template(self, template: PageTemplate) -> Self
fn compress_streams(self, on: bool) -> Self
fn insert_toc(self, insert_at: usize, title: impl Into<String>) -> Self
fn with_page_labels(self, labels: PageLabelsBuilder) -> Self
fn on_open(self, script: impl Into<String>) -> Self
fn bookmark(self, title: impl Into<String>, page_index: usize) -> Self
fn bookmark_tree<F>(self, f: F) -> Self
fn register_embedded_font(self, name: impl Into<String>, font: EmbeddedFont) -> Self
Page Creation & Output
fn page(&mut self, size: PageSize) -> FluentPageBuilder<'_>
fn letter_page(&mut self) -> FluentPageBuilder<'_>
fn a4_page(&mut self) -> FluentPageBuilder<'_>
fn build(self) -> Result<Vec<u8>>
fn save(self, path: impl AsRef<Path>) -> Result<()>
fn save_encrypted(self, path: impl AsRef<Path>, user_password: &str, owner_password: &str) -> Result<()>
fn save_with_encryption(self, path: impl AsRef<Path>, config: EncryptionConfig) -> Result<()>
fn to_bytes_encrypted(self, user_password: &str, owner_password: &str) -> Result<Vec<u8>>
fn to_bytes_with_encryption(self, config: EncryptionConfig) -> Result<Vec<u8>>
FluentPageBuilder
A page builder returned by DocumentBuilder::page(). Calls chain; done() returns control to the DocumentBuilder.
Positioning & Text
fn at(self, x: f32, y: f32) -> Self
fn font(self, name: &str, size: f32) -> Self
fn text_config(self, config: TextConfig) -> Self
fn measure(&self, text: &str) -> f32
fn remaining_space(&self) -> f32
fn page_dimensions(&self) -> (f32, f32)
fn text(self, text: &str) -> Self
fn text_in_rect(self, rect: Rect, text: &str, align: TextAlign) -> Self
fn heading(self, level: u8, text: &str) -> Self
fn bullet_list<S: AsRef<str>>(self, items: &[S]) -> Self
fn numbered_list<S: AsRef<str>>(self, items: &[S], style: ListStyle) -> Self
fn code_block(self, language: &str, source: &str) -> Self
fn paragraph(self, text: &str) -> Self
fn rich_paragraph(self, runs: &[TextRun]) -> Self
fn columns(self, column_count: u32, gap_pt: f32, text: &str) -> Self
fn footnote(self, ref_mark: &str, note_text: &str) -> Self
fn space(self, points: f32) -> Self
fn horizontal_rule(self) -> Self
fn newline(self) -> Self
fn inline(self, text: &str) -> Self
fn inline_bold(self, text: &str) -> Self
fn inline_italic(self, text: &str) -> Self
fn inline_color(self, r: f32, g: f32, b: f32, text: &str) -> Self
fn element(self, element: ContentElement) -> Self
fn elements(self, elements: Vec<ContentElement>) -> Self
fn new_page_same_size(self) -> FluentPageBuilder
fn done(self) -> &mut DocumentBuilder
Annotations
fn link_url(self, url: &str) -> Self
fn link_page(self, page: usize) -> Self
fn link_named(self, destination: &str) -> Self
fn link_javascript(self, script: &str) -> Self
fn highlight(self, color: (f32, f32, f32)) -> Self
fn underline(self, color: (f32, f32, f32)) -> Self
fn strikeout(self, color: (f32, f32, f32)) -> Self
fn squiggly(self, color: (f32, f32, f32)) -> Self
fn sticky_note(self, text: &str) -> Self
fn sticky_note_with_icon(self, text: &str, icon: TextAnnotationIcon) -> Self
fn sticky_note_at(self, x: f32, y: f32, text: &str) -> Self
fn stamp(self, stamp_type: StampType) -> Self
fn stamp_at(self, rect: Rect, stamp_type: StampType) -> Self
fn freetext(self, rect: Rect, text: &str) -> Self
fn freetext_styled(self, rect: Rect, text: &str, font: &str, size: f32) -> Self
fn watermark(self, text: &str) -> Self
fn watermark_confidential(self) -> Self
fn watermark_draft(self) -> Self
fn watermark_custom(self, watermark: WatermarkAnnotation) -> Self
fn add_annotation<A: Into<Annotation>>(self, annotation: A) -> Self
Form Widgets
fn text_field(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32, default_value: Option<String>) -> Self
fn checkbox(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32, checked: bool) -> Self
fn combo_box(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32, options: Vec<String>, selected: Option<String>) -> Self
fn list_box(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32, options: Vec<String>, selected: Option<String>, multi_select: bool) -> Self
fn radio_group(self, name: impl Into<String>, buttons: Vec<(String, f32, f32, f32, f32)>, selected: Option<String>) -> Self
fn push_button(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32, caption: impl Into<String>) -> Self
fn signature_field(self, name: impl Into<String>, x: f32, y: f32, w: f32, h: f32) -> Self
fn required(self) -> Self
fn read_only(self) -> Self
fn tooltip(self, text: impl Into<String>) -> Self
fn field_keystroke(self, script: impl Into<String>) -> Self
fn field_format(self, script: impl Into<String>) -> Self
fn field_validate(self, script: impl Into<String>) -> Self
fn field_calculate(self, script: impl Into<String>) -> Self
fn tab_order(self, order: TabOrder) -> Self
Graphics, Images & Tables
fn rect(self, x: f32, y: f32, w: f32, h: f32) -> Self
fn filled_rect(self, x: f32, y: f32, w: f32, h: f32, r: f32, g: f32, b: f32) -> Self
fn line(self, x1: f32, y1: f32, x2: f32, y2: f32) -> Self
fn stroke_rect(self, x: f32, y: f32, w: f32, h: f32, style: LineStyle) -> Self
fn stroke_line(self, x1: f32, y1: f32, x2: f32, y2: f32, style: LineStyle) -> Self
fn circle(self, cx: f32, cy: f32, radius: f32, style: LineStyle) -> Self
fn ellipse(self, cx: f32, cy: f32, rx: f32, ry: f32, style: LineStyle) -> Self
fn polygon(self, points: &[(f32, f32)], style: LineStyle) -> Self
fn arc(self, cx: f32, cy: f32, radius: f32, start: f32, end: f32, style: LineStyle) -> Self
fn bezier_curve(self, points: &[(f32, f32)], style: LineStyle) -> Self
fn with_transform<F>(self, matrix: [f32; 6], f: F) -> Self
fn rotated<F>(self, degrees: f32, f: F) -> Self
fn scaled<F>(self, sx: f32, sy: f32, f: F) -> Self
fn translated<F>(self, tx: f32, ty: f32, f: F) -> Self
fn image_from_file(self, path: impl AsRef<Path>, rect: Rect) -> Result<Self>
fn image_from_bytes(self, bytes: &[u8], rect: Rect) -> Result<Self>
fn image_from_bytes_with_alt(self, bytes: &[u8], rect: Rect, alt: &str) -> Result<Self>
fn image_with(self, data: ImageData, rect: Rect) -> Self
fn barcode_1d(self, barcode_type: BarcodeType, data: &str, x: f32, y: f32, w: f32, h: f32) -> Result<Self>
fn barcode_qr(self, data: &str, x: f32, y: f32, size: f32) -> Result<Self>
fn table(self, table: Table) -> Self
fn streaming_table(self, /* column + row config */) -> Self
PdfPage
DOM-like page handle from Pdf::page() / DocumentEditor::get_page(). Query elements, edit text, and manage annotations, then write back with save_page.
use pdf_oxide::editor::PdfPage;
Queries
fn root(&self) -> PdfElement
fn children(&self) -> Vec<PdfElement>
fn find_text_containing(&self, needle: &str) -> Vec<PdfText>
fn find_text<F>(&self, predicate: F) -> Vec<PdfText>
fn find_images(&self) -> Vec<PdfImage>
fn find_images_in_region(&self, region: Rect) -> Vec<PdfImage>
fn find_paths(&self) -> Vec<PdfPath>
fn find_tables(&self) -> Vec<PdfTable>
fn find_in_region(&self, region: Rect) -> Vec<PdfElement>
fn get_element(&self, id: ElementId) -> Option<PdfElement>
fn get_parent(&self, id: ElementId) -> Option<PdfElement>
fn get_children(&self, id: ElementId) -> Vec<PdfElement>
fn get_siblings(&self, id: ElementId) -> Vec<PdfElement>
fn get_next_sibling(&self, id: ElementId) -> Option<PdfElement>
fn get_prev_sibling(&self, id: ElementId) -> Option<PdfElement>
Editing
fn set_text(&mut self, id: ElementId, new_text: impl Into<String>) -> Result<()>
fn modify_text<F>(&mut self, id: ElementId, f: F) -> Result<()>
fn set_image_alt_text(&mut self, id: ElementId, alt: impl Into<String>) -> Result<()>
fn add_text(&mut self, content: TextContent) -> ElementId
fn add_image(&mut self, content: ImageContent) -> ElementId
fn add_path(&mut self, content: PathContent) -> ElementId
fn add_table(&mut self, content: TableContent) -> ElementId
fn remove_element(&mut self, id: ElementId) -> bool
fn render(&self) -> Result<Vec<u8>>
Annotations
fn annotations(&self) -> &[AnnotationWrapper]
fn annotation(&self, index: usize) -> Option<&AnnotationWrapper>
fn annotations_mut(&mut self) -> &mut [AnnotationWrapper]
fn annotation_count(&self) -> usize
fn add_annotation<A: Into<Annotation>>(&mut self, annotation: A) -> AnnotationId
fn remove_annotation(&mut self, index: usize) -> Option<AnnotationWrapper>
fn remove_annotation_by_id(&mut self, id: AnnotationId) -> Option<AnnotationWrapper>
fn find_annotation(&self, id: AnnotationId) -> Option<&AnnotationWrapper>
fn find_annotations_in_region(&self, region: Rect) -> Vec<&AnnotationWrapper>
fn find_annotations_by_type(&self, subtype: AnnotationSubtype) -> Vec<&AnnotationWrapper>
fn has_annotations_modified(&self) -> bool
DOM Element Types
Element wrappers returned by PdfPage queries. All are accessed through PdfElement, which dispatches by type.
PdfElement
fn id(&self) -> ElementId
fn bbox(&self) -> Rect
fn structure_type(&self) -> &str
fn is_text(&self) -> bool
fn is_image(&self) -> bool
fn is_path(&self) -> bool
fn is_table(&self) -> bool
fn is_structure(&self) -> bool
fn as_text(&self) -> Option<&PdfText>
fn as_image(&self) -> Option<&PdfImage>
fn as_path(&self) -> Option<&PdfPath>
fn as_table(&self) -> Option<&PdfTable>
fn as_structure(&self) -> Option<&PdfStructure>
PdfText
fn id(&self) -> ElementId
fn text(&self) -> &str
fn bbox(&self) -> Rect
fn font_name(&self) -> &str
fn font_size(&self) -> f32
fn is_bold(&self) -> bool
fn is_italic(&self) -> bool
fn color(&self) -> Color
fn origin(&self) -> Option<Point>
fn rotation_degrees(&self) -> Option<f32>
fn matrix(&self) -> Option<[f32; 6]>
fn is_rotated(&self) -> bool
fn contains(&self, needle: &str) -> bool
fn starts_with(&self, prefix: &str) -> bool
fn ends_with(&self, suffix: &str) -> bool
fn set_text(&mut self, new_text: impl Into<String>)
fn set_style(&mut self, style: TextStyle)
fn set_matrix(&mut self, matrix: [f32; 6])
fn set_origin(&mut self, origin: Point)
fn set_rotation(&mut self, degrees: f32)
PdfImage
fn id(&self) -> ElementId
fn bbox(&self) -> Rect
fn format(&self) -> ImageFormat
fn dimensions(&self) -> (u32, u32)
fn aspect_ratio(&self) -> f32
fn is_grayscale(&self) -> bool
fn alt_text(&self) -> Option<&str>
fn set_alt_text(&mut self, alt: impl Into<String>)
fn resolution(&self) -> Option<(f32, f32)>
fn horizontal_dpi(&self) -> Option<f32>
fn vertical_dpi(&self) -> Option<f32>
fn is_high_resolution(&self) -> bool
fn is_low_resolution(&self) -> bool
PdfPath
fn id(&self) -> ElementId
fn bbox(&self) -> Rect
fn operations(&self) -> &[PathOperation]
fn stroke_color(&self) -> Option<Color>
fn fill_color(&self) -> Option<Color>
fn stroke_width(&self) -> f32
fn has_stroke(&self) -> bool
fn has_fill(&self) -> bool
fn line_cap(&self) -> LineCap
fn line_join(&self) -> LineJoin
fn is_closed(&self) -> bool
fn set_stroke_color(&mut self, color: Option<Color>)
fn set_fill_color(&mut self, color: Option<Color>)
fn set_stroke_width(&mut self, width: f32)
fn to_svg(&self) -> String
fn to_svg_document(&self) -> String
PdfTable
fn id(&self) -> ElementId
fn bbox(&self) -> Rect
fn row_count(&self) -> usize
fn column_count(&self) -> usize
fn has_header(&self) -> bool
fn caption(&self) -> Option<&str>
fn get_cell(&self, row: usize, col: usize) -> Option<&TableCellContent>
fn detection_confidence(&self) -> f32
fn is_from_structure_tree(&self) -> bool
fn set_cell_text(&mut self, row: usize, col: usize, text: impl Into<String>) -> bool
fn set_caption(&mut self, caption: impl Into<String>)
AnnotationWrapper
fn id(&self) -> AnnotationId
fn subtype(&self) -> AnnotationSubtype
fn rect(&self) -> Rect
fn contents(&self) -> Option<&str>
fn color(&self) -> Option<(f32, f32, f32)>
fn is_modified(&self) -> bool
fn is_new(&self) -> bool
fn set_contents(&mut self, text: impl Into<String>)
fn set_rect(&mut self, rect: Rect)
fn set_color(&mut self, r: f32, g: f32, b: f32)
FormFieldWrapper
Returned by DocumentEditor::get_form_fields(). Wraps a read field or a pending widget and exposes typed accessors and mutators.
use pdf_oxide::editor::form_fields::{FormFieldWrapper, FormFieldValue};
fn name(&self) -> &str
fn partial_name(&self) -> &str
fn full_name(&self) -> String
fn page_index(&self) -> usize
fn value(&self) -> FormFieldValue
fn set_value(&mut self, value: FormFieldValue)
fn field_type(&self) -> Option<&FieldType>
fn bounds(&self) -> Option<Rect>
fn tooltip(&self) -> Option<&str>
fn is_new(&self) -> bool
fn is_modified(&self) -> bool
fn is_readonly(&self) -> bool
fn set_readonly(&mut self, readonly: bool)
fn is_required(&self) -> bool
fn set_required(&mut self, required: bool)
fn flags(&self) -> Option<u32>
fn set_flags(&mut self, flags: u32)
fn get_rect(&self) -> Option<Rect>
fn set_rect(&mut self, rect: Rect)
fn get_max_length(&self) -> Option<u32>
fn set_max_length(&mut self, max_len: u32)
fn get_alignment(&self) -> Option<u32>
fn set_alignment(&mut self, alignment: u32)
fn get_background_color(&self) -> Option<[f32; 3]>
fn set_background_color(&mut self, color: [f32; 3])
fn get_border_color(&self) -> Option<[f32; 3]>
fn set_border_color(&mut self, color: [f32; 3])
fn set_border_width(&mut self, width: f32)
fn set_default_appearance(&mut self, da: impl Into<String>)
FormFieldValue is an enum with helpers: is_none(), as_text() -> Option<&str>, as_bool() -> Option<bool>, as_choice() -> Option<&str>, as_multi_choice() -> Option<&[String]>.
OfficeConverter
pdf_oxide::converters::OfficeConverter converts DOCX/XLSX/PPTX into PDF bytes. Requires the office feature.
use pdf_oxide::converters::OfficeConverter;
fn new() -> Self
fn with_config(config: OfficeConfig) -> Self
fn config(&self) -> &OfficeConfig
fn convert_docx(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
fn convert_docx_bytes(&self, bytes: &[u8]) -> Result<Vec<u8>>
fn convert_xlsx(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
fn convert_xlsx_bytes(&self, bytes: &[u8]) -> Result<Vec<u8>>
fn convert_pptx(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
fn convert_pptx_bytes(&self, bytes: &[u8]) -> Result<Vec<u8>>
fn convert(&self, path: impl AsRef<Path>) -> Result<Vec<u8>>
Margins::uniform(margin), Margins::a4(), Margins::letter(), and Margins::none() build margin presets for OfficeConfig.
Rendering
Requires the rendering feature. Free functions operate directly on a PdfDocument; PageRenderer offers reusable, configured rendering.
use pdf_oxide::rendering::{render_page, render_page_region, render_page_fit, flatten_to_images,
PageRenderer, RenderOptions, RenderedImage, ImageFormat};
Free Functions
fn render_page(doc: &PdfDocument, page_num: usize, options: &RenderOptions) -> Result<RenderedImage>
fn render_page_region(doc: &PdfDocument, page_num: usize, region: Rect, options: &RenderOptions) -> Result<RenderedImage>
fn render_page_fit(doc: &PdfDocument, page_num: usize, fit_width: u32, fit_height: u32, options: &RenderOptions) -> Result<RenderedImage>
fn flatten_to_images(doc: &PdfDocument, dpi: u32) -> Result<Vec<u8>>
RenderOptions
fn with_dpi(dpi: u32) -> Self
fn with_transparent_background(self) -> Self
fn as_jpeg(self, quality: u8) -> Self
fn as_raw(self) -> Self
PageRenderer / RenderedImage
fn new(options: RenderOptions) -> Self // PageRenderer
fn render_page(&mut self, doc: &PdfDocument, page_num: usize) -> Result<RenderedImage>
fn render_page_with_options(&mut self, doc: &PdfDocument, page_num: usize, options: &RenderOptions) -> Result<RenderedImage>
fn as_bytes(&self) -> &[u8] // RenderedImage
fn save(&self, path: impl AsRef<Path>) -> Result<()>
Search
use pdf_oxide::search::{TextSearcher, SearchOptions, SearchResult};
fn search(doc: &PdfDocument, pattern: &str, options: &SearchOptions) -> Result<Vec<SearchResult>> // TextSearcher::search
fn search_page(doc: &PdfDocument, page: usize, pattern: &str, options: &SearchOptions) -> Result<Vec<SearchResult>>
fn new() -> Self // SearchOptions
fn case_insensitive() -> Self
fn with_case_insensitive(self, value: bool) -> Self
fn with_literal(self, value: bool) -> Self
fn with_whole_word(self, value: bool) -> Self
fn with_max_results(self, max: usize) -> Self
fn with_page_range(self, start: usize, end: usize) -> Self
Digital Signatures
Requires the signatures feature. Sign with PdfSigner, verify with SignatureVerifier, and enumerate existing signatures with enumerate_signatures.
use pdf_oxide::signatures::{PdfSigner, SignatureVerifier, SigningCredentials, SignOptions,
Timestamp, TsaClient, enumerate_signatures, count_signatures};
SigningCredentials
fn new(certificate: Vec<u8>, private_key: Vec<u8>) -> Self
fn with_chain(self, chain: Vec<Vec<u8>>) -> Self
fn from_pkcs12(data: &[u8], password: &str) -> Result<Self>
fn from_pem(cert_pem: &str, key_pem: &str) -> Result<Self>
fn from_der(cert_der: Vec<u8>) -> Result<Self>
fn subject(&self) -> Result<String>
fn issuer(&self) -> Result<String>
fn serial(&self) -> Result<String>
fn validity(&self) -> Result<(i64, i64)>
fn is_valid(&self) -> Result<bool>
SignOptions
fn with_appearance(self, appearance: SignatureAppearance) -> Self
fn with_reason(self, reason: impl Into<String>) -> Self
fn with_location(self, location: impl Into<String>) -> Self
fn with_timestamp(self, tsa_url: impl Into<String>) -> Self
PdfSigner
fn new(credentials: SigningCredentials, options: SignOptions) -> Self
fn sign(&self, signed_bytes: &[u8]) -> Result<Vec<u8>>
fn sign_pades(&self, signed_bytes: &[u8]) -> Result<Vec<u8>>
fn compute_digest(&self, signed_bytes: &[u8]) -> Vec<u8>
fn calculate_byte_range(&self, file_size: usize, contents_offset: usize) -> [i64; 4]
fn placeholder_size(&self) -> usize
Convenience free functions: sign_pdf_bytes(...) and sign_pdf_bytes_pades(...).
SignatureVerifier
fn new() -> Self
fn add_trusted_root(&mut self, cert_der: Vec<u8>)
fn add_trusted_roots(&mut self, certs: Vec<Vec<u8>>)
fn load_system_roots(&mut self) -> Result<usize>
fn extract_signature_info(&self, sig_dict: &Object) -> Result<SignatureInfo>
fn verify(&self, sig_dict: &Object, signed_bytes: &[u8]) -> Result<VerificationResult>
fn quick_check(&self, sig_dict: &Object) -> Result<bool>
Enumeration
fn enumerate_signatures(doc: &mut PdfDocument) -> Result<Vec<SignatureInfo>>
fn count_signatures(doc: &mut PdfDocument) -> Result<usize>
Timestamps (RFC 3161)
fn from_der(token: &[u8]) -> Result<Self> // Timestamp
fn time(&self) -> i64
fn serial(&self) -> String
fn policy_oid(&self) -> String
fn tsa_name(&self) -> String
fn hash_algorithm(&self) -> HashAlgorithm
fn message_imprint(&self) -> Vec<u8>
fn verify(&self) -> Result<bool>
fn new(url: impl Into<String>) -> Self // TsaClient (requires `tsa-client`)
fn request_timestamp(&self, data: &[u8]) -> Result<Timestamp>
fn request_timestamp_hash(&self, digest: &[u8], algorithm: HashAlgorithm) -> Result<Timestamp>
OCR
Requires the ocr (native ONNX) or ocr-tract (pure-Rust) feature. Drive a PaddleOCR-style pipeline with OcrEngine, configured by OcrConfig.
use pdf_oxide::ocr::{OcrEngine, OcrConfig, detect_page_type, needs_ocr, ocr_page, extract_text_with_ocr};
Page Detection
fn detect_page_type(doc: &PdfDocument, page: usize) -> Result<PageType>
fn needs_ocr(doc: &PdfDocument, page: usize) -> Result<bool>
fn ocr_page(doc: &PdfDocument, page: usize, engine: &OcrEngine, options: &OcrExtractOptions) -> Result<OcrOutput>
fn extract_text_with_ocr(doc: &PdfDocument, page: usize, engine: &OcrEngine, options: &OcrExtractOptions) -> Result<String>
OcrEngine
fn new(det_model_path: impl AsRef<Path>, rec_model_path: impl AsRef<Path>, dict_path: impl AsRef<Path>, config: OcrConfig) -> Result<Self>
fn from_bytes(det_model: &[u8], rec_model: &[u8], dict: &[u8], config: OcrConfig) -> Result<Self>
fn ocr_image(&self, image: &DynamicImage) -> Result<OcrOutput>
fn config(&self) -> &OcrConfig
OcrOutput::text(), OcrOutput::text_in_reading_order(), and OcrOutput::to_text_spans(scale) read the recognized text.
OcrConfig / OcrConfigBuilder
fn new() -> OcrConfig
fn v5() -> OcrConfig
fn builder() -> OcrConfigBuilder
fn det_threshold(self, threshold: f32) -> Self
fn box_threshold(self, threshold: f32) -> Self
fn rec_threshold(self, threshold: f32) -> Self
fn det_max_side(self, max_side: u32) -> Self
fn det_resize_strategy(self, strategy: DetResizeStrategy) -> Self
fn rec_target_height(self, height: u32) -> Self
fn num_threads(self, threads: usize) -> Self
fn unclip_ratio(self, ratio: f32) -> Self
fn max_candidates(self, max: usize) -> Self
fn detect_styles(self, detect: bool) -> Self
fn det_model_path(self, path: impl Into<PathBuf>) -> Self
fn rec_model_path(self, path: impl Into<PathBuf>) -> Self
fn dict_path(self, path: impl Into<PathBuf>) -> Self
fn build(self) -> OcrConfig
PDF/A, PDF/UA & PDF/X Compliance
use pdf_oxide::compliance::{validate_pdf_a, PdfAValidator, PdfALevel, ValidationResult};
fn validate_pdf_a(document: &mut PdfDocument, level: PdfALevel) -> Result<ValidationResult>
fn new() -> PdfAValidator
fn validate(&self, document: &mut PdfDocument, level: PdfALevel) -> Result<ValidationResult>
ValidationResult reports ComplianceError/ComplianceWarning lists and ValidationStats. PDF/UA accessibility and PDF/X print-production validators live alongside in pdf_oxide::compliance.
Embedded Files & Page Labels
EmbeddedFile / EmbeddedFilesBuilder
use pdf_oxide::writer::{EmbeddedFile, EmbeddedFilesBuilder, AFRelationship};
fn new(name: impl Into<String>, data: Vec<u8>) -> EmbeddedFile
fn with_description(self, description: impl Into<String>) -> Self
fn with_mime_type(self, mime_type: impl Into<String>) -> Self
fn with_creation_date(self, date: impl Into<String>) -> Self
fn with_modification_date(self, date: impl Into<String>) -> Self
fn with_af_relationship(self, relationship: AFRelationship) -> Self
fn size(&self) -> usize
fn new() -> EmbeddedFilesBuilder
fn add_file(&mut self, file: EmbeddedFile) -> &mut Self
fn files(&self) -> &[EmbeddedFile]
fn into_files(self) -> Vec<EmbeddedFile>
PageLabelsBuilder
use pdf_oxide::writer::PageLabelsBuilder;
fn new() -> Self
fn add_range(self, range: PageLabelRange) -> Self
fn decimal(self, start_page: usize) -> Self
fn roman_lower(self, start_page: usize) -> Self
fn roman_upper(self, start_page: usize) -> Self
fn alpha_lower(self, start_page: usize) -> Self
fn alpha_upper(self, start_page: usize) -> Self
fn prefixed(self, start_page: usize, prefix: &str, start_value: u32) -> Self
fn build(self) -> Object
EmbeddedFont
Custom TTF/OTF embedding for DocumentBuilder::register_embedded_font.
use pdf_oxide::writer::EmbeddedFont;
fn from_file(path: impl AsRef<Path>) -> Result<Self, String>
fn from_data(name: Option<String>, data: Vec<u8>) -> Result<Self, String>
Batch & Parallel Extraction
BatchProcessor
use pdf_oxide::batch::{BatchProcessor, BatchResult, BatchSummary};
fn new() -> Self
fn with_progress(self, callback: ProgressCallback) -> Self
fn extract_text_from_files(&self, paths: &[&Path]) -> Vec<BatchResult>
fn extract_text_from_directory(&self, dir: &Path) -> Result<Vec<BatchResult>, Error>
fn from_results(results: &[BatchResult]) -> BatchSummary
ParallelExtractor
Requires the parallel feature.
use pdf_oxide::{ParallelExtractor, extract_all_text_parallel, extract_all_markdown_parallel};
fn extract_all_text(path: &Path) -> Result<Vec<String>>
fn extract_all_markdown(path: &Path, options: &ConversionOptions) -> Result<Vec<String>>
fn extract_all_text_parallel(path: &Path) -> Result<Vec<String>>
fn extract_all_markdown_parallel(path: &Path, options: &ConversionOptions) -> Result<Vec<String>>
Free Functions
use pdf_oxide::api::merge_pdfs;
use pdf_oxide::{clear_global_font_cache, global_font_cache_stats, set_global_font_cache_capacity,
clear_cmap_cache, cmap_cache_size};
fn merge_pdfs<P: AsRef<Path>>(paths: &[P]) -> Result<Vec<u8>>
fn set_global_font_cache_capacity(capacity: usize)
fn global_font_cache_stats() -> (usize, usize)
fn clear_global_font_cache()
fn clear_cmap_cache()
fn cmap_cache_size() -> usize
Core Data Types
These structs carry extraction results. Fields are public.
TextSpan
A run of identically-styled text. Returned by extract_spans().
| Field | Type | Description |
|---|---|---|
text |
String |
The text content |
bbox |
Rect |
Bounding box |
font_name |
String |
PostScript font name |
font_size |
f32 |
Font size in points |
font_weight |
FontWeight |
Weight enum (thin → black) |
is_italic |
bool |
Italic flag |
is_monospace |
bool |
Fixed-width font flag |
color |
Color |
RGB color |
char_widths |
Vec<f32> |
Per-glyph advance widths |
rotation_degrees |
f32 |
Span rotation |
mcid |
Option<u32> |
Marked content ID (tagged PDFs) |
heading_level |
Option<u8> |
Detected heading level |
TextChar
A single positioned character. Returned by extract_chars().
| Field | Type | Description |
|---|---|---|
char |
char |
The Unicode character |
bbox |
Rect |
Bounding box |
font_name |
String |
PostScript font name |
font_size |
f32 |
Font size in points |
font_weight |
FontWeight |
Weight enum |
is_italic |
bool |
Italic flag |
color |
Color |
RGB color |
origin_x, origin_y |
f32 |
Text origin |
advance_width |
f32 |
Glyph advance |
rotation_degrees |
f32 |
Character rotation |
matrix |
Option<[f32; 6]> |
Text matrix |
mcid |
Option<u32> |
Marked content ID |
Word / TextLine / PageText
Word groups characters into a token (text, bbox, chars, avg_font_size, dominant_font, is_bold, is_italic, mcid). TextLine groups words with a bbox and joined text. PageText (from extract_page_text()) bundles spans, chars, page_width, and page_height in a single pass.
Error Handling
use pdf_oxide::{Error, Result};
Result<T> is std::result::Result<T, pdf_oxide::Error>. Error is an enum covering parse failures (Error::InvalidPdf), I/O errors, encryption/authentication failures, and out-of-range page indices.
use pdf_oxide::PdfDocument;
fn main() -> pdf_oxide::Result<()> {
let doc = PdfDocument::open("input.pdf")?;
for page in doc.page_indices() {
let text = doc.extract_text(page)?;
println!("Page {}: {} chars", page + 1, text.len());
}
Ok(())
}
Complete Example
use pdf_oxide::api::Pdf;
use pdf_oxide::writer::{DocumentBuilder, PageSize};
fn main() -> pdf_oxide::Result<()> {
// --- Creation (fluent builder) ---
DocumentBuilder::new()
.title("Report")
.author("PDF Oxide")
.letter_page()
.heading(1, "Quarterly Report")
.paragraph("Generated natively in Rust.")
.link_url("https://pdf.oxide.fyi")
.done()
.save("report.pdf")?;
// --- Creation from Markdown ---
let mut pdf = Pdf::from_markdown("# Hello\n\nFrom **PDF Oxide**.")?;
pdf.save("hello.pdf")?;
// --- Extraction + editing ---
let mut doc = Pdf::open("input.pdf")?;
println!("Pages: {}", doc.page_count()?);
let markdown = doc.to_markdown(0)?;
println!("{markdown}");
doc.set_title("Updated Title")?;
doc.rotate_all_pages(90)?;
// DOM search and replace
let mut page = doc.page(0)?;
for text in page.find_text_containing("DRAFT") {
page.set_text(text.id(), "FINAL")?;
}
doc.save_page(page)?;
// Search across the document
let hits = doc.search_with_options(
"configuration",
pdf_oxide::search::SearchOptions::case_insensitive(),
)?;
println!("Found {} matches", hits.len());
doc.save("output.pdf")?;
Ok(())
}
Other Language Bindings
PDF Oxide ships native bindings for every major ecosystem: Python, Node.js, WASM, C#, Golang, Java, PHP, Ruby, C++, Swift, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C, and Elixir.
Next Steps
- Types & Enums — all shared types and enums
- Page API Reference — consistent per-page iteration across bindings
- Getting Started with Rust — tutorial