NexPDF for Rust
Render, extract, edit, convert, sign and validate PDFs from Rust with the NexPDF engine, through safe bindings over its C library.
NexPDF for Rust (the crate nexpdf-sdk, imported as nexpdf_sdk) is a safe API over the native
NexPDF engine (libnexpdf_ffi). It links the engine's C library at build time, statically or
dynamically, and has no other dependency.
Every function of the C ABI is available. Functions that take a document are methods of
nexpdf_sdk::Document; those that create a document (from_html, open_office,
template_docx_to_pdf, ...) are associated functions of Document; the rest are functions of the
crate root. Options and results are the same JSON strings as in every NexPDF SDK. With the serde
feature, every *_json function also has a *_json_value twin that returns a serde_json::Value.
use nexpdf_sdk::Document;
fn main() -> nexpdf_sdk::Result<()> {
let doc = Document::open("contract.pdf")?;
println!("{} pages, {} x {} pt", doc.page_count()?, doc.page_width(0), doc.page_height(0));
println!("{}", doc.extract_page_text(0)?);
Ok(())
}The crate is called nexpdf-sdk because nexpdf is the name of the engine's own Rust crate, which
is not distributed.
Requirements
| Rust | 1.70 or later (edition 2021) |
| Operating systems | Linux (x86_64, arm64), macOS (Apple silicon and Intel), Windows (x86_64, MSVC), iOS, Android |
| Native library | libnexpdf_ffi from the release archive for your platform, linked by the nexpdf-sys build script |
| Dependencies | None (serde_json with the optional serde feature) |
The SDK is two crates:
| Crate | What it is |
|---|---|
nexpdf-sdk | The safe API: Document (freed on drop), every C function as a method or function returning Result<T, nexpdf_sdk::Error>, license::activate, version() |
nexpdf-sys | The raw extern "C" declarations, and the build script that links libnexpdf_ffi |
How it works
Documentowns a native document handle and frees it when dropped.- Every call returns
nexpdf_sdk::Result<T>.Error::Enginecarries the engine's message;Error::Licensecarries the negative code of a rejected key. See Error handling. - Methods take
&selfwhen the C function takes aconstdocument and&mut selfwhen it changes the document. - String parameters take
&str,&StringorOption<&str>, whereNonepasses NULL (the C default). Byte buffers are&[u8], page lists&[u32]; strings come back asString, buffers asVec<u8>. DocumentisSendbut notSync: a document can move to another thread, but only one thread may use it at a time. Different documents work in parallel, andtry_clone()gives an independent copy.
Getting started
Installation
The crate, the native library, static or dynamic linking.
Your first document
Open a PDF, render a page and extract its text.
Add your license key
Activate a key and handle license errors.
Running without a key
View-only mode, the watermark and trial keys.
Guides
Opening and saving
Files, bytes, passwords, pictures, HTML and Office input.
Rendering
Pages and thumbnails to PNG, coordinates.
Document structure
Metadata, bookmarks, page labels, layers, attachments.
Text extraction
Text, Markdown, positioned blocks, passages for LLMs.
Search
Find text and its rectangles.
OCR
Make scanned pages searchable, in any script.
Structured extraction
Tables, key-values, schema extraction with your LLM, classification.
Barcodes
Read QR, Data Matrix, PDF417 and linear codes; draw barcodes.
Annotations
Markup, shapes, ink, stamps, measurements, XFDF.
Forms
Fill, create, calculate, flatten, import and export.
XFA forms
Run FormCalc and JavaScript, lay out dynamic forms, convert to AcroForm, flatten.
Comment threads
Replies and review states on annotations.
Real-time collaboration
Sync pages, annotations, comments, form values and bookmarks.
Editing
Merge, split, reorder, crop; edit text and images.
Compare and optimise
Diff versions, shrink files, control memory.
Word-level comparison
Inserted, deleted, replaced and moved text; annotated PDF.
Security
Encryption, permissions, watermarks, Bates numbers.
Redaction
Remove content for good by area, text or pattern.
Signatures
PAdES signing, external signers, verification.
Long-term signatures
PAdES B-LTA, document and archive timestamps.
Conversion
PDF to Word, Excel, PowerPoint, HTML and more.
Templates
PDFs from Word, HTML and PDF templates and JSON data.
PDF/A, PDF/X and PDF/UA
Archiving, print and accessibility.
PDF/A and PDF/UA validation
PDF/A and PDF/UA-1 and -2 with clause ids; convert to PDF/A or PDF/UA.