Skip to content

The Fastest PDF Library for Rust

I was building a Rust application to process PDF documents at scale. The Rust PDF ecosystem was fragmented. Some libraries parsed structure but couldn’t extract text. Others had text extraction but failed on common document formats.

I evaluated every available Rust PDF library and found a clear winner.

I tested five Rust PDF libraries

rust_pdf_comparison.txt
| Library | Mean | p99 | Pass Rate | Text Extraction |
|-------------|------:|-----:|----------:|-----------------|
| pdf_oxide | 0.8ms | 9ms | 100% | Built-in |
| oxidize_pdf | 13.5ms| 11ms | 99.1% | Basic |
| unpdf | 2.8ms | 10ms | 95.1% | Basic |
| pdf_extract | 4.08ms| 37ms | 91.5% | Basic |
| lopdf | 0.3ms | 2ms | 80.2% | No built-in |

pdf_oxide stood out with the best combination of speed, reliability, and built-in text extraction.

pdf_oxide has a simple API

main.rs
use pdf_oxide::PdfDocument;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open("document.pdf")?;
// Basic info
println!("Pages: {}", doc.page_count());
// Extract text from a specific page
let text = doc.extract_text(0)?;
println!("Page 1 text: {}", text);
// Extract images from a page
let images = doc.extract_images(0)?;
Ok(())
}

PDF creation is straightforward

create_pdf.rs
use pdf_oxide::api::Pdf;
use pdf_oxide::api::PdfBuilder;
use pdf_oxide::writer::PageSize;
// Quick creation from markdown
let pdf = Pdf::from_markdown("# Hello World\n\nContent.")?;
pdf.save("output.pdf")?;
// With more control
let pdf = PdfBuilder::new()
.title("My Document")
.author("Developer")
.page_size(PageSize::A4)
.margin(72.0)
.from_markdown("# Content")?;
pdf.save("custom.pdf")?;

Why lopdf isn’t enough

lopdf is fast (0.3ms) but lacks built-in text extraction. You’d need to implement text extraction yourself, which is complex:

lopdf_example.rs
use lopdf::Document;
let doc = Document::load("document.pdf")?;
// Now you need to parse content streams yourself
// No extract_text() method available

Why I chose pdf_oxide

  1. Speed: 0.8ms mean, matches lopdf’s fast parsing
  2. Reliability: 100% pass rate on 3,830 test PDFs
  3. Built-in text extraction: No need to implement it yourself
  4. Additional features: Image extraction, Markdown conversion, PDF creation

Summary

In this post, I compared Rust PDF libraries. pdf_oxide is the fastest with built-in text extraction and 100% reliability.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments