XL. PDF Functions

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);
?>

Table of Contents
PDF_get_info — Returns a default info structure for a pdf document
PDF_set_info_creator — Fills the creator field of the info structure
PDF_set_info_title — Fills the title field of the info structure
PDF_set_info_subject — Fills the subject field of the info structure
PDF_set_info_keywords — Fills the keywords field of the info structure
PDF_set_info_author — Fills the author field of the info structure
PDF_open — Opens a new pdf document
PDF_close — Closes the pdf document
PDF_begin_page — Starts page
PDF_end_page — Ends page
PDF_show — Output text at current position
PDF_show_xy — Output text at position
PDF_set_font — Select the current font face and size
PDF_set_leading — Sets distance between text lines
PDF_set_text_rendering — Determines how text is rendered
PDF_set_horiz_scaling — Sets horizontal scaling of text
PDF_set_text_rise — Sets the text rise
PDF_set_text_matrix — Sets the text matrix
PDF_set_text_pos — Sets text position
PDF_set_char_spacing — Sets character spacing
PDF_set_word_spacing — Sets spacing between words
PDF_continue_text — Output text in next line
PDF_stringwidth — Returns width of text in current font
PDF_save — Saves current enviroment
PDF_restore — Restores formerly saved enviroment
PDF_translate — Sets origin of coordinate system
PDF_scale — Sets scaling
PDF_rotate — Sets rotation
PDF_setflat — Sets flatness
PDF_setlinejoin — Sets linejoin parameter
PDF_setlinecap — Sets linecap aparameter
PDF_setmiterlimit — Sets miter limit
PDF_setlinewidth — Sets line width
PDF_setdash — Sets dash pattern
PDF_moveto — Sets current point
PDF_curveto — Draws a curve
PDF_lineto — Draws a line
PDF_circle — Draw a circle
PDF_arc — Draws an arc
PDF_rect — Draw a rectangle
PDF_closepath — Close path
PDF_stroke — Draw line along path
PDF_closepath_stroke — Close path and draw line along path
PDF_fill — Fill current path
PDF_fill_stroke — Fill and stroke current path
PDF_closepath_fill_stroke — Close, fill and stroke current path
PDF_endpath — Ends current path
PDF_clip — Clips to current path
PDF_setgray_fill — Sets filling color to gray value
PDF_setgray_stroke — Sets drawing color to gray value
PDF_setgray — Sets drawing and filling color to gray value
PDF_setrgbcolor_fill — Sets filling color to rgb color value
PDF_setrgbcolor_stroke — Sets drawing color to rgb color value
PDF_setrgbcolor — Sets drawing and filling color to rgb color value
PDF_add_outline — Adds bookmark for current page
PDF_set_transition — Sets transition between pages
PDF_set_duration — Sets duration between pages
PDF_open_jpeg — Opens a JPEG image
PDF_close_image — Closes an image
PDF_place_image — Places an image on the page
PDF_put_image — Stores an image in the PDF for later use
PDF_execute_image — Places a stored image on the page