Add-On SVG template engine
Informations
Author:Alan KnowlesLicense: FPDF
Description
XML_SvgToPdf is a PEAR package meant to read a SVG template and generate a PDF. It is primarily designed to output labels. It has been tested with Sodipodi (a free SVG editor).It requires that you first install:
- PEAR
- The XML_Parser package
- The XML_Tree package
XML_SvgToPdf needs another package, XML_Tree_Morph, included in the archive. After you have installed the 4 packages, you must have in your PEAR/XML directory:
- Parser.php
- SvgToPdf.php
- Tree.php
In PEAR/XML/SvgToPdf:
- Base.php
- G.php
- Path.php
- Rect.php
- Text.php
- Tspan.php
In PEAR/XML/Tree:
- Morph.php
- Node.php
A label is defined by a dynamic area in the page. To define it, proceed like this:
- Draw a rectangle to delimit the area and mark it as non-printable (in the item properties).
Note that this property is Sodipodi-specific (it adds the
sodipodi:nonprintable="true"
attribute to therect
element in the SVG file). - Add a text with 3 lines (they won't appear in the PDF):
dynamic=name (name of the group)
cols=number (number of columns)
rows=number (number of rows)
- Add one or several texts with variables of the form {variable} in them.
- Make a group with all these elements.
object construct(svg, [array data])
The data array has a single element, whose key is the name of the dynamic group, and the value is an array with a number of elements. Each element corresponds to a label and is an array which gives the values for the {variable} variables.
Note: images and curves are not supported.
You can find more details here.
Example
<?php
//Include PEAR path if necessary
ini_set('include_path', '.;C:/Php/Pear');
require('XML/SvgToPDF.php');
//Print 15 labels
$label=array();
for($i=1;$i<=15;$i++)
$label[]=array('name'=>"Name $i", 'address'=>"Address $i", 'city'=>"City $i");
$pdf=XML_SvgToPDF::construct('ex.svg', array('label'=>$label));
$pdf->Output();
?>