PDFlib

PDFlib is a development tool for PDF-enabling your software or generating PDF on your server. PDFlib offers a simple-to-use API for programmatically creating PDF files from within your own server- or client-side software. PDFlib doesn't make use of third-party software for generating PDF, nor does it require any other tools. It is considerably more powerful, efficient and full-featured than PHP's built-in PDF functions.

Installing PDFlib for PHP is easy, but you'll need to install your own copy of PHP. If you already have a custom installation, you may skip the next two sections.

Installing PHP 5
In order to use low-level extensions like PDFlib, you should compile a custom install of PHP. I'll adapt the relevant portions of the install guide here:

 Copy the main PHP5 Install Script into a text editor and replace your.domain.com on the 9th line with your site's domain name. MAKE SURE YOU USE THE SAME DOMAIN NAME AND CASE THAT APPEARS IN THE DIRECTORY LISTING (UPPER or lower). For example, if your domain is listed as DOMAIN.COM instead of WWW.DOMAIN.COM, make sure you use DOMAIN.COM. Copy the new contents to your clipboard. Log in to your account using SSH Create a new file to save the script to. I use pico as my editor here just because that's what I'm used to, but use whatever you prefer. pico installscript  Paste the text into your session window, hit Ctrl-O  to save, Ctrl-X to exit the editor. Make the file executable by entering the command: chmod +x installscript  Run the script by entering the command: ./installscript  </ol>

If you receive any errors, follow the procedures on the Installing PHP5 page.

After your screen settles down and PHP is done, confirm that under the domain you installed to you see a cgi-bin folder with the file php.cgi inside. If not, you probably made a typo when you entered your domain name into the install script. In that case, go back to your home directory and look for a new folder with your mistyped domain name. Copy cgi-bin to your domain directory.

Now you need to edit your .htaccess file appropriately. Add something like:

AddHandler phpFive .php Action phpFive /cgi-bin/php.cgi

to a file called .htaccess and place it in the root folder of your domain you specified above (/home/YOUR USERNAME/YOUR DOMAIN HERE/.htaccess)

Verifying Your PHP Installation
To make sure your custom install worked, enter the following into a file called test.php (or something similar) and stick it in the root directory of the domain you're working with.

<?php phpinfo; ?>

From your browser, load your test page and check the information it presents. Under the section called Configuration File Path, if you see the location /etc/php5/cgi/php.ini, something went wrong and you should check the Installing PHP5 page and get things straightened out before you continue. Otherwise, if you see a location that begins /home/, everything went okay.

Installing PDFlib
The following instructions assume you'll download the package to /home/YOUR USERNAME/. At the time of this writing, PDFlib is at version 7.0.5, but as newer versions are released you'll need to modify the filenames below. The newest version of PDFlib can always be located at their site.

<ol> Download and expand PDFlib.

wget http://www.pdflib.com/binaries/PDFlib/705/PDFlib-7.0.5-Linux-php.tar.gz

tar -xvvzf PDFlib-7.0.5-Linux-php.tar.gz </li> Go to your domain's cgi-bin directory and copy PDFlib to it.

cp ../../PDFlib-7.0.5-Linux-php/bind/php5/php-520/libpdf_php.so.

The php-520 may need to be changed for future releases of PHP and PDFlib.</li> Now copy your php.ini to cgi-bin.

cp ../../php5/etc/php5/YOUR DOMAIN HERE/php.ini. </li> Verify your extension directory. I use pico here just because that's what I'm used to, but use whatever you prefer.

pico php.ini

Ctrl-W to find extension_dir

Make sure extension_dir = "./"</li> Now, add the following line somewhere in php.ini.

extension=libpdf_php.so

If you're using pico, then hit Ctrl-O to save, Ctrl-X to exit.</li></ol>

Verifying Your PDFlib Installation
To make sure everything worked, enter the following into a file called test.php (or something similar) and stick it in the root directory of the domain you're working with.

<?php phpinfo; ?>

From your browser, load your test page and check the information it presents. You should have a new section called pdf which will look something like this:

You're done!

Further Help
You can always ask people for assistance at the Dreamhost forums.

Please note that most of the operations supplied by PDFLib could be easily performed by GhostScript through the command gs.