Class Xml2Pdf

Description

Parse an XML file and convert it on PDF document.

Parse an XML content using the PHP XML parser functions then convert it on PDF document using FPDF.

For each tag XML, the parser try to instantiate the corresponding object searching it in the tag plugin directory. eg, to a tag named custom, it'll search the file xml2pdf.tag.custom.php, then it'll instantiate the class Xml2PdfTag_custom.

The tag plugins class must have the following method :

  • void __construtc(object Pdf, array) or void __construct(object Pdf, array, object Pdf)
  • void addContent(string)
  • void close()
Example of plugin class :
  1.  class Xml2PdfTag_custom {
  2.      /**
  3.       * objet représentant la balise mère.
  4.       */
  5.      public $parent;
  6.  
  7.      /**
  8.       * objet Pdf.
  9.       */
  10.      public $pdf;
  11.  
  12.      /**
  13.       * contenu de la balise.
  14.       */
  15.      public $content;
  16.  
  17.      /**
  18.       * Constructeur :
  19.       *
  20.       * il peut prendre seulement deux paramètres, dans ce cas, la balise mère
  21.       * ne sera pas connu.
  22.       */
  23.      public function __construct($pdf$tagProperties$parent{
  24.          // here you can parse the tagProperties
  25.      }
  26.  
  27.      /**
  28.       * ajoute le contenu.
  29.       */
  30.      public function addContent($content{
  31.          // ici vous pouvez gérer les actions à effectué sur le contenu de
  32.          // la balise
  33.      }
  34.  
  35.      /**
  36.       * méthode appelé quand la balise est fermée.
  37.       */
  38.      public function close({
  39.          // ici vous pouvez mettre l'action à effectué quand la balise
  40.          // à été analysé
  41.      }
  42.  }

To simplify the plugin class code, you can extends your plugin class with Xml2PdfTag or Xml2PdfTextTag.

Located in /Xml2Pdf.php (line 108)


	
			
Variable Summary
Method Summary
 static array convertColor (string $color)
 static array getColor ()
 static void showException (object $exception)
 void __construct (string $xml)
 string _getXmlContent ( $xml)
 boolean _parse ()
 void _parseClosingTag (object $parser, string $tag)
 void _parseContent (object $parser, string $content)
 void _parseOpeningTag (object $parser, string $tag, array $tagProperties)
Variables
boolean $_donotparse = false (line 132)

True if the tag does not be parsed.

  • access: private
object Pdf $_pdf = null (line 120)

object Pdf.

  • access: private
array $_tagStack = array() (line 126)

tags stack.

  • access: private
string $_xml = null (line 114)

XML content.

  • access: private
Methods
static convertColor (line 336)

Convert an hexadecimal color on RGB color.

static array convertColor (string $color)
  • string $color: coulor.
static getColor (line 360)

Generate a RGB color.

  • access: public
static array getColor ()
static showException (line 303)

Show an error message.

It's also the exception handler.

static void showException (object $exception)
  • object $exception: objet Exception
Constructor __construct (line 143)

Constructor.

  • access: public
void __construct (string $xml)
  • string $xml: xml file or content
render (line 159)

Build the document.

Parse the XML content, build the PDF document then return it.

  • access: public
object Pdf render ()
_getXmlContent (line 318)

Get the xml content of a file.

  • access: private
string _getXmlContent ( $xml)
  • $xml
_parse (line 174)

Parse the XML content.

Parse the XML content using PHP XML parser functions.

  • access: private
boolean _parse ()
_parseClosingTag (line 258)

Parse closing tags.

Call the method close() of the last tag of the tags stack.

  • access: private
void _parseClosingTag (object $parser, string $tag)
  • object $parser: xml parser.
  • string $tag: tag name.
_parseContent (line 286)

Parse the tag content.

Call the method addContent() of the last tag of the tags stack.

  • access: private
void _parseContent (object $parser, string $content)
  • object $parser: analyseur xml
  • string $content: contenue
_parseOpeningTag (line 203)

Parse the opening tag.

Try to instantitate the tag plugin class.

  • access: private
void _parseOpeningTag (object $parser, string $tag, array $tagProperties)
  • object $parser: parser xml
  • string $tag: tag name
  • array $tagProperties: tag properties

Documentation generated on Wed, 11 Oct 2006 22:27:17 +0200 by phpDocumentor 1.3.0