Skip to content

Справочник Rust API

PDF Oxide — это нативный Rust-крейт. Крейт pdf_oxide служит источником истины для всех остальных привязок (Python, JavaScript/WASM, Go, C#, Java и C ABI). На этой странице описана публичная поверхность Rust API для v0.3.69.

# Cargo.toml
[dependencies]
pdf_oxide = "0.3.69"

Опциональные feature-флаги: 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

Для других языков см. Справочник Python API, Справочник Node.js API или Справочник WASM API, а также Типы и перечисления.

Почти каждый метод, который может завершиться ошибкой, возвращает pdf_oxide::Result<T> (псевдоним для Result<T, pdf_oxide::Error>). В приведённых ниже сигнатурах завершающая обёртка -> Result<...> опускается только там, где это отмечено.


Pdf

pdf_oxide::api::Pdf — это единый высокоуровневый фасад для создания, открытия, извлечения, редактирования и сохранения PDF. Он лениво конструирует DocumentEditor при первом вызове редактирования/извлечения, поэтому большинство методов принимают &mut self.

use pdf_oxide::api::Pdf;

Создание

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>

Создание нового PDF из Markdown, HTML, HTML+CSS, простого текста, одного или нескольких изображений, QR-кода или одномерного штрих-кода. Варианты *_with_fonts / *_css встраивают пользовательские шрифты TTF/OTF.

Открытие

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>

Сведения о документе и метаданные

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<()>

Извлечение текста и содержимого

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<()>

Извлечение по областям

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(...) возвращает PdfPageRegion, чьи методы filter_mode(), extract_text(), extract_words(), extract_text_lines(), extract_chars(), extract_rects(), extract_lines(), extract_images() и extract_tables() работают в пределах единого обрезающего прямоугольника.

Поиск

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<()>

Рендеринг

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<()>

Требует feature-флаг rendering.

Геометрия страницы

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<()>

Стирание / забеливание

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

Редактирование с цензурой

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)

Экспорт данных форм и вложенные файлы

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)

Работа с изображениями

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

Метки страниц и метаданные XMP

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

fn page(&mut self, index: usize) -> Result<PdfPage>
fn save_page(&mut self, page: PdfPage) -> Result<()>

page(i) возвращает DOM-подобный PdfPage для поэлементного редактирования (см. PdfPage); save_page записывает изменённую страницу обратно.

Сохранение

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 настраивает метаданные, размер страницы, поля и типографику перед созданием 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 — это низкоуровневый ридер: открытие, парсинг, расшифровка и все примитивы извлечения. Он основан на &self и ориентирован на чтение; оберните его в DocumentEditor (или используйте Pdf), чтобы изменять и сохранять.

use pdf_oxide::PdfDocument;

Открытие и аутентификация

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>

Сведения о документе

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>

Геометрия страницы

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>

Извлечение текста

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>

Извлечение с фильтрацией и по областям

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

Векторные контуры и таблицы

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

Изображения и шрифты

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>)>>

Опциональное содержимое (слои)

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

Конвертация форматов

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

Очистка пробелов / колонтитулов

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<()>

Классификация и извлечение через OCR

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 требуют feature-флаг ocr (или ocr-tract).


DocumentEditor

pdf_oxide::editor::DocumentEditor — это изменяемый слой редактирования, стоящий за Pdf: метаданные, операции со страницами, слияние, формы, цензурирование, работа с изображениями и сохранение. Получите его через DocumentEditor::open(...), from_document или Pdf::open_editor.

use pdf_oxide::editor::DocumentEditor;

Конструирование и сохранение

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() и SaveOptions::with_encryption(config) управляют стратегией сохранения.

Метаданные

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>)

Операции со страницами

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<()>

Геометрия страницы

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-редактирование страницы

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

Стирание и сведение

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]

Вложенные файлы

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-формы

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

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<()>

Редактирование с цензурой

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>

Работа с изображениями

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 — это fluent-API генерации PDF, ориентированный на страницы. Каждая страница строится с помощью FluentPageBuilder, возвращаемого методами page(), letter_page() или a4_page().

