phpDocumentor Converters
PDFdefault
[ class tree: Converters ] [ index: Converters ] [ all elements ]
Prev Next
Using the PDFParser XML templating language

Using the PDFParser XML templating language

Learn how the PDFParser XML templating language is constructed and used

by Gregory Beaver

Table of Contents

PDFParser Introduction

This documentation deals only with the PDFParser XML templating language. To learn how to use phpDocumentor, read the phpDocumentor Guide to Creating Fantastic Documentation. To learn how to write a new Converter, read Converter Manual

Overview

The PDF:default Converter uses the powerful Cezpdf class library written by Wayne Munro. Although the Cezpdf library is very versatile and useful, it is designed to be used as PHP code, and does not allow access to its methods from the text passed to it. The PDFParser class was written to solve this problem. Through the use of a few basic XML-based tags, and the versatile <pdffunction /> tag, one can access any feature of the Cezpdf library and do anything that it can do. This is what makes it possible to use Smarty templates without modifying any code in phpDocumentor, a primary goal of the 1.2.0 release.

PDFParser XML tags

<text>

The <text> tag is a block tag (requires a closing tag). All output that is not a PDFParser tag must be enclosed in this tag. These are the parameters to the text tag:

  • size (required) - font size

  • any legal parameter to Cezpdf::ezText() (all optional):

  • left - indentation from the left margin

  • right - indentation from the right margin

  • aleft - absolute indentation from the left side of the page

  • aright - absolute indentation from the right side of the page

  • justification - one of left, right, center/centre, full

  • either leading or spacing

  • Examples might include:

  • <text size="11">Hello World!</text>

  • <text size="11" justification="right">Hello World!</text>

  • <text size="11" left="10" right="10" justification="center">Hello World!</text>


  • <font>

    Unlike HTML, the <font /> tag is a self-enclosed tag, and is only used to select the font face (and future versions will also select color). Syntax is <font face="fontface" /> The fontface must be present in the Converters/PDF/default/templates/fonts/ subdirectory as a fontface-php.afm and fontface.afm file, otherwise Cezpdf will cause all kinds of PHP warnings. This is an issue with Cezpdf that we are assisting the author in fixing, and will not be a problem in the future.


    <newpage>

    This is the simplest tag, use it as <newpage /> to tell Cezpdf to jump to the top of the next page in output.


    <pdffunction>

    The <pdffunction> tag is the most versatile of the PDFParser tags. This tag can be used to arbitrarily call any Cpdf or Cezpdf method. Arguments can be passed to the function both as literal values and using dynamic variables, both class variables and temporary variables. The method chosen is selected as if pdffunction were a namespace rather than a

    Here are the parameters to the pdffunction:

  • return (optional) set a temporary variable to the value returned from the function. This parameter allows a later reference to the temporary variable like: <pdffunction:getYPlusOffset return="newy" offset="0" /> <pdffunction:addJpegFromFile arg="logo.jpg" x="250" y=$newy />

  • any other parameter represents an argument. Since the parameters passed are simply passed by value to the method, the names can be anything that is useful to understanding how they work. <pdffunction:ezStartPageNumbers x="500" y="28" size="10" pos="" pattern="{ldelim}PAGENUM{rdelim} of {ldelim}TOTALPAGENUM{rdelim}" num="1" /> could just as easily be <pdffunction:ezStartPageNumbers arg="500" foo="28" bar="10" mylord="" goodnessgracious="{ldelim}PAGENUM{rdelim} of {ldelim}TOTALPAGENUM{rdelim}" num="1" /> and the code would still work splendidly. The first way is obviously easier to handle, and so is recommended.

    Most arguments to the method will be literals, like numbers or strings, but some arguments may need to be more dynamic, based on the values returned from other pdffunction tags. To do this, use the return parameter as described above, and reference the temporary variable as if it were a php variable like <pdffunction:whatever arg=$tempvar /> It may even be necessary to access a data member of the pdf class. In this case, use $this->datamember as in <pdffunction:whatever arg=$this->datamember />


    Prev   Next
    Writing templates for the HTMLframes Converter Writing templates for the PDFdefault Converter

    Documentation generated on Tue, 24 Oct 2006 09:20:31 -0500 by phpDocumentor 1.3.1