PDFlib in PHP HowTo
PDFlib in PHP HowTo
Last change: February 17, 2011 Latest PDFlib version covered in this document: 8.0.2 Latest version of this document available at: www.pdflib.com/developer/technical-documentation Contact: PDFlib GmbH Franziska-Bilek-Weg 9 80339 Mnchen, Germany phone +49 89 452 33 84-0 [email protected] www.pdflib.com
2 Supported Platforms
Loadable PHP extension modules implemented as DSOs (dynamic shared objects, also called dynamic link library DLL) are the recommended method of using PDFlib with PHP. PHP supports dynamic loading of extensions from DSOs on the following platforms (only platforms supported by PDFlib GmbH are mentioned here): > Microsoft Windows > Mac OS X 10.6 (see Section 2.2, Platforms where PHP does not reliably support DSOs for older versions) > Linux on x86 and ia64 > Linux on zSeries > FreeBSD 6/7 on x86 > Sun Solaris 10 on x86 and Sparc > HP-UX 11 > AIX 5/6 32-bit (the AIX binary can also be used on IBM i5/iSeries) > IBM i5/iSeries (see Section 6.4, Installing and Using the PDFlib DSO on i5/iSeries) The PDFlib 8.0.2 distribution packages shipped by PDFlib GmbH contain PDFlib DSOs for a number of PHP versions. These are grouped into several directories as follows (not all PHP versions are supported on all platforms, though): > bind/php/php-510 for PHP 5.1.0 5.1.6 > bind/php/php-520 for PHP 5.2.0 5.2.17 > bind/php/php-530 for PHP 5.3.0 5.3.5 Depending on the compatibility properties of the PHP distribution PDFlib may also work with newer versions of PHP, but we have only tested the combinations above. Using commercial PDFlib packages with PHP on platforms with DSO support. PDFlib GmbH makes available packages with precompiled binary PDFlib DSOs for several platforms and PHP versions. If such a package is available for your combination of platform and PHP proceed with Section 6, Deploying the PDFlib DSO.
If you don't find a PDF section check your log files to find the reason. If the output created 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 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 extension will also be shown. The PDFlib product examples. The distribution package of your PDFlib product includes 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:
$ cp bind/php/*.php .../htdocs $ cp bind/data/* .../htdocs/data
> point your browser to the URLs of the examples > enjoy the generated PDFs
Starting with PHP 5.2 we also offer Windows binaries of the PDFlib PHP binding which have been built without support for thread safety. These binaries are named as follows (ZTS refers to Zend Thread Safety, a threading abstraction layer):
bind/php/php-<version>-nozts/libpdf_php.dll
Since PHP 5.3 the precompiled PHP binaries for Windows (php.exe) come in two incompatible flavors: one is compiled with Visual Studio 6, while the other is compiled with Visual Studio 2008 (also called VS9). The VS9 versions of the PDFlib PHP binding are located in directories ending with _VS9, e.g.
bind/php/php-<version>_VS9/libpdf_php.dll
For the PHP installation process please follow the documentation of your PHP distribution and 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 use the DLL in the php-<version>-nozts_VS9 directory, and must rename libpdf_php.dll to php_ pdf.dll.
Copy the PDFlib DSO to the directory which is specified in the extension_dir line in php.ini. The standard Unix versions of the PDFlib DSO have been built without multithread support. However, the binaries
bind/php/php-<version>mt/libpdf_php.so
which are available for some platforms, are PDFlib DSOs for use with versions of PHP which include Zend Thread Safety (ZTS) support.
(on Windows)
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)
or
dl("libpdf_php.so"); (on Unix; adjust the shared library suffix if necessary)
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.
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.2 or PHP 5.3 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. Since PASE is not an emulation: since i5/iSeries and AIX are based on the same POWER processor architecture, 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/partnerworld/wps/servlet/ContentHandler/pw_com_porting_ibmi_pase
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 environment, 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-8.0.x-AIX-php.tar.gz
> Unpack the PDFlib package for AIX, using any of the available tools for unpacking .tar.gz packages. > Locate libpdf_php.so and copy it to the extension_dir of Zend Server. The output of phpinfo( ) shows the exact location of this directory. > Rename the new copy of libpdf_php.so to php_pdf.so to match the naming conventions used in Zend Server. Add the following line to your php.ini (again, the exact location of this directory is shown in the phpinfo( ) output):
extension=php_pdf.so
> As an alternative to the previous step you can also load the PDFlib DSO directly from your script without configuring it in php.ini (note that for security reasons this method is no longer recommended):
dl("php_pdf.so");
All of these options must match. PHP on Mac OS X 10.5 and earlier. The PDFlib DSOs works fine with the native PHP version bundled with Mac OS X 10.6 (Snow Leopard). However, Apples PHP version which is bundled with Mac OS X 10.4 and 10.5 does not work with PDFlib DSOs. To use PHP with PDFlib on Mac OS X 10.5 and earlier you need third-party PHP packages such as MAMP or XAMPP for Mac. Mac OS X 10.5 (Leopard) suffers from an additional restriction: as described in developer.apple.com/releasenotes/CoreFoundation/CoreFoundation.html it is no longer possible to use CoreFoundation functions after a call to fork( ) without exec( ). However, CoreFoundation functions are required for PDFlibs host font feature, and the critical sequence above is used in the combination of Apache and PHP. This may trigger the following error message in the Apache log (and may even crash the Apache process):
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on _THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_ FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
In order to work around this problem you can run PHP as a CGI on Apache, or disable the host font feature in PDFlib using the following call:
PDF_set_parameter($p, "debug", "h");
PDFlib with XAMPP or MAMP on Mac OS X 10.6 and older. If you add the PDFlib PHP extension to your php.ini on a Mac OS X Intel machine which has XAMPP installed, the following error message appears:
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. We detected that commenting out DYLD_LIBRARY_PATH in xamppfiles/bin/envvars cures this problem. If you have MAMP installed, the following error message may appear in the log file:
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php5.3/ lib/php/extensions/no-debug-non-zts-20090626/libpdf_php.so' - dlopen(/Applications/MAMP/ bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/libpdf_php.so, 9): Symbol not found: __cg_jpeg_resync_to_restart Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib Expected in: /Applications/MAMP/Library/lib/libjpeg.8.dylib in /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ ImageIO.framework/Versions/A/Resources/libTIFF.dylib in Unknown on line 0
To cure the problem with MAMP comment out DYLD_LIBRARY_PATH in Library/bin/ envvars. PDFlib with XAMPP on Linux. Some versions of system libraries bundled with the XAMPP package may trigger the following error message:
Warning: PHP Startup: Unable to load dynamic library '/opt/lampp/htdocs/test/pdf/pdflib/ bind/php/php-530/libpdf_php.so' - /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/libstdc++.so.6) in Unknown on line 0
In this case you must disable the following two lines in the file bin/envvars, e.g. by adding a comment character at the start of the line:
#binbuild LD_LIBRARY_PATH="/opt/lampp/lib/:$LD_LIBRARY_PATH" #binbuild export LD_LIBRARY_PATH
10
11