Skip to Content
NexPDF

Installation

Install the NexPDF PHP package with Composer, enable the FFI extension, and make the native engine library available.

English

Install the package

composer require nexdevit/nexpdf

The classes are autoloaded from the Nexdevit\NexPdf namespace.

Enable FFI

The package needs ext-ffi. Its default setting, ffi.enable=preload, allows FFI only in the CLI and in preloaded scripts. For PHP-FPM, Apache or any other web server, enable it in php.ini:

php.ini
extension=ffi
ffi.enable=true
php -m | grep FFI

Get the native library

Download the archive for your platform from the v1.1.0 release. Each archive holds a folder nexpdf-ffi-1.1.0-<platform> with include/nexpdf.h and the libraries in lib/:

PlatformArchiveLibrary
Linux x86_64nexpdf-ffi-1.1.0-linux-x64.tar.gzlib/libnexpdf_ffi.so
Linux arm64nexpdf-ffi-1.1.0-linux-arm64.tar.gzlib/libnexpdf_ffi.so
macOSnexpdf-ffi-1.1.0-macos-universal.tar.gzlib/libnexpdf_ffi.dylib
Windows x86_64nexpdf-ffi-1.1.0-windows-x64.ziplib/nexpdf_ffi.dll

Tell the SDK where the library is

The library is looked up in this order:

  1. Nexdevit\NexPdf\Native::load($path), called before any other NexPDF call;
  2. the NEXPDF_LIB_PATH environment variable (the full path of the file);
  3. the NEXPDF_LIB_DIR environment variable (the folder holding it);
  4. lib/ in the package folder, next to src/ (for example vendor/nexdevit/nexpdf/lib/);
  5. the system loader (LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PATH).
export NEXPDF_LIB_PATH=/opt/nexpdf/lib/libnexpdf_ffi.so

or, in code:

use Nexdevit\NexPdf\Native;

Native::load('/opt/nexpdf/lib/libnexpdf_ffi.so');

Under PHP-FPM, environment variables of the shell are not passed to the workers by default: set env[NEXPDF_LIB_PATH] in the pool configuration, or call Native::load.

Check the installation

php -r 'require "vendor/autoload.php"; echo Nexdevit\NexPdf\NexPdf::version(), "\n";'

Docker

Dockerfile
FROM php:8.3-cli
RUN apt-get update && apt-get install -y libffi-dev && docker-php-ext-install ffi
ADD https://github.com/nexdevit/nexpdf-php/releases/download/v1.1.0/nexpdf-ffi-1.1.0-linux-x64.tar.gz /tmp/
RUN tar -xzf /tmp/nexpdf-ffi-1.1.0-linux-x64.tar.gz -C /opt
ENV NEXPDF_LIB_DIR=/opt/nexpdf-ffi-1.1.0-linux-x64/lib
COPY . /app
WORKDIR /app

On this page