SVG template engine

Informations

Author: Alan Knowles
License: 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:
The XML_SvgToPDF class provides a static factory method which creates a FPDF object and renders the SVG template on it:

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();
?>
View the result here.

Download

ZIP | TGZ