PDFlib in PHP HowTo PDF
PDFlib in PHP HowTo PDF
PDFlib in PHP HowTo PDF
with PHP
Last change: June 4, 2019
Latest PDFlib version covered in this document: 9.2.0
Latest version of this document available at:
www.pdflib.com/documentation/howtos/
Contact:
PDFlib GmbH
Franziska-Bilek-Weg 9
80339 München, Germany
phone +49 • 89 • 452 33 84-0
support@pdflib.com
www.pdflib.com
Most of the PDFlib information applies to other PDFlib GmbH products analogously.
Notes for the following products are included where applicable:
> PDFlib TET (Text and Image Extraction Toolkit)
> PDFlib PLOP (Linearization, Optimization, Protection) and PLOP DS (Digital Signa-
ture)
The methods for deploying any of these products as a PHP extension are the same in all
cases. Multiple versions of these products cannot be deployed at the same time. Howev-
er, multiple products can coexist within one PHP installation. Evaluation versions of
PDFlib products are fully functional, but display a demo stamp across all generated PDF
pages unless a valid license key is applied. Other PDFlib GmbH products have other re-
strictions in evaluation mode (see documentation).
Supported PHP versions. The distribution packages shipped by PDFlib GmbH contain
DSOs for a variety of PHP versions. These are grouped into several directories as follows
(not all PHP versions are supported on all platforms, though):
> bind/php/php-540 for PHP 5.4.0 and above
> bind/php/php-550 for PHP 5.5.0 and above
> bind/php/php-560 for PHP 5.6.0 and above
> bind/php/php-700 for PHP 7.0.0 and above
> bind/php/php-710 for PHP 7.1.0 and above
> bind/php/php-720 for PHP 7.2.0 and above
> bind/php/php-730 for PHP 7.3.0 and above
Thread safety. On most platforms two variants of the PHP binary are available, and
the PDFlib DSO must match the selected PHP version:
> Thread-safe (TS): this version should generally be used when loading PHP as a mod-
ule into a Web server. The thread-safe version should be used when loading PHP as
an Apache module.
> Non-thread-safe (NTS): this version includes nts in the directory name and should
generally be used when using PHP in a Web server through FastCGI protocol, work-
ing with the command-line interface (CLI), or integrating PHP with IIS via FastCGI.
Refer to the PHP Web site for more information regarding TS and NTS versions of PHP.
It may help to classify yourself according to these types of developers. The remainder of
this document describes tasks which require at least sysadmin or C developer skills. PHP
developers without additional knowledge or assistance will not be able to perform the
required steps without assistance.
The PHP info page. You can test the success of your PDFlib product installation and
configuration with the following mini PHP script:
<?phpinfo()?>
you are using your own PDFlib DSO or custom PHP with a statically linked PDFlib.
The version number of the PECL module which has been used to build the PDFlib ex-
tension will also be shown.
> If you don't find any PDFlib section check your log files to determine the reason.
The PDFlib product examples. The distribution package of your PDFlib product in-
cludes two flavors of examples which you can use to test your installation. In the bind/
php directory you can find PDFlib programming examples. To use the examples proceed
as follows:
> Copy the PHP samples and data files to your htdocs directory or another directory
which has been configured appropriately in the Web server:
$ cp bind/php /path/to/htdocs
$ cp bind/data /path/to/htdocs
You are a Web hosting provider. As a provider you should be aware of the following:
> Although PDFlib Lite source code is freely available, and many Linux and PHP distri-
butions contain PDFlib Lite, the PDFlib Lite license does not cover free use of PDFlib
Lite on a Web hoster’s systems.
> You can install commercial PDFlib DSOs even without obtaining a license. In this sit-
uation you can install one of the precompiled PDFlib DSOs supplied by PDFlib GmbH
without a license key (i.e. a demo stamp will be created). Those among your custom-
ers who wish to commercially use it can obtain a commercial license to disable the
demo stamp. In other words, you can offer PDFlib without the need for obtaining a li-
cense for all of your servers. The recommended method is to install the PDFlib DSO
in some globally accessible directory, and set the extension= line in php.ini appropri-
ately.
> Alternatively, if (like an increasing number of providers) you believe in PDFlib avail-
ability as a competitive advantage, you can obtain a site license which covers all your
servers and customers. Individual users will no longer be required to obtain a license
on their own in this case. Please contact PDFlib GmbH if you are interested in more
details.
Requirements:
> Skill level: sysadmin
> The PDFlib DSO, either built on your own or (preferably) from a binary package pro-
vided by PDFlib GmbH at www.pdflib.com/download/pdflib-product-family/
> Working PHP binary
This section applies to the precompiled DSOs distributed by PDFlib GmbH, as well as to
DSOs which you have built yourself.
Copy the PDFlib DSO to the directory which is specified in the extension_dir line in
php.ini.
Using PDFlib with Zend Server. In order to use PDFlib with Zend Server you must in-
stall the DSO php_pdflib.so from the php-<version> directory. Copy this DSO to the exten-
sion directory and restart PHP.
Step 1: Temporarily disable System Integrity Protection (SIP). This requires rebooting
into recovery mode:
> Restart the system and press cmd-R until the Apple logo appears.
> Select Terminal from the Utilities menu.
> In the window that opens type csrutil disable and press return to disable System In-
tegrity Protection.
> Choose Restart from the Apple menu.
Step 2: Install the PDFlib DSO in the PHP extension directory. Copy the appropriate
version of the PDFlib DSO to the extension directory of the preinstalled PHP binary, e.g.
cp bind/php/php-710-nts/php_pdflib.so /usr/lib/php/extensions/no-debug-non-zts-20160303/
Step 3: Enable System Integrity Protection again. This requires rebooting again:
> Restart the system and press cmd-R until the Apple logo appears.
> Select Terminal from the Utilities menu.
> In the window that opens type csrutil enable and press return to enable System Integ-
rity Protection. This ensures that your machine is fully protected by SIP.
> Choose Restart from the Apple menu.
Now configure the PDFlib extension for PHP with one of the methods described in the
next section.
and restart your Web server so that the changes are recognized.
Custom pdflib.ini file. If your PHP version supports additional .ini files parsing you
can create a pdflib.ini configuration file with a single line as follows (adjust the shared li-
brary suffix .dll as necessary for your platform, e.g. .so):
extension=php_pdflib.dll
The requirements for using PDFlib with PHP on i5/iSeries are as follows:
> Zend Server for IBM i or Zend Server Community Edition (CE) for IBM i
> PHP 5.4 or above
Zend Server for IBM i is based on the Portable Application Solutions Environment (PASE
for i), an »integrated runtime for porting selected applications from AIX systems«. PASE
is not an emulation: since i5/iSeries and AIX are based on the same POWER processor ar-
chitecture, PASE uses the processor directly. There are no performance disadvantages
when using PASE. More details about PASE can be found on the following IBM Web site:
www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzalf/rzalfintro.htm
Perform the following steps to use PDFlib with Zend Server for IBM i:
> Since Zend Server and the underlying Apache Web server are based on the PASE envi-
ronment, you must use the PDFlib package for AIX, not the PDFlib package for i5/
iSeries. Download the following package from the PDFlib Web site:
PDFlib-9.x.y-AIX-php.tar.gz
> Unpack the PDFlib package for AIX, using one of the available tools for unpacking
.tar.gz packages.
> Locate php_pdflib.so and copy it to the extension_dir of Zend Server. The output of
phpinfo( ) shows the exact location of this directory.
All of these options must match. In the example above it was attempted to load the
non-thread-safe DSO into a thread-safe PHP binary.
In this case you must disable the following two lines in the file bin/envvars, e.g. by add-
ing a comment character at the start of the line:
#binbuild LD_LIBRARY_PATH="/opt/lampp/lib/:$LD_LIBRARY_PATH"
#binbuild export LD_LIBRARY_PATH
PDFlib with XAMPP on Linux Intel 64. If you are using the 32-bit edition of XAMPP you
must use the 32-bit edition of PDFlib for this combination. However, you may see the
following error message:
Warning: PHP Startup: Unable to load dynamic library
'/opt/lampp/htdocs/test/pdf/PDFlib-x.y.z-Linux-php/bind/php/php-710/php_pdflib.so'
- libstdc++.so.6: wrong ELF class: ELFCLASS64 in Unknown on line 0
The reason for this error is that while XAMPP includes some of the 32-bit runtime librar-
ies required for PDFlib, one important runtime library is still missing. You must install
the 32-bit version of libstdc++.so.6 on the system. For example, on Debian systems this
can be achieved with the following command:
apt-get install ia32-libs
6.6.3 macOS
PDFlib with XAMPP on macOS. If you add the PDFlib PHP extension to your php.ini on
an macOS Intel machine which has XAMPP installed, the following error message ap-
pears:
dyld: NSLinkModule() error
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/
Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /Applications/xampp/xamppfiles/lib/libjpeg.62.dylib
The PDFlib extension is linked against the ApplicationServices Framework, and XAMPP
changes the DYLD_LIBRARY_PATH. This combination confuses the dynamic link editor.