Skip to Content
NexPDF

NexPDF for C and C++

Render, extract, edit, convert, sign and validate PDFs from C++17 with a header-only RAII layer over the NexPDF C ABI, or from C with nexpdf.h.

English

NexPDF for C and C++ (github.com/nexdevit/nexpdf-cpp) is a header-only C++17 layer, nexpdf.hpp, over the C ABI of the native NexPDF engine, with RAII and exceptions. C programs include nexpdf.h and call the C functions directly.

Every function of the C ABI is available. Functions that take a document are methods of nexdevit::nexpdf::Document; the others are functions in namespace nexdevit::nexpdf. Options and results are the same JSON strings as in every NexPDF SDK; parse them with your JSON library.

#include <iostream>
#include <nexpdf.hpp>

namespace nexpdf = nexdevit::nexpdf;

int main() {
    auto doc = nexpdf::Document::open("contract.pdf");
    std::cout << doc.page_count() << " " << doc.page_width(0) << " x " << doc.page_height(0) << "\n";
    std::cout << doc.extract_page_text(0) << "\n";
}

Requirements

CompilerC++17 (nexpdf.hpp) or C99 (nexpdf.h)
BuildCMake 3.16 or later, or any build system that sets an include path and links a library
Operating systemsLinux (x86_64, arm64), macOS (Apple silicon and Intel), Windows (x86_64)
Native librarylibnexpdf_ffi.so, libnexpdf_ffi.dylib or nexpdf_ffi.dll (shared), or the static library, from the release
DependenciesNone. The examples use nlohmann/json to parse JSON results, as an example only

How it works

  • Document owns a native document handle and frees it in its destructor. It is move-only; reset() frees it at once, and using a moved-from or reset document throws std::logic_error. handle() gives the C pointer for direct calls to nexpdf.h.
  • Failures throw nexdevit::nexpdf::Error, a std::runtime_error with the engine's message. A rejected license sets code().
  • Byte buffers are std::vector<uint8_t>, page lists std::vector<uint32_t>, and optional string parameters are std::optional<std::string>: trailing ones default to std::nullopt, which the engine reads as its default.
  • Use one document from one thread at a time. Different documents can be used on different threads, and doc.copy() gives an independent copy.
  • The guides use three small helpers, read_file, read_text and write_file, defined in Getting started.

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