How To Use Pdflib With PHP: 1 Scope of This Document
How To Use Pdflib With PHP: 1 Scope of This Document
The methods for deploying any of these products as a PHP extension are the same in all
cases. However, only one product can be used at a time. Similarly, multiple versions of
these products cannot be deployed at the same time. Note that the evaluation versions
of commercial PDFlib products will be fully functional, but will display a demo stamp
across all generated PDF pages unless a valid license key is applied.
This document applies to the following software versions:
> PDFlib 5 and 6, as well as all maintenance versions of each
> PHP 4.2.0 or above, and PHP 5 as well as all maintenance versions of each.
Using commercial PDFlib packages with PHP on platforms with DSO support. PDFlib
GmbH makes available packages with precompiled binary PDFlib DSOs for several plat-
forms and PHP versions. If such a package is available for your combination of platform
and PHP proceed with Section 5, »Deploying the PDFlib DSO«.
If a PDFlib DSO is not available you need the appropriate precompiled PDFlib C lib-
rary for your platform (available for all platforms supported by PDFlib GmbH), and
must build a PDFlib DSO for PHP according to Section 6, »Building a DSO from a PDFlib
C library«.
Using PDFlib Lite with PHP on platforms with DSO support. In order to use PDFlib Lite
you need PDFlib source code, and must proceed according to Section 7, »Building PDFlib
Lite from Source«. Once you’ve done this you must build a PDFlib DSO for PHP accord-
ing to Section 6, »Building a DSO from a PDFlib C library«.
Using commercial PDFlib packages with PHP on platforms without DSO support. You
need the appropriate precompiled PDFlib C library for your platform, and must rebuild
PHP according to Section 8, »Building PHP with statically linked PDFlib«.
Using PDFlib Lite with PHP on platforms without DSO support. In order to use PDFlib
Lite you need PDFlib Lite source code and must first build a PDFlib Lite C library accord-
ing to Section 7, »Building PDFlib Lite from Source«. Next, you must rebuild PHP accord-
ing to Section 8, »Building PHP with statically linked PDFlib«.
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 installation and configura-
tion with the following mini PHP script:
<?phpinfo()?>
If you don't find a PDF section check your log files to find the reason. If the output creat-
ed by phpinfo( ) contains the line PDFlib GmbH Binary Version you are using a precompiled
PDFlib DSO provided by PDFlib GmbH. If you see a line PDFlib GmbH Version you are us-
ing 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 extension will also
be shown.
Note If the output of phpinfo( ) shows only »PDFlib Version« you are using an old PDFlib extension
wrapper from a PHP 4 distribution. This combination is not supported.
The PDFlib examples. The PDFlib distribution packages include with two flavours of
examples which you can use to test your installation. In the php-43x directory you will
find the old-style examples using the functional API. These examples can be used for
PHP 4 and PHP5 .
In the php-50x directory you can find the new object-oriented examples. These will
work only with PHP 5 or above. To use the examples proceed as follows:
> Copy some files to your htdocs directory:
$ cp bind/php/php-<version>/*.php .../htdocs
$ cp bind/data/* .../htdocs/data
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.
This section applies to the prebuilt DSOs distributed by PDFlib GmbH, as well as to DSOs
which you have built yourself.
For the PHP installation process please follow the documentation of your PHP distribu-
tion, and copy the PDFlib DSO to the directory which is specified in the extension_dir line
in php.ini.
Copy the PDFlib DSO to the directory which is specified in the extension_dir line in
php.ini.
or
extension=libpdf_php.so (on Unix; adjust the shared library suffix if necessary)
and restart your Web server so that the changes are recognized.
Loading the PDFlib DSO explicitly in your PHP script. Without the extension line in
php.ini you must include the following line in your PHP scripts:
dl("libpdf_php.dll"); (on Windows)
The line extension_dir is not relevant in this case. Note that for security reasons this
method is no longer recommended; many Web hosters do not allow it.
Note Maintainers of Linux and PHP distributions should include PDFlib support for PHP as DSO be-
cause this facilitates updates.
Binary characteristics of PHP and PDFlib DSO must match. Several properties of your
PHP binary must match those of the PDFlib DSO. These properties are determined when
building PHP, and cannot be changed afterwards. The precompiled DSOs for PDFlib have
been built as follows:
> non-debug version
> for supported PHP versions see bind/php/php-<version>
> thread-safe (mostly relevant for Windows)
If you see an error message similar to the following when trying to load the PDFlib DSO,
your PHP build number does not match that of the PDFlib module:
Warning: pdf: Unable to initialize module
Module compiled with debug=0, thread-safety=0 module API=20020429
PHP compiled with debug=0, thread-safety=1 module API=20020429
and supply the path where PDFlib is installed at the following prompt:
path to pdflib installation? : $HOME/pdflib-6.0.x/bind/c
This will create a PDFlib module called pdf.so (or similar, depending on platform). After
building the extension you should check your php.ini to make sure that the extension
was added properly, and restart Apache to activate the new module.
On Unix systems (for Windows see readme-source-windows.txt in the PDFlib Lite distri-
bution) unpack the PDFlib Lite source code, change to the created directory, and issue
the following commands:
$ ./configure
$ make
$ make install
This will create a PDFlib Lite C library. For more details see readme-source-unix.txt in the
PDFlib Lite distribution.
The last step in the sequence above will install the library and include files to some
local directory. By default these files will be installed to some system directory, which
means that sysadmin permissions are required. However, you can also install to some
private (non-privileged) directory by using the --prefix option in the initial call to the
configure script, e.g.
$ ./configure --prefix=$HOME
Note that the installation will automatically create libs and include subdirectories under
the specified prefix.
If DSOs don’t work in your situation you must rebuild PHP from source code in order to
include PDFlib support. This step must be done within the PHP build process. Below you
will find an overview on how to achieve this, but you’ll have to refer the PHP documen-
tation for more details.
Building PHP. Unpack PHP, configure and build it to your needs. We recommend to
initially try this without PDFlib support in order to get accustomed with the process.
Prepare the PDFlib C library. For the commercial PDFlib product: unpack the PDFlib C
library and note the full path to the bind/c directory in this package.
For PDFlib Lite: build the PDFlib Lite C library according to Section 7, »Building PDFlib
Lite from Source«.
Prepare the PECL Package. Create an ext/pdf directory in your PHP source tree. Unpack
the PECL package for PDFlib, and move the content of this package (including pdf.c, php_
pdf.h and others) to the ext/pdf directory of your PHP source tree.
Put everything together. Change to the PHP source directory and follow these steps:
# rebuild the PHP configure script:
$ ./buildconf --force
$ make
....
Build complete.
(It is safe to ignore warnings about tempnam and tmpnam).
# install it as root
$ sudo make install
# probably you have to configure your Web server to load the new php module