Source for file Xml2Pdf.php
Documentation is available at Xml2Pdf.php
* @author guillaume l. <guillaume@geelweb.org>
* @link http://www.geelweb.org
* @license http://opensource.org/licenses/bsd-license.php BSD License
* @copyright copytight © 2006, guillaume luchet
* @todo bench : recursion
* @todo add tag <include file="include_file.xml" />
require_once('Xml2Pdf.config.php');
* Parse an XML file and convert it on PDF document.
* Parse an XML content using the
* {@link http://php.net/manual/en/ref.xml.php PHP XML parser functions}
* then convert it on PDF document using
* {@link http://www.fpdf.org 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 <b>xml2pdf.tag.custom.php</b>, then it'll instantiate the
* class <b>Xml2PdfTag_custom</b>.
* 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)
* Example of plugin class :
* class Xml2PdfTag_custom {
* * objet représentant la balise mère.
* * contenu de la balise.
* * il peut prendre seulement deux paramètres, dans ce cas, la balise mère
* public function __construct($pdf, $tagProperties, $parent) {
* // here you can parse the tagProperties
* public function addContent($content) {
* // ici vous pouvez gérer les actions à effectué sur le contenu de
* * méthode appelé quand la balise est fermée.
* public function close() {
* // ici vous pouvez mettre l'action à effectué quand la balise
* To simplify the plugin class code, you can extends your plugin class with
* {@link Xml2PdfTag Xml2PdfTag} or {@link Xml2PdfTextTag Xml2PdfTextTag}.
* @author guillaume l. <guillaume@geelweb.org>
* @link http://www.geelweb.org
* @license http://opensource.org/licenses/bsd-license.php BSD License
* @copyright copyright © 2006, guillaume luchet
* @tutorial Xml2Pdf/Xml2Pdf.pkg
* True if the tag does not be parsed.
// Xml2Pdf::__construct() {{{
* @param string $xml xml file or content
* Parse the XML content, build the PDF document then return it.
* Parse the XML content using PHP XML parser functions.
throw
new Exception(sprintf('xml error %s at line %d',
// Xml2Pdf::_parseOpeningTag() {{{
* Try to instantitate the tag plugin class.
* @param object $parser parser xml
* @param string $tag tag name
* @param array $tagProperties tag properties
foreach ($tagProperties as $key=>
$value) {
$tagToText .=
' ' .
strtolower($key) .
'="' .
$value .
'"';
$pluginFileName =
'xml2pdf.tag.' .
$tagName .
'.php';
$pluginClass =
'Xml2PdfTag_' .
$tagName;
require_once($pluginFileName);
sprintf('Xml2Pdf error : unknow plugin class %s for tag %s',
$pluginClass, $tagName));
$this->_tagStack[] =
new $pluginClass($this->_pdf, $tagProperties, $parent);
$this->_tagStack[] =
new $pluginClass($this->_pdf, $tagProperties);
throw
new Exception(sprintf('Xml2Pdf parsing error : unknow plugin file %s for tag %s',
$pluginFileName, $tagName));
// Xml2Pdf::_parseClosingTag(object, string) {{{
* Call the method close() of the last tag of the tags stack.
* @param object $parser xml parser.
* @param string $tag tag name.
$result =
$tagObject->close();
// Xml2Pdf::_parseContent(object, content) {{{
* Call the method addContent() of the last tag of the tags stack.
* @param object $parser analyseur xml
* @param string $content contenue
$tagObject->addContent($content);
// Xml2Pdf::showException() {{{
* It's also the exception handler.
* @param object $exception objet Exception
print_r('Xml2Pdf error : ' .
$exception->getMessage());
// Xml2Pdf::_getXmlContent(string) {{{
* Get the xml content of a file.
// Xml2Pdf::convertColor(string) {{{
* Convert an hexadecimal color on RGB color.
* @param string $color coulor.
$array['r'] =
substr((string)
$color,1,2);
$array['g'] =
substr((string)
$color,3,2);
$array['b'] =
substr((string)
$color,5,2);
$array['r'] =
hexdec($array['r']);
$array['g'] =
hexdec($array['g']);
$array['b'] =
hexdec($array['b']);
// Xml2Pdf::getColor() // {{{
$array['r'] =
rand(128, 255);
$array['g'] =
rand(128, 255);
$array['b'] =
rand(128, 255);
Documentation generated on Wed, 11 Oct 2006 22:27:17 +0200 by phpDocumentor 1.3.0