flpdf 0.1.7

A pure-Rust PDF toolkit modeled on qpdf — read, rewrite, linearize, and inspect PDFs.
Documentation
//! `flpdf` is a pure-Rust PDF toolkit modeled on the qpdf workflow.
//!
//! The crate is organised as a few small layers that you can mix as needed:
//!
//! - [`Pdf`] is the parsed-but-lazy document handle. [`Pdf::open`] reads the trailer
//!   and cross-reference table, then resolves objects on demand via [`Pdf::resolve`].
//! - [`Object`], [`Dictionary`], [`Stream`], and [`ObjectRef`] are the data model.
//! - [`pages`], [`outline`], and [`fonts`] are traversal helpers built on top of
//!   `Pdf`. They mirror the read-only inspection surface that `qpdf --show-pages`,
//!   `--show-outline`, and `--show-fonts` provide.
//! - [`write_pdf`] performs an incremental rewrite (preserving the source bytes and
//!   appending an updated xref/trailer) and [`write_qdf`] produces a flat, qdf-style
//!   dump of every resolved object.
//! - [`check_reader`] reports diagnostics gathered during parsing/repair, returning a
//!   [`CheckReport`] of [`Diagnostic`]s.
//!
//! # End-to-end example
//!
//! ```no_run
//! use std::fs::File;
//! use std::io::BufReader;
//! use flpdf::{pages, write_pdf, Pdf};
//!
//! let file = BufReader::new(File::open("input.pdf")?);
//! let mut pdf = Pdf::open(file)?;
//!
//! for object_ref in pages::page_refs(&mut pdf)? {
//!     println!("page: {object_ref}");
//! }
//!
//! let mut out = File::create("output.pdf")?;
//! write_pdf(&mut pdf, &mut out)?;
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! Errors flow through the unified [`Error`] enum and the crate-level [`Result`] alias,
//! except for the small [`object::ParseObjectRefError`] returned by
//! [`ObjectRef::parse`].

// Mechanically enforce threat-model guarantee (a): no undefined behaviour. The
// crate contains no `unsafe` blocks, so this attribute keeps it that way.
#![forbid(unsafe_code)]

pub mod acroform_document_helper;
pub mod acroform_field_prune;
pub mod annotation_helper;
pub mod appearance;
pub(crate) mod ascii85;
pub(crate) mod ascii_hex;
pub mod attachment_list;
pub mod cache;
pub mod check;
pub mod content_stream;
pub mod default_appearance;
pub mod diagnostics;
pub mod embedded_files;
pub mod encrypt_setup;
pub mod error;
pub mod filespec_helper;
pub mod filters;
pub mod fonts;
pub mod json;
pub mod json_inspect;
pub mod linearization;
pub mod name_number_tree;
pub mod object;
pub mod object_copy;
pub mod objr_obj_annot_p;
pub mod outline;
pub mod outline_dest_remap;
pub mod outline_document_helper;
pub(crate) mod overlay;
pub mod page_annotation_enum;
pub mod page_annotation_flatten;
pub mod page_closure;
pub mod page_collate;
pub mod page_combine;
pub mod page_document_helper;
pub mod page_extract;
pub(crate) mod page_form_xobject;
pub mod page_label_document_helper;
pub mod page_merge;
pub mod page_object_helper;
pub mod page_plan;
pub mod page_range;
pub mod page_rotate;
pub mod page_splice;
pub mod page_split;
pub mod page_tree_rebuild;
pub mod pages;
pub mod parser;
pub mod permissions;
pub mod qdf_fix;
pub mod reader;
pub(crate) mod ref_chain;
pub mod resources;
pub(crate) mod rewrite_renumber;
pub mod rotate_spec;
pub(crate) mod run_length;
pub mod signatures;
pub mod standard_font_metrics;
pub mod struct_tree_pg;
pub mod subset_prune;
pub mod thread_bead_p;
pub mod writer;
pub mod xref;

// Internal security primitives — not part of the public API.
pub(crate) mod security;

