SVG template engine

Generates a PDF from SVG Template

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:
  • sodipodi:nonprintable="true" attribute to the rect 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.
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

Quelle

http://www.fpdf.org/en/script/script43.php, zuletzt abgerufen 02.10.2016 10:26