3 This class is an extension to the tcpdf class using a syntax that the original reports were written in
4 (the R &OS pdf.php class) - due to easily portation this wrapper class
5 was written to allow the same code base to use the more functional tcpdf.class by Nicola Asuni
7 * Wrapper for use R&OSpdf API with tcpdf.org class
8 * Joe Hunt <joe.hunt.consulting@gmail.com> and Janusz Dobrowolski <janusz@iron.from.pl>
11 define("K_RE_PATTERN_RTL", "/(
13 | \xD7[\x80\x83\x86\x90-\xAA\xB0-\xB4] # R
14 | \xDF[\x80-\xAA\xB4\xB5\xBA] # R
16 | \xEF\xAC[\x9D\x9F\xA0-\xA8\xAA-\xB6\xB8-\xBC\xBE] # R
17 | \xEF\xAD[\x80\x81\x83\x84\x86-\x8F] # R
18 | \xF0\x90\xA0[\x80-\x85\x88\x8A-\xB5\xB7\xB8\xBC\xBF] # R
19 | \xF0\x90\xA4[\x80-\x99] # R
20 | \xF0\x90\xA8[\x80\x90-\x93\x95-\x97\x99-\xB3] # R
21 | \xF0\x90\xA9[\x80-\x87\x90-\x98] # R
22 | \xE2\x80[\xAB\xAE] # RLE & RLO
26 * Pattern to test Arabic strings using regular expressions.
27 * source: http://www.w3.org/International/questions/qa-forms-utf-8
29 define("K_RE_PATTERN_ARABIC", "/(
30 \xD8[\x80-\x83\x8B\x8D\x9B\x9E\x9F\xA1-\xBA] # AL
31 | \xD9[\x80-\x8A\xAD-\xAF\xB1-\xBF] # AL
32 | \xDA[\x80-\xBF] # AL
33 | \xDB[\x80-\x95\x9D\xA5\xA6\xAE\xAF\xBA-\xBF] # AL
34 | \xDC[\x80-\x8D\x90\x92-\xAF] # AL
35 | \xDD[\x8D-\xAD] # AL
36 | \xDE[\x80-\xA5\xB1] # AL
37 | \xEF\xAD[\x90-\xBF] # AL
38 | \xEF\xAE[\x80-\xB1] # AL
39 | \xEF\xAF[\x93-\xBF] # AL
40 | \xEF[\xB0-\xB3][\x80-\xBF] # AL
41 | \xEF\xB4[\x80-\xBD] # AL
42 | \xEF\xB5[\x90-\xBF] # AL
43 | \xEF\xB6[\x80-\x8F\x92-\xBF] # AL
44 | \xEF\xB7[\x80-\x87\xB0-\xBC] # AL
45 | \xEF\xB9[\xB0-\xB4\xB6-\xBF] # AL
46 | \xEF\xBA[\x80-\xBF] # AL
47 | \xEF\xBB[\x80-\xBC] # AL
48 | \xD9[\xA0-\xA9\xAB\xAC] # AN
51 include_once (dirname(__FILE__).'/tcpdf.php');
53 class Cpdf extends TCPDF {
55 function Cpdf($pageSize='A4', $l=array())
57 if (!isset($l['a_meta_charset']))
58 $l = array('a_meta_charset' => 'ISO-8859-1', 'a_meta_dir' => 'ltr', 'a_meta_language' => 'en_GB', 'w_page' => 'page');
59 $enc = $l['a_meta_charset'];
60 $uni = ($enc == 'UTF-8' || $enc == 'GB2312' ? true : false);
62 ini_set("memory_limit", "25M");
63 $this->TCPDF('P', 'pt', $pageSize, $uni, $enc);
64 $this->setLanguageArray($l);
65 $this->setPrintHeader(false);
66 $this->setPrintFooter(false);
67 $this->setPDFVersion("1.3");
68 $this->setAutoPageBreak(0);
71 $this->SetLineWidth(1);
75 function selectFont($fontname, $style='')
78 $fontname = basename($fontname);
79 if ($style == 'italic')
81 elseif ($style == 'bold')
89 switch ($this->l['a_meta_language'])
91 case "ar_EG" : $fontname = "ae_tholoth"; break;
92 case "zh_CN" : $fontname = "gbsn00lp"; break;
93 default : $fontname = "dejavu"; break;
96 elseif ($this->encoding === "ISO-8859-2")
98 switch ($this->l['a_meta_language'])
100 default : $fontname = "freesans"; break;
103 elseif ($this->encoding === "ISO-8859-5")
105 switch ($this->l['a_meta_language'])
107 default : $fontname = "freesans5"; break;
110 // else use built-in adobe fonts helvetica.
112 $this->SetFont($fontname, $type);
128 function line($x1,$y1,$x2,$y2)
130 TCPDF::line($x1, $this->h-$y1, $x2, $this->h-$y2);
133 function rectangle($x, $y, $w, $h, $style='', $border_style=array(), $fill_color=array())
135 TCPDF::Rect($x, $this->h-$y, $w, $h, $style, $border_style, $fill_color);
139 function addText($xb,$yb,$size,$txt)//,$angle=0,$wordSpaceAdjust=0)
141 if ($this->isunicode && $this->encoding != "UTF-8")
142 $txt = iconv($this->encoding, "UTF-8", $txt);
143 $this->SetFontSize($size);
144 $this->Text($xb, $this->h-$yb, $txt);
147 function addInfo($label,$value)
151 $this->SetTitle($value);
153 if ($label=='Subject')
155 $this->SetSubject($value);
157 if($label=='Creator')
159 // The Creator info in source is not exactly it should be ;)
160 $value = str_replace( "ros.co.nz", "tcpdf.org", $value );
161 $value = str_replace( "R&OS", "", $value );
162 $this->SetCreator( $value );
166 $this->SetAuthor($value);
170 function addJpegFromFile($img,$x,$y,$w=0,$h=0)
172 $this->Image($img, $x, $this->h-$y-$h, $w, $h);
175 function addPngFromFile($img,$x,$y,$w=0,$h=0)
177 $this->Image($img, $x, $this->h-$y-$h, $w, $h);
180 * Next Two functions are adopted from R&OS pdf class
184 * draw a part of an ellipse
186 function partEllipse($x0,$y0,$astart,$afinish,$r1,$r2=0,$angle=0,$nSeg=8)
188 $this->ellipse($x0,$y0,$r1,$r2,$angle,$nSeg,$astart,$afinish,0);
193 * note that the part and filled ellipse are just special cases of this function
195 * draws an ellipse in the current line style
196 * centered at $x0,$y0, radii $r1,$r2
197 * if $r2 is not set, then a circle is drawn
198 * nSeg is not allowed to be less than 2, as this will simply draw a line (and will even draw a
199 * pretty crappy shape at 2, as we are approximating with bezier curves.
201 function ellipse($x0,$y0,$r1,$r2=0,$angle=0,$nSeg=8,$astart=0,$afinish=360,$close=1,$fill=0)
203 TCPDF::Ellipse($x0, $y0, $r1, $r2, $angle, $astart. $afinish, ($close?'C':''), "", "", $nSeg);
207 TCPDF::Output('', 'I');
212 return TCPDF::Output('','S');
215 function calcTextWrap($txt, $width, $spacebreak=false)
219 $w = $this->GetStringWidth($txt);
220 if ($w > $width && $w > 0 && $width != 0)
223 $k = intval($n * $width / $w);
224 if ($k > 0 && $k < $n)
226 $txt2 = substr($txt, 0, $k);
227 if ($spacebreak && (($pos = strrpos($txt2, " ")) !== false))
229 $txt2 = substr($txt2, 0, $pos);
230 $ret = substr($txt, $pos+1);
233 $ret = substr($txt, $k);
236 return array($txt2, $ret);
239 function addTextWrap($xb, $yb, $w, $h, $txt, $align='left', $border=0, $fill=0, $spacebreak=false)
244 if ($align == 'right')
246 elseif ($align == 'left')
251 $txt = $this->calcTextWrap($txt, $w, $spacebreak);
254 $this->SetXY($xb, $this->h - $yb - $h);
255 $txt = TCPDF::unhtmlentities($txt);
256 if ($this->isunicode && $this->encoding != "UTF-8")
257 $txt = iconv($this->encoding, "UTF-8", $txt);
258 $this->Cell($w, $h, $txt, $border, 0, $align, $fill);
262 * sets the colour for stroke operations
264 function setStrokeColor($r,$g,$b,$force=0)
266 TCPDF::SetDrawColor($r,$g,$b);
269 * this sets the line drawing style.
270 * width, is the thickness of the line in user units
271 * cap is the type of cap to put on the line, values can be 'butt','round','square'
272 * where the diffference between 'square' and 'butt' is that 'square' projects a flat end past the
274 * join can be 'miter', 'round', 'bevel'
275 * dash is an array which sets the dash pattern, is a series of length values, which are the lengths of the
277 * (2) represents 2 on, 2 off, 2 on , 2 off ...
278 * (2,1) is 2 on, 1 off, 2 on, 1 off.. etc
279 * phase is a modifier on the dash pattern which is used to shift the point at which the pattern starts.
281 function setLineStyle($width=1,$cap='',$join='',$dash='',$phase=0)
283 $this->SetLineWidth($width);
286 function Text($x, $y, $txt, $stroke=0, $clip=false)
288 TCPDF::Text($x,$y, TCPDF::unhtmlentities($txt), $stroke, $clip);