pub use acroform_document_helper::{AcroFormDocumentHelper, AcroFormFieldInfo};
pub use acroform_field_prune::{
    prune_acroform_after_subset, prune_acroform_after_subset_with_max_depth,
    DEFAULT_MAX_ACROFORM_DEPTH,
};
pub use annotation_helper::{AnnotationObjectHelper, FormFieldObjectHelper};
pub use appearance::{
    generate_button_field_appearance, generate_choice_field_appearance,
    generate_text_field_appearance,
};
pub use attachment_list::{format_attachment_list, list_attachment_info, AttachmentInfo};
pub use cache::{CacheEntry, ObjectCache};
pub use check::{
    check_reader, check_reader_strict, check_reader_with_options,
    check_reader_with_options_and_limits, CheckReport, CheckSummary,
};
pub use content_stream::{
    normalize_content_stream, ContentParseOptions, ContentStreamParser, ContentToken,
};
pub use default_appearance::{parse_default_appearance, DefaultAppearance, TextColor};
pub use diagnostics::{Diagnostic, Diagnostics, Severity};
pub use embedded_files::{
    delete_embedded_file, insert_embedded_file, list_embedded_files,
    list_embedded_files_with_max_depth, remove_attachment, DEFAULT_MAX_EMBEDDED_FILES_DEPTH,
};
pub use encrypt_setup::{CopyEncryptionSource, EncryptMethod, EncryptParams};
pub use error::{EncryptedError, Error, Result};
pub use filespec_helper::{
    add_attachment_from_path, copy_attachments_from, encode_utf16be, extract_attachment,
    extract_attachment_to_path, format_pdf_date, md5_checksum, write_attachment,
    EmbeddedFileStream, FileParamDates, FileSpec, FileSpecBuilder,
};
pub use name_number_tree::{
    build_name_tree, build_number_tree, read_name_tree, read_number_tree, DEFAULT_MAX_TREE_DEPTH,
    LEAF_MAX,
};
pub use object::{Dictionary, Object, ObjectRef, ParseObjectRefError, Stream};
pub use object_copy::copy_objects;
pub use objr_obj_annot_p::drop_objr_obj_annot_dangling_p;
pub use outline::OutlineItem;
pub use outline_dest_remap::{remap_outline_and_dests, remap_outline_and_dests_with_max_depth};
pub use outline_document_helper::{Dest, OutlineDocumentHelper, OutlineNode};
pub use overlay::{apply_overlay_specs, OverlayKind, OverlaySpec};
pub use page_annotation_enum::{
    enumerate_document_annotations, enumerate_page_annotations, EnumeratedAnnotation,
};
pub use page_annotation_flatten::{flatten_annotations, flatten_annotations_on_page, FlattenMode};
pub use page_collate::collate;
pub use page_combine::{CombinedPage, CombinedPlan, InputSpec};
pub use page_document_helper::PageDocumentHelper;
pub use page_extract::{extract_page, extract_pages};
pub use page_label_document_helper::{LabelRange, LabelStyle, PageLabelDocumentHelper};
pub use page_merge::{merge_documents, MergeInput};
pub use page_object_helper::{PageBox, PageObjectHelper};
pub use page_plan::{PagePlan, SelectedPage};
pub use page_range::{Endpoint, PageRange, PageRangeEntry, Parity};
pub use page_rotate::{
    apply_rotate_to_pages, compose_rotate, flatten_rotation_on_pages, normalize_rotate,
    resolve_inherited_rotate, resolve_inherited_rotate_with_max_depth, RotateMode, RotateOp,
};
pub use page_splice::{splice_pages, splice_pages_with_max_depth};
pub use page_split::{digit_width, split_output_path, split_pages};
pub use page_tree_rebuild::{rebuild_page_tree, rebuild_page_tree_with_max_depth, RebuildResult};
pub use parser::parse_object;
pub use permissions::{PermissionsConfig, PrintPermission};
pub use qdf_fix::fix_qdf;
pub use reader::{EncryptionInfo, Pdf, PdfOpenOptions, Permissions};
pub use resources::{remove_unreferenced_resources, RemoveUnreferencedResources};
pub use rotate_spec::RotateSpec;
pub use security::password::PasswordMode;
pub use security::standard::ObjectKeyAlg;
pub use signatures::{
    acroform_sig_flags, clear_sig_flags, disable_digital_signatures, remove_security_restrictions,
    signature_rewrite_impact, signatures, signatures_with_max_depth, strip_signature_values,
    would_rewrite_invalidate_signatures, SignatureInfo, SignatureRewriteImpact,
    SignatureRewriteReason, SignatureWriteMode, DEFAULT_MAX_SIGNATURE_FIELD_DEPTH,
    SIG_FLAGS_APPEND_ONLY, SIG_FLAGS_SIGNATURES_EXIST,
};
pub use standard_font_metrics::StandardFont;
pub use struct_tree_pg::{
    drop_struct_elem_dangling_pg, drop_struct_elem_dangling_pg_with_max_depth,
    DEFAULT_MAX_STRUCT_TREE_DEPTH,
};
pub use subset_prune::prune_after_subset;
pub use thread_bead_p::drop_thread_bead_dangling_p;
pub use writer::{
    apply_stream_compress_policy, effective_pdf_version, parse_pdf_version, write_pdf,
    write_pdf_with_options, write_qdf, write_stream_to_buf, CompressStreams,
    NewlineBeforeEndstream, ObjectStreamMode, StreamDataMode, WriteOptions,
};
pub use xref::{
    load_xref_and_trailer, load_xref_and_trailer_best_effort, load_xref_and_trailer_with_repair,
    LoadedXref, XrefForm, XrefOffset,
};

/// Crate version, mirroring `Cargo.toml`'s `[package].version`.
pub fn version() -> &'static str {
    env!("CARGO_PKG_VERSION")
}