A Rust library for PDF document manipulation.
open sourceMITself-hostablefree
lopdf is a Rust library that loads a PDF into an in-memory object model (dictionaries, streams, object IDs) that you can read, change and save again, or build up from nothing. It parses and writes cross-reference streams and object streams, decrypts and encrypts documents, extracts text from pages, edits content streams, deletes and renumbers pages and objects, compresses streams, works with bookmarks and outlines, and can append incremental updates to an existing file. Optional features add async loading with Tokio, serde support, image embedding and TrueType font embedding via skrifa. It works at the level of PDF objects, so tasks such as merging documents are written by the caller, as its README's examples show.
Problems it solves
- open an existing PDF in Rust, change some objects and save it again
- merge several PDF files into one from a Rust program
- delete pages from a PDF or renumber its objects in Rust
- pull the text out of PDF pages in Rust without a C library
- decrypt a PDF that has an empty user password so my Rust code can process it
- rewrite a page's content stream to add or replace drawing operations
- make PDFs smaller by packing objects into object streams and compressing streams
- read a PDF's bookmarks, outline and table of contents from Rust
- append an incremental update to a PDF instead of rewriting the whole file
- build a PDF object by object with a dictionary macro in Rust
- load PDFs asynchronously in a Tokio service
- replace the XML data packet inside a PDF form's XFA stream and save the file from Rust
- edit one stream object in an existing PDF and write the change as an incremental update
Features
- load, edit and save PDF documents as an object model
- create PDFs from scratch with a dictionary! macro and content operations
- object streams and cross-reference streams (PDF 1.5+), reading and writing
- decryption (automatic for empty passwords) and encryption
- text extraction from pages
- delete pages, prune and renumber objects, compress and decompress streams
- bookmarks, outlines, destinations and table of contents
- incremental updates through IncrementalDocument
- optional async loading (Tokio), serde, image embedding and TrueType font embedding via skrifa
- parallel object-stream and cross-reference parsing with rayon
Limitations
- Doesn't stream large PDFs: it keeps the whole document in memory as objects until it saves the file1
- May not decrypt every encrypted PDF: some encryption algorithms aren't fully supported, and only empty passwords open automatically1
Capabilities
| Has official SDKs | plan not known |
|---|
Alternatives
The same job
These do what lopdf does.
- pdfium-render A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project.
- pdf-rs Rust library to read, manipulate and write PDF files.
- pdf-writer A step-by-step PDF writer.
- qpdf A content-preserving PDF document transformer
- pdfcpu PDF tooling for Go and the command line
- pdf-lib Create and modify PDF documents in any JavaScript environment.
