Skip to main content

Crate folio_pdf

Crate folio_pdf 

Source
Expand description

§Folio PDF — A comprehensive PDF library for Rust

Folio provides full-featured PDF reading, writing, and manipulation.

§Quick Start

§Open a PDF and read pages

use folio_pdf::prelude::*;

let mut doc = PdfDoc::open("document.pdf")?;
println!("Pages: {}", doc.page_count()?);

let page = doc.get_page(1)?;
println!("Size: {}x{}", page.width(), page.height());

§Extract text

use folio_pdf::prelude::*;

let mut doc = PdfDoc::open("document.pdf")?;
let page = doc.get_page(1)?;
let text = TextExtractor::extract_from_page(&page, doc.cos_mut())?;
println!("{}", text);

§Read form fields

use folio_pdf::prelude::*;

let data = std::fs::read("form.pdf")?;
let mut doc = CosDoc::open(data)?;
for field in AcroForm::get_fields(&mut doc)? {
    println!("{}: {:?} = {:?}", field.name(), field.field_type(), field.value());
}

§Read bookmarks

use folio_pdf::prelude::*;

let data = std::fs::read("document.pdf")?;
let mut doc = CosDoc::open(data)?;
for (bookmark, depth) in Bookmark::get_all(&mut doc)? {
    println!("{}{}", "  ".repeat(depth as usize), bookmark.title());
}

§Module Organization

ModuleDescription
corePrimitive types: Rect, Matrix2D, Point, ColorPt, PdfDate, errors
cosLow-level PDF object model, parser, serializer, CosDoc
docHigh-level PdfDoc, Page, DocInfo
contentContent stream parsing, operators, graphics state
fontFont loading, encoding tables, Unicode mapping
textText extraction and search
annotAnnotation types (highlight, text, link, widget, etc.)
formsAcroForm fields (text, checkbox, radio, choice, signature)
navBookmarks, destinations, actions
filtersStream compression/decompression (Flate, ASCII85, LZW, etc.)

Modules§

annot
PDF annotations. PDF annotation types — reading, creating, and modifying annotations.
content
Content stream parsing and graphics state. PDF content stream parsing and graphics state.
core
Core types: Rect, Matrix2D, Point, ColorPt, PdfDate, FolioError. Core primitive types for the Folio PDF library.
cos
Low-level COS object model and PDF parser. COS (Carousel Object System) object model and PDF parser.
doc
High-level PDF document and page model. High-level PDF document model.
filters
Stream filters (compression/decompression). PDF stream filter pipeline.
font
Font loading, encoding, and Unicode mapping. PDF font handling — loading, metrics, encoding, and Unicode mapping.
forms
Interactive form fields. PDF interactive forms (AcroForms).
image
Image embedding and extraction. PDF image handling — embedding, extracting, and reading image XObjects.
nav
Bookmarks, destinations, and actions. PDF navigation: bookmarks (outlines), destinations, and actions.
prelude
Prelude — import this for the most commonly used types.
text
Text extraction. PDF text extraction and search.

Type Aliases§

Error
Convenience type alias for the library’s error type.
Result
Convenience type alias for Results.