Skip to Content
NexPDF

NexPDF for Rust

Render, extract, edit, convert, sign and validate PDFs from Rust with the NexPDF engine, through safe bindings over its C library.

English

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

Rust1.70 or later (edition 2021)
Operating systemsLinux (x86_64, arm64), macOS (Apple silicon and Intel), Windows (x86_64, MSVC), iOS, Android
Native librarylibnexpdf_ffi from the release archive for your platform, linked by the nexpdf-sys build script
DependenciesNone (serde_json with the optional serde feature)

The SDK is two crates:

CrateWhat it is
nexpdf-sdkThe safe API: Document (freed on drop), every C function as a method or function returning Result<T, nexpdf_sdk::Error>, license::activate, version()
nexpdf-sysThe raw extern "C" declarations, and the build script that links libnexpdf_ffi

How it works

  • Document owns a native document handle and frees it when dropped.
  • Every call returns nexpdf_sdk::Result<T>. Error::Engine carries the engine's message; Error::License carries the negative code of a rejected key. See Error handling.
  • Methods take &self when the C function takes a const document and &mut self when it changes the document.
  • String parameters take &str, &String or Option<&str>, where None passes NULL (the C default). Byte buffers are &[u8], page lists &[u32]; strings come back as String, buffers as Vec<u8>.
  • Document is Send but not Sync: a document can move to another thread, but only one thread may use it at a time. Different documents work in parallel, and try_clone() gives an independent copy.

Getting started

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.

Help and reference

On this page