Skip to main content

folio_pdf/
lib.rs

1//! # Folio PDF — A comprehensive PDF library for Rust
2//!
3//! Folio provides full-featured PDF reading, writing, and manipulation.
4//!
5//! ## Quick Start
6//!
7//! ### Open a PDF and read pages
8//!
9//! ```no_run
10//! use folio_pdf::prelude::*;
11//!
12//! let mut doc = PdfDoc::open("document.pdf")?;
13//! println!("Pages: {}", doc.page_count()?);
14//!
15//! let page = doc.get_page(1)?;
16//! println!("Size: {}x{}", page.width(), page.height());
17//! # Ok::<(), folio_pdf::Error>(())
18//! ```
19//!
20//! ### Extract text
21//!
22//! ```no_run
23//! use folio_pdf::prelude::*;
24//!
25//! let mut doc = PdfDoc::open("document.pdf")?;
26//! let page = doc.get_page(1)?;
27//! let text = TextExtractor::extract_from_page(&page, doc.cos_mut())?;
28//! println!("{}", text);
29//! # Ok::<(), folio_pdf::Error>(())
30//! ```
31//!
32//! ### Read form fields
33//!
34//! ```no_run
35//! use folio_pdf::prelude::*;
36//!
37//! let data = std::fs::read("form.pdf")?;
38//! let mut doc = CosDoc::open(data)?;
39//! for field in AcroForm::get_fields(&mut doc)? {
40//!     println!("{}: {:?} = {:?}", field.name(), field.field_type(), field.value());
41//! }
42//! # Ok::<(), folio_pdf::Error>(())
43//! ```
44//!
45//! ### Read bookmarks
46//!
47//! ```no_run
48//! use folio_pdf::prelude::*;
49//!
50//! let data = std::fs::read("document.pdf")?;
51//! let mut doc = CosDoc::open(data)?;
52//! for (bookmark, depth) in Bookmark::get_all(&mut doc)? {
53//!     println!("{}{}", "  ".repeat(depth as usize), bookmark.title());
54//! }
55//! # Ok::<(), folio_pdf::Error>(())
56//! ```
57//!
58//! ## Module Organization
59//!
60//! | Module | Description |
61//! |--------|-------------|
62//! | [`core`] | Primitive types: `Rect`, `Matrix2D`, `Point`, `ColorPt`, `PdfDate`, errors |
63//! | [`cos`] | Low-level PDF object model, parser, serializer, `CosDoc` |
64//! | [`doc`] | High-level `PdfDoc`, `Page`, `DocInfo` |
65//! | [`content`] | Content stream parsing, operators, graphics state |
66//! | [`font`] | Font loading, encoding tables, Unicode mapping |
67//! | [`text`] | Text extraction and search |
68//! | [`annot`] | Annotation types (highlight, text, link, widget, etc.) |
69//! | [`forms`] | AcroForm fields (text, checkbox, radio, choice, signature) |
70//! | [`nav`] | Bookmarks, destinations, actions |
71//! | [`filters`] | Stream compression/decompression (Flate, ASCII85, LZW, etc.) |
72
73/// Core types: `Rect`, `Matrix2D`, `Point`, `ColorPt`, `PdfDate`, `FolioError`.
74pub mod core;
75
76/// Low-level COS object model and PDF parser.
77pub mod cos;
78
79/// High-level PDF document and page model.
80pub mod doc;
81
82/// Content stream parsing and graphics state.
83pub mod content;
84
85/// Font loading, encoding, and Unicode mapping.
86pub mod font;
87
88/// Text extraction.
89pub mod text;
90
91/// Image embedding and extraction.
92pub mod image;
93
94/// PDF annotations.
95pub mod annot;
96
97/// Interactive form fields.
98pub mod forms;
99
100/// Bookmarks, destinations, and actions.
101pub mod nav;
102
103/// Stream filters (compression/decompression).
104pub mod filters;
105
106/// Convenience type alias for the library's error type.
107pub type Error = crate::core::FolioError;
108
109/// Convenience type alias for Results.
110pub type Result<T> = crate::core::Result<T>;
111
112/// Prelude — import this for the most commonly used types.
113///
114/// ```
115/// use folio_pdf::prelude::*;
116/// ```
117pub mod prelude {
118    // Document types
119    pub use crate::doc::{DocInfo, Page, PdfDoc};
120
121    // Low-level access
122    pub use crate::cos::CosDoc;
123
124    // Text extraction and search
125    pub use crate::text::{SearchOptions, SearchResult, TextExtractor, TextSearch};
126
127    // Images
128    pub use crate::image::{PdfImage, add_image_to_page};
129
130    // Annotations
131    pub use crate::annot::{Annot, AnnotFlags, AnnotType};
132
133    // Forms
134    pub use crate::forms::{AcroForm, Field, FieldFlags, FieldType};
135
136    // Navigation
137    pub use crate::nav::{Action, ActionType, Bookmark, Destination, FitType};
138
139    // Core types
140    pub use crate::core::{ColorPt, FolioError, Matrix2D, PdfDate, Point, QuadPoint, Rect, Result};
141}