talira

pdf-writer

A step-by-step PDF writer.

open sourceMIT OR Apache-2.0self-hostablefree

pdf-writer is a low-level Rust crate from the Typst project that writes PDF files object by object. You build the document into one internal buffer through strongly typed writers for each PDF structure (catalog, pages, content streams, fonts, images, annotations, interactive form fields, signature fields, tagged-structure elements, colour spaces and ICC profiles), and each writer finishes its object when it's dropped. It leaves the document's design to you: you choose the object IDs, write the content stream operators and make sure the result is valid. It forbids unsafe code, and the higher-level krilla crate is built on it.

Problems it solves

  • write PDF files from Rust with full control over every object and dictionary
  • emit PDF content streams (paths, text operators, images) directly from my own layout engine
  • I'm building a typesetting or report engine in Rust and need a fast PDF backend with no hidden magic
  • create AcroForm fields and signature fields in a PDF I generate in Rust
  • write tagged PDF structure elements for accessibility from my Rust renderer
  • embed CID fonts with ToUnicode CMaps so text in my generated PDF can be copied and searched
  • generate PDFs in Rust without unsafe code or C dependencies
  • write ICC output intents and separation colour spaces into a PDF for print
  • add outlines, named destinations and link annotations to PDFs my program writes
  • low-allocation PDF serializer for a Rust document pipeline that produces many files

Features

  • strongly typed writers for pages, fonts, images, annotations, actions and more
  • content stream builder for PDF drawing and text operators
  • interactive form fields (AcroForm), including signature fields and seed values
  • tagged PDF: structure tree, role maps, marked content and attributes
  • Type 0, CID, Type 1 and Type 3 fonts, CMaps, widths and font descriptors
  • colour spaces: ICC profiles, Separation, DeviceN, shading and tiling patterns, output intents
  • embedded files, outlines, page labels, name and number trees, transitions and renditions
  • chunks that can be written separately and renumbered
  • writers deref to plain dictionaries for fields the typed API doesn't expose
  • unsafe code forbidden

Limitations

  • Doesn't validate the PDF you write: it doesn't allocate object IDs or check that every required field is present, so you follow the PDF spec yourself1

Capabilities

Has official SDKsplan not known

Alternatives

The same job

These do what pdf-writer does.

  1. lopdf A Rust library for PDF document manipulation.
  2. krilla A high-level, ergonomic Rust library for creating PDF documents.
  3. ironpress HTML to PDF. In process. In pure Rust.

Compare pdf-writer with the top 3