Installation
Install the NexPDF PHP package with Composer, enable the FFI extension, and make the native engine library available.
Install the package
composer require nexdevit/nexpdfThe 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:
extension=ffi
ffi.enable=truephp -m | grep FFIGet 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/:
| Platform | Archive | Library |
|---|---|---|
| Linux x86_64 | nexpdf-ffi-1.1.0-linux-x64.tar.gz | lib/libnexpdf_ffi.so |
| Linux arm64 | nexpdf-ffi-1.1.0-linux-arm64.tar.gz | lib/libnexpdf_ffi.so |
| macOS | nexpdf-ffi-1.1.0-macos-universal.tar.gz | lib/libnexpdf_ffi.dylib |
| Windows x86_64 | nexpdf-ffi-1.1.0-windows-x64.zip | lib/nexpdf_ffi.dll |
Tell the SDK where the library is
The library is looked up in this order:
Nexdevit\NexPdf\Native::load($path), called before any other NexPDF call;- the
NEXPDF_LIB_PATHenvironment variable (the full path of the file); - the
NEXPDF_LIB_DIRenvironment variable (the folder holding it); lib/in the package folder, next tosrc/(for examplevendor/nexdevit/nexpdf/lib/);- the system loader (
LD_LIBRARY_PATH,DYLD_LIBRARY_PATH,PATH).
export NEXPDF_LIB_PATH=/opt/nexpdf/lib/libnexpdf_ffi.soor, 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
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