Skip to main content

Crate pivot_pdf

Crate pivot_pdf 

Source
Expand description

PDF creation library for Rust.

pivot-pdf provides a high-level API for building PDF documents programmatically. It is designed for low memory usage, making it suitable for SaaS applications that generate many documents (invoices, reports, contracts, bills of material, etc.).

§Quick Start

use pivot_pdf::{DocumentOptions, PdfDocument, BuiltinFont, Rect, TextFlow, TextStyle};

let mut doc = PdfDocument::new(Vec::<u8>::new(), DocumentOptions::default()).unwrap();
doc.set_info("Title", "Hello World");
doc.begin_page(612.0, 792.0);
doc.place_text("Hello, world!", 72.0, 720.0);
doc.end_page().unwrap();
let pdf_bytes = doc.end_document().unwrap();

§Key Types

  • PdfDocument — the main entry point for building documents
  • TextFlow — flowing styled text across multiple pages
  • Table — rendering tabular data with flexible styling
  • BuiltinFont — the 14 standard PDF fonts (no embedding required)

§Feature Highlights

  • Incremental page writing: each page is flushed to the writer as it completes, keeping memory constant regardless of document size.
  • TrueType fonts: embed custom fonts from .ttf files.
  • JPEG and PNG images: embed with automatic fit/fill/stretch modes.
  • FlateDecode compression: enable with PdfDocument::set_compression.
  • PDF merge: combine existing PDFs with merge_pdfs.

Re-exports§

pub use document::DocumentOptions;
pub use document::FormFieldError;
pub use document::Origin;
pub use document::PdfDocument;
pub use fonts::BuiltinFont;
pub use fonts::FontRef;
pub use fonts::TrueTypeFontId;
pub use graphics::Angle;
pub use graphics::Color;
pub use images::ImageFit;
pub use images::ImageId;
pub use merger::merge_pdfs;
pub use merger::MergeOptions;
pub use merger::PdfMergeError;
pub use reader::PdfReadError;
pub use reader::PdfReader;
pub use tables::Cell;
pub use tables::CellOverflow;
pub use tables::CellStyle;
pub use tables::Row;
pub use tables::Table;
pub use tables::TableCursor;
pub use tables::TextAlign;
pub use textflow::FitResult;
pub use textflow::Rect;
pub use textflow::TextFlow;
pub use textflow::TextStyle;
pub use textflow::WordBreak;

Modules§

document
High-level PDF document builder.
fonts
Font types and metrics.
graphics
Color types for PDF graphics.
images
Image loading and placement.
merger
PDF merge operations.
objects
PDF object types (ISO 32000-1:2008 §7.3).
reader
PDF reader for parsing existing PDF files.
tables
Table rendering for tabular data.
textflow
Flowing text layout across bounding boxes.
truetype
TrueType font parsing and embedding.
writer
Low-level PDF binary writer.