use pdf_oxide::writer::{DocumentBuilder, 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 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

Создание страниц и вывод

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

Построитель страницы, возвращаемый методом DocumentBuilder::page(). Вызовы выстраиваются в цепочку; done() возвращает управление обратно DocumentBuilder.

Позиционирование и текст

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

Аннотации

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

Виджеты форм

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

Графика, изображения и таблицы

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-подобный дескриптор страницы из Pdf::page() / DocumentEditor::get_page(). Запрашивайте элементы, редактируйте текст и управляйте аннотациями, а затем записывайте изменения обратно через save_page.

use pdf_oxide::editor::PdfPage;

Запросы

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>

Редактирование

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

Аннотации

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-элементов

Обёртки над элементами, возвращаемые запросами PdfPage. Доступ ко всем осуществляется через PdfElement, который диспетчеризует по типу.

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

Возвращается методом DocumentEditor::get_form_fields(). Оборачивает прочитанное поле или ожидающий виджет и предоставляет типизированные геттеры и сеттеры.

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_none(), as_text() -> Option<&str>, as_bool() -> Option<bool>, as_choice() -> Option<&str>, as_multi_choice() -> Option<&[String]>.


OfficeConverter

pdf_oxide::converters::OfficeConverter конвертирует DOCX/XLSX/PPTX в байты PDF. Требует feature-флаг office.

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() и Margins::none() создают предустановки полей для OfficeConfig.


Рендеринг

Требует feature-флаг rendering. Свободные функции работают напрямую с PdfDocument; PageRenderer предоставляет переиспользуемый настраиваемый рендеринг.

use pdf_oxide::rendering::{render_page, render_page_region, render_page_fit, flatten_to_images,
                           PageRenderer, RenderOptions, RenderedImage, ImageFormat};

Свободные функции

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<()>

Поиск

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

Электронные подписи

Требует feature-флаг signatures. Подписывайте с помощью PdfSigner, проверяйте через SignatureVerifier и перечисляйте существующие подписи через 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

Вспомогательные свободные функции: sign_pdf_bytes(...) и 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>

Перечисление

fn enumerate_signatures(doc: &mut PdfDocument) -> Result<Vec<SignatureInfo>>
fn count_signatures(doc: &mut PdfDocument) -> Result<usize>

Метки времени (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

Требует feature-флаг ocr (нативный ONNX) или ocr-tract (чистый Rust). Управляйте конвейером в стиле PaddleOCR через OcrEngine, настраиваемый с помощью OcrConfig.

use pdf_oxide::ocr::{OcrEngine, OcrConfig, detect_page_type, needs_ocr, ocr_page, extract_text_with_ocr};

Определение типа страницы

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() и OcrOutput::to_text_spans(scale) читают распознанный текст.

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

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 сообщает о списках ComplianceError/ComplianceWarning и ValidationStats. Валидаторы доступности PDF/UA и подготовки к печати PDF/X находятся рядом, в pdf_oxide::compliance.


Вложенные файлы и метки страниц

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

Встраивание пользовательских шрифтов TTF/OTF для 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>

Пакетное и параллельное извлечение

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

Требует feature-флаг parallel.

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

Свободные функции

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

Основные типы данных

Эти структуры несут результаты извлечения. Поля являются публичными.

TextSpan

Фрагмент текста с одинаковым стилем. Возвращается методом extract_spans().

Поле Тип Описание
text String Содержимое текста
bbox Rect Ограничивающий прямоугольник
font_name String PostScript-имя шрифта
font_size f32 Размер шрифта в пунктах
font_weight FontWeight Перечисление насыщенности (thin → black)
is_italic bool Флаг курсива
is_monospace bool Флаг моноширинного шрифта
color Color Цвет RGB
char_widths Vec<f32> Ширины продвижения для каждого глифа
rotation_degrees f32 Поворот фрагмента
mcid Option<u32> ID размеченного содержимого (тегированные PDF)
heading_level Option<u8> Определённый уровень заголовка

TextChar

Один позиционированный символ. Возвращается методом extract_chars().

Поле Тип Описание
char char Символ Unicode
bbox Rect Ограничивающий прямоугольник
font_name String PostScript-имя шрифта
font_size f32 Размер шрифта в пунктах
font_weight FontWeight Перечисление насыщенности
is_italic bool Флаг курсива
color Color Цвет RGB
origin_x, origin_y f32 Начало текста
advance_width f32 Продвижение глифа
rotation_degrees f32 Поворот символа
matrix Option<[f32; 6]> Матрица текста
mcid Option<u32> ID размеченного содержимого

Word / TextLine / PageText

Word группирует символы в токен (text, bbox, chars, avg_font_size, dominant_font, is_bold, is_italic, mcid). TextLine группирует words с bbox и объединённым text. PageText (из extract_page_text()) собирает spans, chars, page_width и page_height за один проход.


Обработка ошибок

use pdf_oxide::{Error, Result};

Result<T> — это std::result::Result<T, pdf_oxide::Error>. Error — это перечисление, покрывающее ошибки парсинга (Error::InvalidPdf), ошибки ввода-вывода, сбои шифрования/аутентификации и выход индекса страницы за границы.

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(())
}

Полный пример

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 предоставляет нативные привязки для всех основных экосистем: Python, Node.js, WASM, C#, Golang, Java, PHP, Ruby, C++, Swift, Kotlin, Dart, R, Julia, Zig, Scala, Clojure, Objective-C, и Elixir.

Дальнейшие шаги