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
| Module | Description |
|---|---|
core | Primitive types: Rect, Matrix2D, Point, ColorPt, PdfDate, errors |
cos | Low-level PDF object model, parser, serializer, CosDoc |
doc | High-level PdfDoc, Page, DocInfo |
content | Content stream parsing, operators, graphics state |
font | Font loading, encoding tables, Unicode mapping |
text | Text extraction and search |
annot | Annotation types (highlight, text, link, widget, etc.) |
forms | AcroForm fields (text, checkbox, radio, choice, signature) |
nav | Bookmarks, destinations, actions |
filters | Stream 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.