Specifications
Although it is possible that the official PHP binding might be better then the current one when
(or if) it arrives, the current one is very good. The only problem is that you need to read the
PHP documentation, available at
http://www.php.net/manual/ref.pdf.php
for an overview, installation instructions, and the PDFlib documentation, available as the file
PDFlib-manual.pdf in the PDFlib distribution, for a detailed reference on the API.
A Hello World Script for PDFlib
After you have PHP and installed it with PDFlib enabled, you can test it with a simple program
such as the Hello World example in Listing 30.5.
LISTING 30.5 testpdf.php—Classic Hello World Example Using PDFlib Via PHP
<?
//create file
$fp = fopen(“hello.pdf”, “w”);
if(!$fp)
{
echo “Error: could not create the PDF file”;
exit;
}
// start the pdf document
$pdf = pdf_open($fp);
pdf_set_info($pdf, “Creator”, “pdftest.php”);
pdf_set_info($pdf, “Author”, “Luke Welling and Laura Thomson”);
pdf_set_info($pdf, “Title”, “Hello World (PHP)”);
// US letter is 11” x 8.5” and there are approximately 72 points per inch
pdf_begin_page($pdf, 8.5*72, 11*72);
pdf_add_outline($pdf, “Page 1”);
pdf_set_font($pdf, “Helvetica-Bold”, 24, “host”);
pdf_set_text_pos($pdf, 50, 700);
// write text
pdf_show($pdf,”Hello,world!”);
pdf_continue_text($pdf,”(says PHP)”);
// end the document
pdf_end_page($pdf);
pdf_close($pdf);
fclose($fp);
Building Practical PHP and MySQL Projects
P
ART V
766
36 7842 CH30 3/6/01 3:40 PM Page 766