5 *install Fpdf as a PEAR package by:
6 pear install http://www.akbkhome.com:81/svn/akpear/Fpdf/Fpdf-1.51.tgz
13 'name' => = "Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx";
16 'name' => = "Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx";
19 'name' => = "Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx Xxxxxxxx xxxxxxxxxxxx xxxxxxxxxx xxxxxxx";
22 $pdf = XML_SvgToPDF::construct(dirname(__FILE__).'/test.svg',$data);
28 expects an svg file (probably made by sodipodi)
30 a) it has a text component with
34 b) a non-printable rectangle (which is the bounding box)
35 c) some text {xxxx}{yyyy} which is replaced with
36 address[0....][xxxx] = 'somevalue;
37 address[0....][yyyy] = 'somevalue;
44 require_once 'XML/Tree/Morph.php';
45 require_once 'XML/SvgToPdfAlt/Base.php';
47 // current options for generated file..
49 $GLOBALS['_XML_SVGTOPDF']['options'] = array(
54 class XML_SvgToPDFAlt {
57 static function debug($s,$e=0) {
58 if (!$GLOBALS['_XML_SVGTOPDF']['options']['debug']) {
61 echo "<PRE>".print_R($s,true). "</PRE>";
66 static function construct($svg, $data=array()) {
68 $t = new XML_SvgToPDFAlt;
69 $t->language = @$data['language'];
71 trigger_error(__CLASS__.':construct called without svg', E_USER_ERROR);
74 $x = new XML_Tree_Morph(
79 'svg' => array($t, 'buildObject'),
80 'image' => array($t, 'buildObject'),
81 'text' => array($t, 'buildObject'),
82 'tspan' => array($t, 'buildObject'),
83 'rect' => array($t, 'buildObject'),
84 'g' => array($t, 'buildObject'),
85 'path' => array($t, 'buildObject'),
86 'sodipodi:namedview' => array($t, 'buildNull'),
87 'defs' => array($t, 'buildNull'),
88 'metadata' => array($t, 'buildNull'),
94 $tree = $x->getTreeFromFile();
97 ///echo '<PRE>'.htmlspecialchars(print_r($tree,true));exit;
99 $tree = $t->buildobject($tree);
100 //echo '<PRE>'.htmlspecialchars(print_r($tree,true));
101 //echo "<PRE>";print_r($tree);exit;
102 $orientation = ($tree->width > $tree->height) ? 'L' : 'P';
104 $GLOBALS['_XML_SVGTOPDF']['options']['file'] = $svg;
106 if ($data['language'] == 'big5') {
108 require_once 'FpdfAlt/Chinese.php';
110 $pdf=new FpdfAlt_Chinese($orientation ,'mm','A4');
113 $pdf->AddUniCNShwFont();
116 require_once 'Fpdf.php';
118 $pdf=new FPDF($orientation ,'mm','A4');
122 $pdf->setAutoPageBreak(false);
123 $pdf->AliasNbPages();
124 // convert data to array.
125 if (is_object($data)) {
126 $data = (array) $data;
128 // assoc. array of key => no of fields per page.
129 $perPage = $tree->calcPerPage();
131 // no dynamic blocks:
132 if (!$perPage || empty($data)) {
134 $tree->writePDF($pdf,$data);
140 // build blocks of data for each page.
143 while (true == $haveData ) {
146 foreach($perPage as $k=>$v) {
148 $page_data[$k] = array();
152 $page_data[$k] = array_splice ( $data[$k], 0,$v);
159 $t->debug("<B>PAGE $page<B>");
161 // echo '<PRE>'.htmlspecialchars(print_r($page_data,true));
162 $tree->writePDF($pdf,$page_data);
165 $t->debug($tree, true);
169 function buildNull($node) {
172 function buildObject($node) {
173 $class = 'XML_SvgToPDFAlt_'.$node->name;
175 if (!empty($node->content) && strlen(trim($node->content)) && (@$this->language)) {
176 $node->language = $this->language;
181 //echo "look for $class?";
182 if (!class_exists($class) && !empty($node->name)) {
184 $file = dirname(__FILE__) . '/SvgToPdfAlt/'.ucfirst(strtolower($node->name)). '.php';
185 $this->debug("loading $file");
186 if (file_exists($file)) {
187 require_once 'XML/SvgToPdfAlt/'.ucfirst(strtolower($node->name)) . '.php';
190 // now if it doesnt exist..
191 if (!class_exists($class)) {
192 $this->debug("can not find $class");
193 $class = 'XML_SvgToPDFAlt_Base';
195 //echo '<PRE>';print_r($node);