View Full Version : Using PHP to create a PDF with PDFlib

October 30th, 2009, 01:21 AM
I am attempting to create an Adobe Acrobat doc on the fly using the PHP5 library PDFlib. However, when I run the test.php script the browser times out and gives an HTTP 500 internal server error stating that the site is either under maintenance or has a programming error.

Any help would be appriciated.

Here is the test.php code, obtained from php.net (I've only changed; Creator name, Author name, and resulting PDF file name):


try {
$p = new PDFlib();

/* open new PDF file; insert a file name to create the PDF on disk */
if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());

$p->set_info("Creator", "test.php");
$p->set_info("Author", "smokebox");
$p->set_info("Title", "Hello world (PHP)!");

$p->begin_page_ext(595, 842, "");

$font = $p->load_font("Helvetica-Bold", "winansi", "");

$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show("Hello world!");
$p->continue_text("(says PHP)");


$buf = $p->get_buffer();
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=test.pdf");
print $buf;
catch (PDFlibException $e) {
die("PDFlib exception occurred in hello sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n");
catch (Exception $e) {
$p = 0;

October 30th, 2009, 10:01 AM
Can I get the test URL on our servers so we can check this out for you?

October 30th, 2009, 11:26 AM

October 30th, 2009, 02:49 PM
When I run the test, I get an error. After researching, it appears to be a documented bug (http://pecl.php.net/bugs/bug.php?id=15868&edit=1)

November 2nd, 2009, 02:55 AM
Thank you for the info, the page continually timed out for me prior to printing the error. It's unfortunate the bug ticket has been open >8 months with no update.

Per References 1 and 2 (listed below), it appears that PDFLib requires a commercial license for proper operation in a hosting environment. I do not see it explicitly stated on hostek.com that this license is available.

Does Hostek have a commercial PDFlib license (which matches the currently installed version)?

If so, can the examples distributed with the PDFlib product be successfully executed (Reference 1)?

If not, then I will check out fpdf (Reference 3). This seems to be an open source, pure PHP scripting solution for generating PDFs, independant of the PDFlib extension.

Reference 1: PDFlib.com
Reference 2: ThePlanet.com
Reference 3: fPDF.org

November 2nd, 2009, 09:18 AM
We do not have a commercial PDFlib license installed. The fPDF looks like that should work for you.