Skip to Content
NexPDF

NexPDF for PHP

Render, extract, edit, convert, sign and validate PDFs from PHP 8.1+ with the NexPDF engine, in-process through the FFI extension.

English

NexPDF for PHP (nexdevit/nexpdf, namespace Nexdevit\NexPdf) loads the native NexPDF engine in-process through PHP's FFI extension. There is no compiled PHP extension to install and no other Composer dependency.

Every function of the C ABI is available. Functions that take a document are methods of Nexdevit\NexPdf\Document; the others are static methods of Nexdevit\NexPdf\NexPdf. Options and results are the same JSON strings as in every NexPDF SDK, and json_decode($json, true) parses them.

<?php
require __DIR__ . '/vendor/autoload.php';

use Nexdevit\NexPdf\Document;

$doc = Document::open('contract.pdf');
echo $doc->pageCount(), ' ', $doc->pageWidth(0), ' x ', $doc->pageHeight(0), "\n";
echo $doc->extractPageText(0), "\n";

Requirements

PHP8.1 or later, with ext-ffi
Operating systemsLinux (x86_64, arm64), macOS (Apple silicon and Intel), Windows (x86_64)
Native librarylibnexpdf_ffi.so, libnexpdf_ffi.dylib or nexpdf_ffi.dll from the release
DependenciesNone

How it works

  • Document wraps a native document handle. It is freed when the object is destroyed, or at once with close(). A closed document throws LogicException; isClosed() tells whether it is closed.
  • Failures throw Nexdevit\NexPdf\NexPdfException, a RuntimeException with the engine's message. A rejected license sets the exception code (getCode()).
  • Byte buffers are PHP binary strings (as read by file_get_contents), page lists are arrays of int, and optional trailing strings default to null.
  • $doc->copy() gives an independent copy, for example for undo snapshots.

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