3 php pdf generation library - template extension
4 Copyright (C) Potential Technologies 2002 - 2003
5 http://www.potentialtech.com
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 $Id: template.class.php,v 2.3 2003/07/05 21:33:07 wmoran Exp $
28 var $pdf; // reference to the parent class
37 $temp = $this->nexttid;
38 // Stores the next object ID within this template
39 $this->templ[$temp]['next'] = 0;
44 function size($tid, $width, $height)
46 $this->templ[$tid]["height"] = $height;
47 $this->templ[$tid]["width"] = $width;
51 function rectangle($tid, $bottom, $left, $top, $right, $attrib = array())
53 $temp = $this->pdf->_resolve_param($attrib);
54 $temp["type"] = "rectangle";
56 $temp["left"] = $left;
57 $temp["bottom"] = $bottom;
58 $temp["right"] = $right;
59 return $this->_add_object($temp, $tid);
62 function circle($tid, $cenx, $ceny, $radius, $attrib = array())
64 $temp = $this->pdf->_resolve_param($attrib);
65 $temp["type"] = "circle";
68 $temp["radius"] = $radius;
69 return $this->_add_object($temp, $tid);
72 function line($tid, $x, $y, $attrib = array())
74 $temp = $this->pdf->_resolve_param($attrib);
75 $temp["type"] = "line";
78 return $this->_add_object($temp, $tid);
81 function image($tid, $left, $bottom, $width, $height, $image, $attrib = array())
83 $this->ifield($tid, $left, $bottom, $width, $height, false, $image, $attrib);
86 function ifield($tid, $left, $bottom, $width, $height, $name, $default = false, $attrib = array())
88 $temp = $this->pdf->_resolve_param($attrib);
89 $temp['type'] = "ifield";
90 $temp['left'] = $left;
91 $temp['bottom'] = $bottom;
92 $temp['name'] = $name;
93 $temp['default'] = $default;
94 $temp['width'] = $width;
95 $temp['height'] = $height;
96 return $this->_add_object($temp, $tid);
99 function text($tid, $left, $bottom, $text, $attrib = array())
101 return $this->field($tid, $left, $bottom, false, $text, $attrib);
104 function field($tid, $left, $bottom, $name, $default = '', $attrib = array())
106 $temp = $this->pdf->_resolve_param($attrib);
107 $temp["type"] = "field";
108 $temp["left"] = $left;
109 $temp["bottom"] = $bottom;
110 $temp["name"] = $name;
111 $temp["default"] = $default;
112 return $this->_add_object($temp, $tid);
115 function paragraph($tid, $bottom, $left, $top, $right, $text, $attrib = array())
117 return $this->pfield($tid, $bottom, $left, $top, $right, false, $text, $attrib);
120 function pfield($tid, $bottom, $left, $top, $right, $name, $default = '', $attrib = array())
122 $temp = $this->pdf->_resolve_param($attrib);
123 $temp['type'] = 'pfield';
124 $temp['left'] = $left;
125 $temp['bottom'] = $bottom;
127 $temp['right'] = $right;
128 $temp['name'] = $name;
129 $temp['default'] = $default;
130 return $this->_add_object($temp, $tid);
133 function place($tid, $page, $left, $bottom, $data = array())
136 foreach( $this->templ[$tid]["objects"] as $o ) {
137 switch ($o['type']) {
139 $ok = $ok && $this->pdf->draw_rectangle($bottom + $o["top"],
141 $bottom + $o["bottom"],
148 $ok = $ok && $this->pdf->draw_circle($left + $o['x'],
156 foreach ($o['x'] as $key => $value) {
157 $o['x'][$key] += $left;
158 $o['y'][$key] += $bottom;
160 $ok = $ok && $this->pdf->draw_line($o['x'],
167 $temp = ($o['name'] === false) || !isset($data[$o['name']]) || !strlen($data[$o['name']]) ? $o['default'] : $data[$o['name']];
168 $ok = $ok && $this->pdf->draw_text($left + $o['left'],
169 $bottom + $o['bottom'],
176 $temp = ($o['name'] === false) || !isset($data[$o['name']]) || !strlen($data[$o['name']]) ? $o['default'] : $data[$o['name']];
177 $t = $this->pdf->draw_paragraph($bottom + $o['top'],
179 $bottom + $o['bottom'],
186 $this->pdf->_push_error(6013, "Text overflowed available area: $t");
191 $temp = ($o['name'] === false) || empty($data[$o['name']]) ? $o['default'] : $data[$o['name']];
192 if ($temp === false) {
195 $id = $this->pdf->get_image_size($temp);
197 $o['scale']['x'] = $o['width'] / $id['width'];
198 $o['scale']['y'] = $o['height'] / $id['height'];
199 $ok = $ok && $this->pdf->image_place($temp,
200 $o['bottom'] + $bottom,
213 function _add_object($objarray, $tid)
215 $oid = $this->templ[$tid]["next"];
216 $this->templ[$tid]["next"] ++;
217 $this->templ[$tid]["objects"][$oid] = $objarray;