You can use the pdf functions in PHP to create pdf files if you have the PDF library (available at http://www.ifconnection.de/~tm/) by Thomas Merz. Please consult the excelent documentation for pdflib shipped with the source distribution of pdflib or available at http://www.ifconnection.de/~tm/software/pdflib/PDFlib-0.6.pdf. As long as this documentation is not complete the pdflib documentation should be your first choice. The functions in pdflib and the php3 module have the same name. The parameters are also identical. You should also understand some of the concepts of pdf to efficiently use this module.
The pdf module introduces two new types of variables. They are called pdfdoc and pdfinfo. pdfdoc is a pointer to a PDF document and almost all functions need it as its first parameter. pdfinfo contains meta data about the PDF document.
In order to output text into a PDF document you will need to provide the afm file for each font. By default these afm files are searched for in a directory named 'fonts' relative to the directory where the php3 script is located.
Most of the functions are fairly easy to use. The most difficult part is probably to create a very simple pdf document at all. The following example should help to get started. It creates the file test.pdf with one page. The page contains the text "Times-Roman" in an outlined 30pt font. The text is underlined.
Example 1. PDF_get_info <?php $fp = fopen("test.pdf", "w"); $info = PDF_get_info(); pdf_set_info_author($info, "Uwe Steinmann"); PDF_set_info_title($info, "Test for PHP3 wrapper of PDFlib 0.6"); PDF_set_info_author($info, "Name of Author"); pdf_set_info_creator($info, "See Author"); pdf_set_info_subject($info, "Testing"); $pdf = PDF_open($fp, $info); PDF_begin_page($pdf, 595, 842); PDF_add_outline($pdf, "Page 1"); pdf_set_font($pdf, "Times-Roman", 30, 4); pdf_set_text_rendering($pdf, 1); PDF_show_xy($pdf, "Times Roman outlined", 50, 750); pdf_moveto($pdf, 50, 740); pdf_lineto($pdf, 330, 740); pdf_stroke($pdf); PDF_end_page($pdf); PDF_close($pdf); echo "<A HREF=gettest.php3>finished</A>"; ?> The php3 file gettext.php3 just outputs the pdf document. <?php $fp = fopen("test.pdf", "r"); header("Content-type: application/pdf"); fpassthru($fp); fclose($fp); ?> |