1
|
|
|
<?php |
2
|
|
|
/******************************************************************************* |
3
|
|
|
* Software: FPDF * |
4
|
|
|
* Version: 1.53 * |
5
|
|
|
* Date: 2004-12-31 * |
6
|
|
|
* Author: Olivier PLATHEY * |
7
|
|
|
* License: Freeware * |
8
|
|
|
* * |
9
|
|
|
* You may use and modify this software as you wish. * |
10
|
|
|
*******************************************************************************/ |
11
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
12
|
|
|
die('XOOPS root path not defined'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
if(!class_exists('FPDF')) |
16
|
|
|
{ |
17
|
|
|
define('FPDF_VERSION','1.53'); |
18
|
|
|
|
19
|
|
|
class FPDF |
20
|
|
|
{ |
21
|
|
|
//Private properties |
22
|
|
|
var $page; //current page number |
23
|
|
|
var $n; //current object number |
24
|
|
|
var $offsets; //array of object offsets |
25
|
|
|
var $buffer; //buffer holding in-memory PDF |
26
|
|
|
var $pages; //array containing pages |
27
|
|
|
var $state; //current document state |
28
|
|
|
var $compress; //compression flag |
29
|
|
|
var $DefOrientation; //default orientation |
30
|
|
|
var $CurOrientation; //current orientation |
31
|
|
|
var $OrientationChanges; //array indicating orientation changes |
32
|
|
|
var $k; //scale factor (number of points in user unit) |
33
|
|
|
var $fwPt,$fhPt; //dimensions of page format in points |
34
|
|
|
var $fw,$fh; //dimensions of page format in user unit |
35
|
|
|
var $wPt,$hPt; //current dimensions of page in points |
36
|
|
|
var $w,$h; //current dimensions of page in user unit |
37
|
|
|
var $lMargin; //left margin |
38
|
|
|
var $tMargin; //top margin |
39
|
|
|
var $rMargin; //right margin |
40
|
|
|
var $bMargin; //page break margin |
41
|
|
|
var $cMargin; //cell margin |
42
|
|
|
var $x,$y; //current position in user unit for cell positioning |
43
|
|
|
var $lasth; //height of last cell printed |
44
|
|
|
var $LineWidth; //line width in user unit |
45
|
|
|
var $CoreFonts; //array of standard font names |
46
|
|
|
var $fonts; //array of used fonts |
47
|
|
|
var $FontFiles; //array of font files |
48
|
|
|
var $diffs; //array of encoding differences |
49
|
|
|
var $images; //array of used images |
50
|
|
|
var $PageLinks; //array of links in pages |
51
|
|
|
var $links; //array of internal links |
52
|
|
|
var $FontFamily; //current font family |
53
|
|
|
var $FontStyle; //current font style |
54
|
|
|
var $underline; //underlining flag |
55
|
|
|
var $CurrentFont; //current font info |
56
|
|
|
var $FontSizePt; //current font size in points |
57
|
|
|
var $FontSize; //current font size in user unit |
58
|
|
|
var $DrawColor; //commands for drawing color |
59
|
|
|
var $FillColor; //commands for filling color |
60
|
|
|
var $TextColor; //commands for text color |
61
|
|
|
var $ColorFlag; //indicates whether fill and text colors are different |
62
|
|
|
var $ws; //word spacing |
63
|
|
|
var $AutoPageBreak; //automatic page breaking |
64
|
|
|
var $PageBreakTrigger; //threshold used to trigger page breaks |
65
|
|
|
var $InFooter; //flag set when processing footer |
66
|
|
|
var $ZoomMode; //zoom display mode |
67
|
|
|
var $LayoutMode; //layout display mode |
68
|
|
|
var $title; //title |
69
|
|
|
var $subject; //subject |
70
|
|
|
var $author; //author |
71
|
|
|
var $keywords; //keywords |
72
|
|
|
var $creator; //creator |
73
|
|
|
var $AliasNbPages; //alias for total number of pages |
74
|
|
|
var $PDFVersion; //PDF version number |
75
|
|
|
|
76
|
|
|
/******************************************************************************* |
77
|
|
|
* * |
78
|
|
|
* Public methods * |
79
|
|
|
* * |
80
|
|
|
*******************************************************************************/ |
81
|
|
|
function FPDF($orientation='P',$unit='mm',$format='A4') |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
//Some checks |
84
|
|
|
$this->_dochecks(); |
85
|
|
|
//Initialization of properties |
86
|
|
|
$this->page=0; |
87
|
|
|
$this->n=2; |
88
|
|
|
$this->buffer=''; |
89
|
|
|
$this->pages=array(); |
90
|
|
|
$this->OrientationChanges=array(); |
91
|
|
|
$this->state=0; |
92
|
|
|
$this->fonts=array(); |
93
|
|
|
$this->FontFiles=array(); |
94
|
|
|
$this->diffs=array(); |
95
|
|
|
$this->images=array(); |
96
|
|
|
$this->links=array(); |
97
|
|
|
$this->InFooter=false; |
98
|
|
|
$this->lasth=0; |
99
|
|
|
$this->FontFamily=''; |
100
|
|
|
$this->FontStyle=''; |
101
|
|
|
$this->FontSizePt=12; |
102
|
|
|
$this->underline=false; |
103
|
|
|
$this->DrawColor='0 G'; |
104
|
|
|
$this->FillColor='0 g'; |
105
|
|
|
$this->TextColor='0 g'; |
106
|
|
|
$this->ColorFlag=false; |
107
|
|
|
$this->ws=0; |
108
|
|
|
//Standard fonts |
109
|
|
|
$this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', |
110
|
|
|
'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', |
111
|
|
|
'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', |
112
|
|
|
'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); |
113
|
|
|
//Scale factor |
114
|
|
|
if($unit=='pt') |
115
|
|
|
$this->k=1; |
116
|
|
|
elseif($unit=='mm') |
117
|
|
|
$this->k=72/25.4; |
118
|
|
|
elseif($unit=='cm') |
119
|
|
|
$this->k=72/2.54; |
120
|
|
|
elseif($unit=='in') |
121
|
|
|
$this->k=72; |
122
|
|
|
else |
123
|
|
|
$this->Error('Incorrect unit: '.$unit); |
124
|
|
|
//Page format |
125
|
|
|
if(is_string($format)) |
126
|
|
|
{ |
127
|
|
|
$format=strtolower($format); |
128
|
|
|
if($format=='a3') |
129
|
|
|
$format=array(841.89,1190.55); |
130
|
|
|
elseif($format=='a4') |
131
|
|
|
$format=array(595.28,841.89); |
132
|
|
|
elseif($format=='a5') |
133
|
|
|
$format=array(420.94,595.28); |
134
|
|
|
elseif($format=='letter') |
135
|
|
|
$format=array(612,792); |
136
|
|
|
elseif($format=='legal') |
137
|
|
|
$format=array(612,1008); |
138
|
|
|
else |
139
|
|
|
$this->Error('Unknown page format: '.$format); |
140
|
|
|
$this->fwPt=$format[0]; |
141
|
|
|
$this->fhPt=$format[1]; |
142
|
|
|
} |
143
|
|
|
else |
144
|
|
|
{ |
145
|
|
|
$this->fwPt=$format[0]*$this->k; |
146
|
|
|
$this->fhPt=$format[1]*$this->k; |
147
|
|
|
} |
148
|
|
|
$this->fw=$this->fwPt/$this->k; |
149
|
|
|
$this->fh=$this->fhPt/$this->k; |
150
|
|
|
//Page orientation |
151
|
|
|
$orientation=strtolower($orientation); |
152
|
|
|
if($orientation=='p' || $orientation=='portrait') |
153
|
|
|
{ |
154
|
|
|
$this->DefOrientation='P'; |
155
|
|
|
$this->wPt=$this->fwPt; |
156
|
|
|
$this->hPt=$this->fhPt; |
157
|
|
|
} |
158
|
|
|
elseif($orientation=='l' || $orientation=='landscape') |
159
|
|
|
{ |
160
|
|
|
$this->DefOrientation='L'; |
161
|
|
|
$this->wPt=$this->fhPt; |
162
|
|
|
$this->hPt=$this->fwPt; |
163
|
|
|
} |
164
|
|
|
else |
165
|
|
|
$this->Error('Incorrect orientation: '.$orientation); |
166
|
|
|
$this->CurOrientation=$this->DefOrientation; |
167
|
|
|
$this->w=$this->wPt/$this->k; |
168
|
|
|
$this->h=$this->hPt/$this->k; |
169
|
|
|
//Page margins (1 cm) |
170
|
|
|
$margin=28.35/$this->k; |
171
|
|
|
$this->SetMargins($margin,$margin); |
172
|
|
|
//Interior cell margin (1 mm) |
173
|
|
|
$this->cMargin=$margin/10; |
174
|
|
|
//Line width (0.2 mm) |
175
|
|
|
$this->LineWidth=.567/$this->k; |
176
|
|
|
//Automatic page break |
177
|
|
|
$this->SetAutoPageBreak(true,2*$margin); |
178
|
|
|
//Full width display mode |
179
|
|
|
$this->SetDisplayMode('fullwidth'); |
180
|
|
|
//Enable compression |
181
|
|
|
$this->SetCompression(true); |
182
|
|
|
//Set default PDF version number |
183
|
|
|
$this->PDFVersion='1.3'; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
function SetMargins($left,$top,$right=-1) |
|
|
|
|
187
|
|
|
{ |
188
|
|
|
//Set left, top and right margins |
189
|
|
|
$this->lMargin=$left; |
190
|
|
|
$this->tMargin=$top; |
191
|
|
|
if($right==-1) |
192
|
|
|
$right=$left; |
193
|
|
|
$this->rMargin=$right; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
function SetLeftMargin($margin) |
|
|
|
|
197
|
|
|
{ |
198
|
|
|
//Set left margin |
199
|
|
|
$this->lMargin=$margin; |
200
|
|
|
if($this->page>0 && $this->x<$margin) |
201
|
|
|
$this->x=$margin; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
function SetTopMargin($margin) |
|
|
|
|
205
|
|
|
{ |
206
|
|
|
//Set top margin |
207
|
|
|
$this->tMargin=$margin; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
function SetRightMargin($margin) |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
//Set right margin |
213
|
|
|
$this->rMargin=$margin; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
function SetAutoPageBreak($auto,$margin=0) |
|
|
|
|
217
|
|
|
{ |
218
|
|
|
//Set auto page break mode and triggering margin |
219
|
|
|
$this->AutoPageBreak=$auto; |
220
|
|
|
$this->bMargin=$margin; |
221
|
|
|
$this->PageBreakTrigger=$this->h-$margin; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
function SetDisplayMode($zoom,$layout='continuous') |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
//Set display mode in viewer |
227
|
|
|
if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) |
228
|
|
|
$this->ZoomMode=$zoom; |
229
|
|
|
else |
230
|
|
|
$this->Error('Incorrect zoom display mode: '.$zoom); |
231
|
|
|
if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') |
232
|
|
|
$this->LayoutMode=$layout; |
233
|
|
|
else |
234
|
|
|
$this->Error('Incorrect layout display mode: '.$layout); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
function SetCompression($compress) |
|
|
|
|
238
|
|
|
{ |
239
|
|
|
//Set page compression |
240
|
|
|
if(function_exists('gzcompress')) |
241
|
|
|
$this->compress=$compress; |
242
|
|
|
else |
243
|
|
|
$this->compress=false; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
function SetTitle($title) |
|
|
|
|
247
|
|
|
{ |
248
|
|
|
//Title of document |
249
|
|
|
$this->title=$title; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
function SetSubject($subject) |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
//Subject of document |
255
|
|
|
$this->subject=$subject; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
function SetAuthor($author) |
|
|
|
|
259
|
|
|
{ |
260
|
|
|
//Author of document |
261
|
|
|
$this->author=$author; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
function SetKeywords($keywords) |
|
|
|
|
265
|
|
|
{ |
266
|
|
|
//Keywords of document |
267
|
|
|
$this->keywords=$keywords; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
function SetCreator($creator) |
|
|
|
|
271
|
|
|
{ |
272
|
|
|
//Creator of document |
273
|
|
|
$this->creator=$creator; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
function AliasNbPages($alias='{nb}') |
|
|
|
|
277
|
|
|
{ |
278
|
|
|
//Define an alias for total number of pages |
279
|
|
|
$this->AliasNbPages=$alias; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
function Error($msg) |
|
|
|
|
283
|
|
|
{ |
284
|
|
|
//Fatal error |
285
|
|
|
//die('<B>FPDF error: </B>'.$msg); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
function Open() |
|
|
|
|
289
|
|
|
{ |
290
|
|
|
//Begin document |
291
|
|
|
$this->state=1; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
function Close() |
|
|
|
|
295
|
|
|
{ |
296
|
|
|
//Terminate document |
297
|
|
|
if($this->state==3) |
298
|
|
|
return; |
299
|
|
|
if($this->page==0) |
300
|
|
|
$this->AddPage(); |
301
|
|
|
//Page footer |
302
|
|
|
$this->InFooter=true; |
303
|
|
|
$this->Footer(); |
304
|
|
|
$this->InFooter=false; |
305
|
|
|
//Close page |
306
|
|
|
$this->_endpage(); |
307
|
|
|
//Close document |
308
|
|
|
$this->_enddoc(); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
function AddPage($orientation='') |
|
|
|
|
312
|
|
|
{ |
313
|
|
|
//Start a new page |
314
|
|
|
if($this->state==0) |
315
|
|
|
$this->Open(); |
316
|
|
|
$family=$this->FontFamily; |
317
|
|
|
$style=$this->FontStyle.($this->underline ? 'U' : ''); |
318
|
|
|
$size=$this->FontSizePt; |
319
|
|
|
$lw=$this->LineWidth; |
320
|
|
|
$dc=$this->DrawColor; |
321
|
|
|
$fc=$this->FillColor; |
322
|
|
|
$tc=$this->TextColor; |
323
|
|
|
$cf=$this->ColorFlag; |
324
|
|
|
if($this->page>0) |
325
|
|
|
{ |
326
|
|
|
//Page footer |
327
|
|
|
$this->InFooter=true; |
328
|
|
|
$this->Footer(); |
329
|
|
|
$this->InFooter=false; |
330
|
|
|
//Close page |
331
|
|
|
$this->_endpage(); |
332
|
|
|
} |
333
|
|
|
//Start new page |
334
|
|
|
$this->_beginpage($orientation); |
335
|
|
|
//Set line cap style to square |
336
|
|
|
$this->_out('2 J'); |
337
|
|
|
//Set line width |
338
|
|
|
$this->LineWidth=$lw; |
339
|
|
|
$this->_out(sprintf('%.2f w',$lw*$this->k)); |
340
|
|
|
//Set font |
341
|
|
|
if($family) |
342
|
|
|
$this->SetFont($family,$style,$size); |
343
|
|
|
//Set colors |
344
|
|
|
$this->DrawColor=$dc; |
345
|
|
|
if($dc!='0 G') |
346
|
|
|
$this->_out($dc); |
347
|
|
|
$this->FillColor=$fc; |
348
|
|
|
if($fc!='0 g') |
349
|
|
|
$this->_out($fc); |
350
|
|
|
$this->TextColor=$tc; |
351
|
|
|
$this->ColorFlag=$cf; |
352
|
|
|
//Page header |
353
|
|
|
$this->Header(); |
354
|
|
|
//Restore line width |
355
|
|
|
if($this->LineWidth!=$lw) |
356
|
|
|
{ |
357
|
|
|
$this->LineWidth=$lw; |
358
|
|
|
$this->_out(sprintf('%.2f w',$lw*$this->k)); |
359
|
|
|
} |
360
|
|
|
//Restore font |
361
|
|
|
if($family) |
362
|
|
|
$this->SetFont($family,$style,$size); |
363
|
|
|
//Restore colors |
364
|
|
|
if($this->DrawColor!=$dc) |
365
|
|
|
{ |
366
|
|
|
$this->DrawColor=$dc; |
367
|
|
|
$this->_out($dc); |
368
|
|
|
} |
369
|
|
|
if($this->FillColor!=$fc) |
370
|
|
|
{ |
371
|
|
|
$this->FillColor=$fc; |
372
|
|
|
$this->_out($fc); |
373
|
|
|
} |
374
|
|
|
$this->TextColor=$tc; |
375
|
|
|
$this->ColorFlag=$cf; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
function Header() |
|
|
|
|
379
|
|
|
{ |
380
|
|
|
//To be implemented in your own inherited class |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
function Footer() |
|
|
|
|
384
|
|
|
{ |
385
|
|
|
//To be implemented in your own inherited class |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
function PageNo() |
|
|
|
|
389
|
|
|
{ |
390
|
|
|
//Get current page number |
391
|
|
|
return $this->page; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
View Code Duplication |
function SetDrawColor($r,$g=-1,$b=-1) |
|
|
|
|
395
|
|
|
{ |
396
|
|
|
//Set color for all stroking operations |
397
|
|
|
if(($r==0 && $g==0 && $b==0) || $g==-1) |
398
|
|
|
$this->DrawColor=sprintf('%.3f G',$r/255); |
399
|
|
|
else |
400
|
|
|
$this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); |
401
|
|
|
if($this->page>0) |
402
|
|
|
$this->_out($this->DrawColor); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
function SetFillColor($r,$g=-1,$b=-1) |
|
|
|
|
406
|
|
|
{ |
407
|
|
|
//Set color for all filling operations |
408
|
|
|
if(($r==0 && $g==0 && $b==0) || $g==-1) |
409
|
|
|
$this->FillColor=sprintf('%.3f g',$r/255); |
410
|
|
|
else |
411
|
|
|
$this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); |
412
|
|
|
$this->ColorFlag=($this->FillColor!=$this->TextColor); |
413
|
|
|
if($this->page>0) |
414
|
|
|
$this->_out($this->FillColor); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
View Code Duplication |
function SetTextColor($r,$g=-1,$b=-1) |
|
|
|
|
418
|
|
|
{ |
419
|
|
|
//Set color for text |
420
|
|
|
if(($r==0 && $g==0 && $b==0) || $g==-1) |
421
|
|
|
$this->TextColor=sprintf('%.3f g',$r/255); |
422
|
|
|
else |
423
|
|
|
$this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); |
424
|
|
|
$this->ColorFlag=($this->FillColor!=$this->TextColor); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
function GetStringWidth($s) |
|
|
|
|
428
|
|
|
{ |
429
|
|
|
//Get width of a string in the current font |
430
|
|
|
$s=(string)$s; |
431
|
|
|
$cw=&$this->CurrentFont['cw']; |
432
|
|
|
$w=0; |
433
|
|
|
$l=strlen($s); |
434
|
|
|
for($i=0;$i<$l;$i++) |
435
|
|
|
$w+=$cw[$s{$i}]; |
436
|
|
|
|
437
|
|
|
return $w*$this->FontSize/1000; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
function SetLineWidth($width) |
|
|
|
|
441
|
|
|
{ |
442
|
|
|
//Set line width |
443
|
|
|
$this->LineWidth=$width; |
444
|
|
|
if($this->page>0) |
445
|
|
|
$this->_out(sprintf('%.2f w',$width*$this->k)); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
function Line($x1,$y1,$x2,$y2) |
|
|
|
|
449
|
|
|
{ |
450
|
|
|
//Draw a line |
451
|
|
|
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k)); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
function Rect($x,$y,$w,$h,$style='') |
|
|
|
|
455
|
|
|
{ |
456
|
|
|
//Draw a rectangle |
457
|
|
|
if($style=='F') |
458
|
|
|
$op='f'; |
459
|
|
|
elseif($style=='FD' || $style=='DF') |
460
|
|
|
$op='B'; |
461
|
|
|
else |
462
|
|
|
$op='S'; |
463
|
|
|
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
function AddFont($family,$style='',$file='') |
|
|
|
|
467
|
|
|
{ |
468
|
|
|
//Add a TrueType or Type1 font |
469
|
|
|
$family=strtolower($family); |
470
|
|
|
if($file=='') |
471
|
|
|
$file=str_replace(' ','',$family).strtolower($style).'.php'; |
472
|
|
|
if($family=='arial') |
473
|
|
|
$family='helvetica'; |
474
|
|
|
$style=strtoupper($style); |
475
|
|
|
if($style=='IB') |
476
|
|
|
$style='BI'; |
477
|
|
|
$fontkey=$family.$style; |
478
|
|
|
if(isset($this->fonts[$fontkey])) |
479
|
|
|
$this->Error('Font already added: '.$family.' '.$style); |
480
|
|
|
include($this->_getfontpath().$file); |
481
|
|
|
if(!isset($name)) |
|
|
|
|
482
|
|
|
$this->Error('Could not include font definition file'); |
483
|
|
|
$i=count($this->fonts)+1; |
484
|
|
|
$this->fonts[$fontkey]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); |
|
|
|
|
485
|
|
|
if($diff) |
486
|
|
|
{ |
487
|
|
|
//Search existing encodings |
488
|
|
|
$d=0; |
489
|
|
|
$nb=count($this->diffs); |
490
|
|
|
for($i=1;$i<=$nb;$i++) |
491
|
|
|
{ |
492
|
|
|
if($this->diffs[$i]==$diff) |
|
|
|
|
493
|
|
|
{ |
494
|
|
|
$d=$i; |
495
|
|
|
break; |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
if($d==0) |
499
|
|
|
{ |
500
|
|
|
$d=$nb+1; |
501
|
|
|
$this->diffs[$d]=$diff; |
502
|
|
|
} |
503
|
|
|
$this->fonts[$fontkey]['diff']=$d; |
504
|
|
|
} |
505
|
|
|
if($file) |
506
|
|
|
{ |
507
|
|
|
if($type=='TrueType') |
508
|
|
|
$this->FontFiles[$file]=array('length1'=>$originalsize); |
|
|
|
|
509
|
|
|
else |
510
|
|
|
$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); |
|
|
|
|
511
|
|
|
} |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
function SetFont($family,$style='',$size=0) |
|
|
|
|
515
|
|
|
{ |
516
|
|
|
//Select a font; size given in points |
517
|
|
|
global $fpdf_charwidths; |
518
|
|
|
|
519
|
|
|
$family=strtolower($family); |
520
|
|
|
if($family=='') |
521
|
|
|
$family=$this->FontFamily; |
522
|
|
|
if($family=='arial') |
523
|
|
|
$family='helvetica'; |
524
|
|
|
elseif($family=='symbol' || $family=='zapfdingbats') |
525
|
|
|
$style=''; |
526
|
|
|
$style=strtoupper($style); |
527
|
|
|
if(strpos($style,'U')!==false) |
528
|
|
|
{ |
529
|
|
|
$this->underline=true; |
530
|
|
|
$style=str_replace('U','',$style); |
531
|
|
|
} |
532
|
|
|
else |
533
|
|
|
$this->underline=false; |
534
|
|
|
if($style=='IB') |
535
|
|
|
$style='BI'; |
536
|
|
|
if($size==0) |
537
|
|
|
$size=$this->FontSizePt; |
538
|
|
|
//Test if font is already selected |
539
|
|
|
if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) |
540
|
|
|
return; |
541
|
|
|
//Test if used for the first time |
542
|
|
|
$fontkey=$family.$style; |
543
|
|
|
if(!isset($this->fonts[$fontkey])) |
544
|
|
|
{ |
545
|
|
|
//Check if one of the standard fonts |
546
|
|
|
if(isset($this->CoreFonts[$fontkey])) |
547
|
|
|
{ |
548
|
|
|
if(!isset($fpdf_charwidths[$fontkey])) |
549
|
|
|
{ |
550
|
|
|
//Load metric file |
551
|
|
|
$file=$family; |
552
|
|
|
if($family=='times' || $family=='helvetica') |
553
|
|
|
$file.=strtolower($style); |
554
|
|
|
include($this->_getfontpath().$file.'.php'); |
555
|
|
|
if(!isset($fpdf_charwidths[$fontkey])) |
556
|
|
|
$this->Error('Could not include font metric file'); |
557
|
|
|
} |
558
|
|
|
$i=count($this->fonts)+1; |
559
|
|
|
$this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); |
560
|
|
|
} |
561
|
|
|
else |
562
|
|
|
$this->Error('Undefined font: '.$family.' '.$style); |
563
|
|
|
} |
564
|
|
|
//Select it |
565
|
|
|
$this->FontFamily=$family; |
566
|
|
|
$this->FontStyle=$style; |
567
|
|
|
$this->FontSizePt=$size; |
568
|
|
|
$this->FontSize=$size/$this->k; |
569
|
|
|
$this->CurrentFont=&$this->fonts[$fontkey]; |
570
|
|
View Code Duplication |
if($this->page>0) |
|
|
|
|
571
|
|
|
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
function SetFontSize($size) |
|
|
|
|
575
|
|
|
{ |
576
|
|
|
//Set font size in points |
577
|
|
|
if($this->FontSizePt==$size) |
578
|
|
|
return; |
579
|
|
|
$this->FontSizePt=$size; |
580
|
|
|
$this->FontSize=$size/$this->k; |
581
|
|
View Code Duplication |
if($this->page>0) |
|
|
|
|
582
|
|
|
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
function AddLink() |
|
|
|
|
586
|
|
|
{ |
587
|
|
|
//Create a new internal link |
588
|
|
|
$n=count($this->links)+1; |
589
|
|
|
$this->links[$n]=array(0,0); |
590
|
|
|
|
591
|
|
|
return $n; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
function SetLink($link,$y=0,$page=-1) |
|
|
|
|
595
|
|
|
{ |
596
|
|
|
//Set destination of internal link |
597
|
|
|
if($y==-1) |
598
|
|
|
$y=$this->y; |
599
|
|
|
if($page==-1) |
600
|
|
|
$page=$this->page; |
601
|
|
|
$this->links[$link]=array($page,$y); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
function Link($x,$y,$w,$h,$link) |
|
|
|
|
605
|
|
|
{ |
606
|
|
|
//Put a link on the page |
607
|
|
|
$this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
function Text($x,$y,$txt) |
|
|
|
|
611
|
|
|
{ |
612
|
|
|
//Output a string |
613
|
|
|
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); |
614
|
|
|
if($this->underline && $txt!='') |
615
|
|
|
$s.=' '.$this->_dounderline($x,$y,$txt); |
616
|
|
|
if($this->ColorFlag) |
617
|
|
|
$s='q '.$this->TextColor.' '.$s.' Q'; |
618
|
|
|
$this->_out($s); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
function AcceptPageBreak() |
|
|
|
|
622
|
|
|
{ |
623
|
|
|
//Accept automatic page break or not |
624
|
|
|
return $this->AutoPageBreak; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') |
|
|
|
|
628
|
|
|
{ |
629
|
|
|
//Output a cell |
630
|
|
|
$k=$this->k; |
631
|
|
|
if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) |
632
|
|
|
{ |
633
|
|
|
//Automatic page break |
634
|
|
|
$x=$this->x; |
635
|
|
|
$ws=$this->ws; |
636
|
|
|
if($ws>0) |
637
|
|
|
{ |
638
|
|
|
$this->ws=0; |
639
|
|
|
$this->_out('0 Tw'); |
640
|
|
|
} |
641
|
|
|
$this->AddPage($this->CurOrientation); |
642
|
|
|
$this->x=$x; |
643
|
|
|
if($ws>0) |
644
|
|
|
{ |
645
|
|
|
$this->ws=$ws; |
646
|
|
|
$this->_out(sprintf('%.3f Tw',$ws*$k)); |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
if($w==0) |
650
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
651
|
|
|
$s=''; |
652
|
|
|
if($fill==1 || $border==1) |
653
|
|
|
{ |
654
|
|
|
if($fill==1) |
655
|
|
|
$op=($border==1) ? 'B' : 'f'; |
656
|
|
|
else |
657
|
|
|
$op='S'; |
658
|
|
|
$s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); |
659
|
|
|
} |
660
|
|
|
if(is_string($border)) |
661
|
|
|
{ |
662
|
|
|
$x=$this->x; |
663
|
|
|
$y=$this->y; |
664
|
|
View Code Duplication |
if(strpos($border,'L')!==false) |
|
|
|
|
665
|
|
|
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); |
666
|
|
View Code Duplication |
if(strpos($border,'T')!==false) |
|
|
|
|
667
|
|
|
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); |
668
|
|
View Code Duplication |
if(strpos($border,'R')!==false) |
|
|
|
|
669
|
|
|
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
670
|
|
View Code Duplication |
if(strpos($border,'B')!==false) |
|
|
|
|
671
|
|
|
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); |
672
|
|
|
} |
673
|
|
|
if($txt!=='') |
674
|
|
|
{ |
675
|
|
|
if($align=='R') |
676
|
|
|
$dx=$w-$this->cMargin-$this->GetStringWidth($txt); |
677
|
|
|
elseif($align=='C') |
678
|
|
|
$dx=($w-$this->GetStringWidth($txt))/2; |
679
|
|
|
else |
680
|
|
|
$dx=$this->cMargin; |
681
|
|
|
if($this->ColorFlag) |
682
|
|
|
$s.='q '.$this->TextColor.' '; |
683
|
|
|
$txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); |
684
|
|
|
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); |
685
|
|
|
if($this->underline) |
686
|
|
|
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); |
687
|
|
|
if($this->ColorFlag) |
688
|
|
|
$s.=' Q'; |
689
|
|
|
if($link) |
690
|
|
|
$this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); |
691
|
|
|
} |
692
|
|
|
if($s) |
693
|
|
|
$this->_out($s); |
694
|
|
|
$this->lasth=$h; |
695
|
|
|
if($ln>0) |
696
|
|
|
{ |
697
|
|
|
//Go to next line |
698
|
|
|
$this->y+=$h; |
699
|
|
|
if($ln==1) |
700
|
|
|
$this->x=$this->lMargin; |
701
|
|
|
} |
702
|
|
|
else |
703
|
|
|
$this->x+=$w; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) |
|
|
|
|
707
|
|
|
{ |
708
|
|
|
//Output text with automatic or explicit line breaks |
709
|
|
|
$cw=&$this->CurrentFont['cw']; |
710
|
|
|
if($w==0) |
711
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
712
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
713
|
|
|
$s=str_replace("\r",'',$txt); |
714
|
|
|
$nb=strlen($s); |
715
|
|
|
if($nb>0 && $s[$nb-1]=="\n") |
716
|
|
|
$nb--; |
717
|
|
|
$b=0; |
718
|
|
|
if($border) |
719
|
|
|
{ |
720
|
|
|
if($border==1) |
721
|
|
|
{ |
722
|
|
|
$border='LTRB'; |
723
|
|
|
$b='LRT'; |
724
|
|
|
$b2='LR'; |
725
|
|
|
} |
726
|
|
|
else |
727
|
|
|
{ |
728
|
|
|
$b2=''; |
729
|
|
|
if(strpos($border,'L')!==false) |
730
|
|
|
$b2.='L'; |
731
|
|
|
if(strpos($border,'R')!==false) |
732
|
|
|
$b2.='R'; |
733
|
|
|
$b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; |
734
|
|
|
} |
735
|
|
|
} |
736
|
|
|
$sep=-1; |
737
|
|
|
$i=0; |
738
|
|
|
$j=0; |
739
|
|
|
$l=0; |
740
|
|
|
$ns=0; |
741
|
|
|
$nl=1; |
742
|
|
|
while($i<$nb) |
743
|
|
|
{ |
744
|
|
|
//Get next character |
745
|
|
|
$c=$s{$i}; |
746
|
|
|
if($c=="\n") |
747
|
|
|
{ |
748
|
|
|
//Explicit line break |
749
|
|
|
if($this->ws>0) |
750
|
|
|
{ |
751
|
|
|
$this->ws=0; |
752
|
|
|
$this->_out('0 Tw'); |
753
|
|
|
} |
754
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
755
|
|
|
$i++; |
756
|
|
|
$sep=-1; |
757
|
|
|
$j=$i; |
758
|
|
|
$l=0; |
759
|
|
|
$ns=0; |
760
|
|
|
$nl++; |
761
|
|
|
if($border && $nl==2) |
762
|
|
|
$b=$b2; |
|
|
|
|
763
|
|
|
continue; |
764
|
|
|
} |
765
|
|
|
if($c==' ') |
766
|
|
|
{ |
767
|
|
|
$sep=$i; |
768
|
|
|
$ls=$l; |
769
|
|
|
$ns++; |
770
|
|
|
} |
771
|
|
|
$l+=$cw[$c]; |
772
|
|
|
if($l>$wmax) |
773
|
|
|
{ |
774
|
|
|
//Automatic line break |
775
|
|
|
if($sep==-1) |
776
|
|
|
{ |
777
|
|
|
if($i==$j) |
778
|
|
|
$i++; |
779
|
|
|
if($this->ws>0) |
780
|
|
|
{ |
781
|
|
|
$this->ws=0; |
782
|
|
|
$this->_out('0 Tw'); |
783
|
|
|
} |
784
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
785
|
|
|
} |
786
|
|
|
else |
787
|
|
|
{ |
788
|
|
|
if($align=='J') |
789
|
|
|
{ |
790
|
|
|
$this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; |
|
|
|
|
791
|
|
|
$this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); |
792
|
|
|
} |
793
|
|
|
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); |
794
|
|
|
$i=$sep+1; |
795
|
|
|
} |
796
|
|
|
$sep=-1; |
797
|
|
|
$j=$i; |
798
|
|
|
$l=0; |
799
|
|
|
$ns=0; |
800
|
|
|
$nl++; |
801
|
|
|
if($border && $nl==2) |
802
|
|
|
$b=$b2; |
803
|
|
|
} |
804
|
|
|
else |
805
|
|
|
$i++; |
806
|
|
|
} |
807
|
|
|
//Last chunk |
808
|
|
|
if($this->ws>0) |
809
|
|
|
{ |
810
|
|
|
$this->ws=0; |
811
|
|
|
$this->_out('0 Tw'); |
812
|
|
|
} |
813
|
|
|
if($border && strpos($border,'B')!==false) |
814
|
|
|
$b.='B'; |
815
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); |
816
|
|
|
$this->x=$this->lMargin; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
function Write($h,$txt,$link='') |
|
|
|
|
820
|
|
|
{ |
821
|
|
|
//Output text in flowing mode |
822
|
|
|
$cw=&$this->CurrentFont['cw']; |
823
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
824
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
825
|
|
|
$s=str_replace("\r",'',$txt); |
826
|
|
|
$nb=strlen($s); |
827
|
|
|
$sep=-1; |
828
|
|
|
$i=0; |
829
|
|
|
$j=0; |
830
|
|
|
$l=0; |
831
|
|
|
$nl=1; |
832
|
|
|
while($i<$nb) |
833
|
|
|
{ |
834
|
|
|
//Get next character |
835
|
|
|
$c=$s{$i}; |
836
|
|
|
if($c=="\n") |
837
|
|
|
{ |
838
|
|
|
//Explicit line break |
839
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
840
|
|
|
$i++; |
841
|
|
|
$sep=-1; |
842
|
|
|
$j=$i; |
843
|
|
|
$l=0; |
844
|
|
|
if($nl==1) |
845
|
|
|
{ |
846
|
|
|
$this->x=$this->lMargin; |
847
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
848
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
849
|
|
|
} |
850
|
|
|
$nl++; |
851
|
|
|
continue; |
852
|
|
|
} |
853
|
|
|
if($c==' ') |
854
|
|
|
$sep=$i; |
855
|
|
|
$l+=$cw[$c]; |
856
|
|
|
if($l>$wmax) |
857
|
|
|
{ |
858
|
|
|
//Automatic line break |
859
|
|
|
if($sep==-1) |
860
|
|
|
{ |
861
|
|
|
if($this->x>$this->lMargin) |
862
|
|
|
{ |
863
|
|
|
//Move to next line |
864
|
|
|
$this->x=$this->lMargin; |
865
|
|
|
$this->y+=$h; |
866
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
867
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
868
|
|
|
$i++; |
869
|
|
|
$nl++; |
870
|
|
|
continue; |
871
|
|
|
} |
872
|
|
|
if($i==$j) |
873
|
|
|
$i++; |
874
|
|
|
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); |
875
|
|
|
} |
876
|
|
|
else |
877
|
|
|
{ |
878
|
|
|
$this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); |
879
|
|
|
$i=$sep+1; |
880
|
|
|
} |
881
|
|
|
$sep=-1; |
882
|
|
|
$j=$i; |
883
|
|
|
$l=0; |
884
|
|
|
if($nl==1) |
885
|
|
|
{ |
886
|
|
|
$this->x=$this->lMargin; |
887
|
|
|
$w=$this->w-$this->rMargin-$this->x; |
888
|
|
|
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize; |
889
|
|
|
} |
890
|
|
|
$nl++; |
891
|
|
|
} |
892
|
|
|
else |
893
|
|
|
$i++; |
894
|
|
|
} |
895
|
|
|
//Last chunk |
896
|
|
|
if($i!=$j) |
897
|
|
|
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') |
|
|
|
|
901
|
|
|
{ |
902
|
|
|
//Put an image on the page |
903
|
|
|
if(!isset($this->images[$file])) |
904
|
|
|
{ |
905
|
|
|
//First use of image, get info |
906
|
|
|
if($type=='') |
907
|
|
|
{ |
908
|
|
|
$pos=strrpos($file,'.'); |
909
|
|
|
if(!$pos) |
910
|
|
|
$this->Error('Image file has no extension and no type was specified: '.$file); |
911
|
|
|
$type=substr($file,$pos+1); |
912
|
|
|
} |
913
|
|
|
$type=strtolower($type); |
914
|
|
|
$mqr=get_magic_quotes_runtime(); |
915
|
|
|
set_magic_quotes_runtime(0); |
916
|
|
|
if($type=='jpg' || $type=='jpeg') |
917
|
|
|
$info=$this->_parsejpg($file); |
918
|
|
|
elseif($type=='png') |
919
|
|
|
$info=$this->_parsepng($file); |
920
|
|
|
else |
921
|
|
|
{ |
922
|
|
|
//Allow for additional formats |
923
|
|
|
$mtd='_parse'.$type; |
924
|
|
|
if(!method_exists($this,$mtd)) |
925
|
|
|
$this->Error('Unsupported image type: '.$type); |
926
|
|
|
else $info=$this->$mtd($file); |
927
|
|
|
} |
928
|
|
|
if(empty($info)) return null; |
929
|
|
|
set_magic_quotes_runtime($mqr); |
930
|
|
|
$info['i']=count($this->images)+1; |
931
|
|
|
$this->images[$file]=$info; |
932
|
|
|
} |
933
|
|
|
else |
934
|
|
|
$info=$this->images[$file]; |
935
|
|
|
//Automatic width and height calculation if needed |
936
|
|
|
if($w==0 && $h==0) |
937
|
|
|
{ |
938
|
|
|
//Put image at 72 dpi |
939
|
|
|
$w=$info['w']/$this->k; |
940
|
|
|
$h=$info['h']/$this->k; |
941
|
|
|
} |
942
|
|
|
if($w==0) |
943
|
|
|
$w=$h*$info['w']/$info['h']; |
944
|
|
|
if($h==0) |
945
|
|
|
$h=$w*$info['h']/$info['w']; |
946
|
|
|
$this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q',$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info['i'])); |
947
|
|
|
if($link) |
948
|
|
|
$this->Link($x,$y,$w,$h,$link); |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
function Ln($h='') |
|
|
|
|
952
|
|
|
{ |
953
|
|
|
//Line feed; default value is last cell height |
954
|
|
|
$this->x=$this->lMargin; |
955
|
|
|
if(is_string($h)) |
956
|
|
|
$this->y+=$this->lasth; |
957
|
|
|
else |
958
|
|
|
$this->y+=$h; |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
function GetX() |
|
|
|
|
962
|
|
|
{ |
963
|
|
|
//Get x position |
964
|
|
|
return $this->x; |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
function SetX($x) |
|
|
|
|
968
|
|
|
{ |
969
|
|
|
//Set x position |
970
|
|
|
if($x>=0) |
971
|
|
|
$this->x=$x; |
972
|
|
|
else |
973
|
|
|
$this->x=$this->w+$x; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
function GetY() |
|
|
|
|
977
|
|
|
{ |
978
|
|
|
//Get y position |
979
|
|
|
return $this->y; |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
function SetY($y) |
|
|
|
|
983
|
|
|
{ |
984
|
|
|
//Set y position and reset x |
985
|
|
|
$this->x=$this->lMargin; |
986
|
|
|
if($y>=0) |
987
|
|
|
$this->y=$y; |
988
|
|
|
else |
989
|
|
|
$this->y=$this->h+$y; |
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
function SetXY($x,$y) |
|
|
|
|
993
|
|
|
{ |
994
|
|
|
//Set x and y positions |
995
|
|
|
$this->SetY($y); |
996
|
|
|
$this->SetX($x); |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
function Output($name='',$dest='') |
|
|
|
|
1000
|
|
|
{ |
1001
|
|
|
//Output PDF to some destination |
1002
|
|
|
//Finish document if necessary |
1003
|
|
|
if($this->state<3) |
1004
|
|
|
$this->Close(); |
1005
|
|
|
//Normalize parameters |
1006
|
|
|
if(is_bool($dest)) |
1007
|
|
|
$dest=$dest ? 'D' : 'F'; |
1008
|
|
|
$dest=strtoupper($dest); |
1009
|
|
|
if($dest=='') |
1010
|
|
|
{ |
1011
|
|
|
if($name=='') |
1012
|
|
|
{ |
1013
|
|
|
$name='doc.pdf'; |
1014
|
|
|
$dest='I'; |
1015
|
|
|
} |
1016
|
|
|
else |
1017
|
|
|
$dest='F'; |
1018
|
|
|
} |
1019
|
|
|
switch($dest) |
1020
|
|
|
{ |
1021
|
|
|
case 'I': |
1022
|
|
|
//Send to standard output |
1023
|
|
|
if(ob_get_contents()) |
1024
|
|
|
$this->Error('Some data has already been output, can\'t send PDF file'); |
1025
|
|
|
if(php_sapi_name()!='cli') |
1026
|
|
|
{ |
1027
|
|
|
//We send to a browser |
1028
|
|
|
header('Content-Type: application/pdf'); |
1029
|
|
|
if(headers_sent()) |
1030
|
|
|
$this->Error('Some data has already been output to browser, can\'t send PDF file'); |
1031
|
|
|
header('Content-Length: '.strlen($this->buffer)); |
1032
|
|
|
header('Content-disposition: inline; filename="'.$name.'"'); |
1033
|
|
|
} |
1034
|
|
|
echo $this->buffer; |
1035
|
|
|
break; |
1036
|
|
|
case 'D': |
1037
|
|
|
//Download file |
1038
|
|
|
if(ob_get_contents()) |
1039
|
|
|
$this->Error('Some data has already been output, can\'t send PDF file'); |
1040
|
|
|
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) |
1041
|
|
|
header('Content-Type: application/force-download'); |
1042
|
|
|
else |
1043
|
|
|
header('Content-Type: application/octet-stream'); |
1044
|
|
|
if(headers_sent()) |
1045
|
|
|
$this->Error('Some data has already been output to browser, can\'t send PDF file'); |
1046
|
|
|
header('Content-Length: '.strlen($this->buffer)); |
1047
|
|
|
header('Content-disposition: attachment; filename="'.$name.'"'); |
1048
|
|
|
echo $this->buffer; |
1049
|
|
|
break; |
1050
|
|
|
case 'F': |
1051
|
|
|
//Save to local file |
1052
|
|
|
$f=fopen($name,'wb'); |
1053
|
|
|
if(!$f){ |
1054
|
|
|
$this->Error('Unable to create output file: '.$name); |
1055
|
|
|
|
1056
|
|
|
return null; |
1057
|
|
|
} |
1058
|
|
|
fwrite($f,$this->buffer,strlen($this->buffer)); |
1059
|
|
|
fclose($f); |
1060
|
|
|
break; |
1061
|
|
|
case 'S': |
1062
|
|
|
//Return as a string |
1063
|
|
|
return $this->buffer; |
1064
|
|
|
default: |
1065
|
|
|
$this->Error('Incorrect output destination: '.$dest); |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
return ''; |
1069
|
|
|
} |
1070
|
|
|
|
1071
|
|
|
/******************************************************************************* |
1072
|
|
|
* * |
1073
|
|
|
* Protected methods * |
1074
|
|
|
* * |
1075
|
|
|
*******************************************************************************/ |
1076
|
|
|
function _dochecks() |
|
|
|
|
1077
|
|
|
{ |
1078
|
|
|
//Check for locale-related bug |
1079
|
|
|
if(1.1==1) |
1080
|
|
|
$this->Error('Don\'t alter the locale before including class file'); |
1081
|
|
|
//Check for decimal separator |
1082
|
|
|
if(sprintf('%.1f',1.0)!='1.0') |
1083
|
|
|
setlocale(LC_NUMERIC,'C'); |
1084
|
|
|
} |
1085
|
|
|
|
1086
|
|
|
function _getfontpath() |
|
|
|
|
1087
|
|
|
{ |
1088
|
|
|
if(!defined('FPDF_FONTPATH') && is_dir(__DIR__.'/font')) |
1089
|
|
|
define('FPDF_FONTPATH',__DIR__.'/font/'); |
1090
|
|
|
|
1091
|
|
|
return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; |
1092
|
|
|
} |
1093
|
|
|
|
1094
|
|
|
function _putpages() |
|
|
|
|
1095
|
|
|
{ |
1096
|
|
|
$nb=$this->page; |
1097
|
|
|
if(!empty($this->AliasNbPages)) |
1098
|
|
|
{ |
1099
|
|
|
//Replace number of pages |
1100
|
|
|
for($n=1;$n<=$nb;$n++) |
1101
|
|
|
$this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]); |
1102
|
|
|
} |
1103
|
|
|
if($this->DefOrientation=='P') |
1104
|
|
|
{ |
1105
|
|
|
$wPt=$this->fwPt; |
1106
|
|
|
$hPt=$this->fhPt; |
1107
|
|
|
} |
1108
|
|
|
else |
1109
|
|
|
{ |
1110
|
|
|
$wPt=$this->fhPt; |
1111
|
|
|
$hPt=$this->fwPt; |
1112
|
|
|
} |
1113
|
|
|
$filter= $this->compress ? '/Filter /FlateDecode ' : ''; |
1114
|
|
|
for($n=1;$n<=$nb;$n++) |
1115
|
|
|
{ |
1116
|
|
|
//Page |
1117
|
|
|
$this->_newobj(); |
1118
|
|
|
$this->_out('<</Type /Page'); |
1119
|
|
|
$this->_out('/Parent 1 0 R'); |
1120
|
|
|
if(isset($this->OrientationChanges[$n])) |
1121
|
|
|
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt)); |
1122
|
|
|
$this->_out('/Resources 2 0 R'); |
1123
|
|
|
if(isset($this->PageLinks[$n])) |
1124
|
|
|
{ |
1125
|
|
|
//Links |
1126
|
|
|
$annots='/Annots ['; |
1127
|
|
|
foreach($this->PageLinks[$n] as $pl) |
1128
|
|
|
{ |
1129
|
|
|
$rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); |
1130
|
|
|
$annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; |
1131
|
|
|
if(is_string($pl[4])) |
1132
|
|
|
$annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; |
1133
|
|
|
else |
1134
|
|
|
{ |
1135
|
|
|
$l=$this->links[$pl[4]]; |
1136
|
|
|
$h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; |
1137
|
|
|
$annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k); |
1138
|
|
|
} |
1139
|
|
|
} |
1140
|
|
|
$this->_out($annots.']'); |
1141
|
|
|
} |
1142
|
|
|
$this->_out('/Contents '.($this->n+1).' 0 R>>'); |
1143
|
|
|
$this->_out('endobj'); |
1144
|
|
|
//Page content |
1145
|
|
|
$p= $this->compress ? gzcompress($this->pages[$n]) : $this->pages[$n]; |
1146
|
|
|
$this->_newobj(); |
1147
|
|
|
$this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); |
1148
|
|
|
$this->_putstream($p); |
1149
|
|
|
$this->_out('endobj'); |
1150
|
|
|
} |
1151
|
|
|
//Pages root |
1152
|
|
|
$this->offsets[1]=strlen($this->buffer); |
1153
|
|
|
$this->_out('1 0 obj'); |
1154
|
|
|
$this->_out('<</Type /Pages'); |
1155
|
|
|
$kids='/Kids ['; |
1156
|
|
|
for($i=0;$i<$nb;$i++) |
1157
|
|
|
$kids.=(3+2*$i).' 0 R '; |
1158
|
|
|
$this->_out($kids.']'); |
1159
|
|
|
$this->_out('/Count '.$nb); |
1160
|
|
|
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); |
1161
|
|
|
$this->_out('>>'); |
1162
|
|
|
$this->_out('endobj'); |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
function _putfonts() |
|
|
|
|
1166
|
|
|
{ |
1167
|
|
|
$nf=$this->n; |
1168
|
|
|
foreach($this->diffs as $diff) |
1169
|
|
|
{ |
1170
|
|
|
//Encodings |
1171
|
|
|
$this->_newobj(); |
1172
|
|
|
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); |
1173
|
|
|
$this->_out('endobj'); |
1174
|
|
|
} |
1175
|
|
|
$mqr=get_magic_quotes_runtime(); |
1176
|
|
|
set_magic_quotes_runtime(0); |
1177
|
|
|
foreach($this->FontFiles as $file=>$info) |
1178
|
|
|
{ |
1179
|
|
|
//Font file embedding |
1180
|
|
|
$this->_newobj(); |
1181
|
|
|
$this->FontFiles[$file]['n']=$this->n; |
1182
|
|
|
$font=''; |
1183
|
|
|
$f=fopen($this->_getfontpath().$file,'rb',1); |
1184
|
|
|
if(!$f) |
1185
|
|
|
$this->Error('Font file not found'); |
1186
|
|
|
while(!feof($f)) |
1187
|
|
|
$font.=fread($f,8192); |
1188
|
|
|
fclose($f); |
1189
|
|
|
$compressed=(substr($file,-2)=='.z'); |
1190
|
|
|
if(!$compressed && isset($info['length2'])) |
1191
|
|
|
{ |
1192
|
|
|
$header=(ord($font{0})==128); |
1193
|
|
|
if($header) |
1194
|
|
|
{ |
1195
|
|
|
//Strip first binary header |
1196
|
|
|
$font=substr($font,6); |
1197
|
|
|
} |
1198
|
|
|
if($header && ord($font{$info['length1']})==128) |
1199
|
|
|
{ |
1200
|
|
|
//Strip second binary header |
1201
|
|
|
$font=substr($font,0,$info['length1']).substr($font,$info['length1']+6); |
1202
|
|
|
} |
1203
|
|
|
} |
1204
|
|
|
$this->_out('<</Length '.strlen($font)); |
1205
|
|
|
if($compressed) |
1206
|
|
|
$this->_out('/Filter /FlateDecode'); |
1207
|
|
|
$this->_out('/Length1 '.$info['length1']); |
1208
|
|
|
if(isset($info['length2'])) |
1209
|
|
|
$this->_out('/Length2 '.$info['length2'].' /Length3 0'); |
1210
|
|
|
$this->_out('>>'); |
1211
|
|
|
$this->_putstream($font); |
1212
|
|
|
$this->_out('endobj'); |
1213
|
|
|
} |
1214
|
|
|
set_magic_quotes_runtime($mqr); |
1215
|
|
|
foreach($this->fonts as $k=>$font) |
1216
|
|
|
{ |
1217
|
|
|
//Font objects |
1218
|
|
|
$this->fonts[$k]['n']=$this->n+1; |
1219
|
|
|
$type=$font['type']; |
1220
|
|
|
$name=$font['name']; |
1221
|
|
|
if($type=='core') |
1222
|
|
|
{ |
1223
|
|
|
//Standard font |
1224
|
|
|
$this->_newobj(); |
1225
|
|
|
$this->_out('<</Type /Font'); |
1226
|
|
|
$this->_out('/BaseFont /'.$name); |
1227
|
|
|
$this->_out('/Subtype /Type1'); |
1228
|
|
|
if($name!='Symbol' && $name!='ZapfDingbats') |
1229
|
|
|
$this->_out('/Encoding /WinAnsiEncoding'); |
1230
|
|
|
$this->_out('>>'); |
1231
|
|
|
$this->_out('endobj'); |
1232
|
|
|
} |
1233
|
|
|
elseif($type=='Type1' || $type=='TrueType') |
1234
|
|
|
{ |
1235
|
|
|
//Additional Type1 or TrueType font |
1236
|
|
|
$this->_newobj(); |
1237
|
|
|
$this->_out('<</Type /Font'); |
1238
|
|
|
$this->_out('/BaseFont /'.$name); |
1239
|
|
|
$this->_out('/Subtype /'.$type); |
1240
|
|
|
$this->_out('/FirstChar 32 /LastChar 255'); |
1241
|
|
|
$this->_out('/Widths '.($this->n+1).' 0 R'); |
1242
|
|
|
$this->_out('/FontDescriptor '.($this->n+2).' 0 R'); |
1243
|
|
|
if($font['enc']) |
1244
|
|
|
{ |
1245
|
|
|
if(isset($font['diff'])) |
1246
|
|
|
$this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); |
1247
|
|
|
else |
1248
|
|
|
$this->_out('/Encoding /WinAnsiEncoding'); |
1249
|
|
|
} |
1250
|
|
|
$this->_out('>>'); |
1251
|
|
|
$this->_out('endobj'); |
1252
|
|
|
//Widths |
1253
|
|
|
$this->_newobj(); |
1254
|
|
|
$cw=&$font['cw']; |
1255
|
|
|
$s='['; |
1256
|
|
|
for($i=32;$i<=255;$i++) |
1257
|
|
|
$s.=$cw[chr($i)].' '; |
1258
|
|
|
$this->_out($s.']'); |
1259
|
|
|
$this->_out('endobj'); |
1260
|
|
|
//Descriptor |
1261
|
|
|
$this->_newobj(); |
1262
|
|
|
$s='<</Type /FontDescriptor /FontName /'.$name; |
1263
|
|
|
foreach($font['desc'] as $k=>$v) |
1264
|
|
|
$s.=' /'.$k.' '.$v; |
1265
|
|
|
$file=$font['file']; |
1266
|
|
|
if($file) |
1267
|
|
|
$s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; |
1268
|
|
|
$this->_out($s.'>>'); |
1269
|
|
|
$this->_out('endobj'); |
1270
|
|
|
} |
1271
|
|
|
else |
1272
|
|
|
{ |
1273
|
|
|
//Allow for additional types |
1274
|
|
|
$mtd='_put'.strtolower($type); |
1275
|
|
|
if(!method_exists($this,$mtd)) |
1276
|
|
|
$this->Error('Unsupported font type: '.$type); |
1277
|
|
|
$this->$mtd($font); |
1278
|
|
|
} |
1279
|
|
|
} |
1280
|
|
|
} |
1281
|
|
|
|
1282
|
|
|
function _putimages() |
|
|
|
|
1283
|
|
|
{ |
1284
|
|
|
$filter= $this->compress ? '/Filter /FlateDecode ' : ''; |
1285
|
|
|
reset($this->images); |
1286
|
|
|
while(list($file,$info)=each($this->images)) |
1287
|
|
|
{ |
1288
|
|
|
$this->_newobj(); |
1289
|
|
|
$this->images[$file]['n']=$this->n; |
1290
|
|
|
$this->_out('<</Type /XObject'); |
1291
|
|
|
$this->_out('/Subtype /Image'); |
1292
|
|
|
$this->_out('/Width '.$info['w']); |
1293
|
|
|
$this->_out('/Height '.$info['h']); |
1294
|
|
|
if($info['cs']=='Indexed') |
1295
|
|
|
$this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); |
1296
|
|
|
else |
1297
|
|
|
{ |
1298
|
|
|
$this->_out('/ColorSpace /'.$info['cs']); |
1299
|
|
|
if($info['cs']=='DeviceCMYK') |
1300
|
|
|
$this->_out('/Decode [1 0 1 0 1 0 1 0]'); |
1301
|
|
|
} |
1302
|
|
|
$this->_out('/BitsPerComponent '.$info['bpc']); |
1303
|
|
|
if(isset($info['f'])) |
1304
|
|
|
$this->_out('/Filter /'.$info['f']); |
1305
|
|
|
if(isset($info['parms'])) |
1306
|
|
|
$this->_out($info['parms']); |
1307
|
|
|
if(isset($info['trns']) && is_array($info['trns'])) |
1308
|
|
|
{ |
1309
|
|
|
$trns=''; |
1310
|
|
|
for($i=0;$i<count($info['trns']);$i++) |
|
|
|
|
1311
|
|
|
$trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; |
1312
|
|
|
$this->_out('/Mask ['.$trns.']'); |
1313
|
|
|
} |
1314
|
|
|
$this->_out('/Length '.strlen($info['data']).'>>'); |
1315
|
|
|
$this->_putstream($info['data']); |
1316
|
|
|
unset($this->images[$file]['data']); |
1317
|
|
|
$this->_out('endobj'); |
1318
|
|
|
//Palette |
1319
|
|
|
if($info['cs']=='Indexed') |
1320
|
|
|
{ |
1321
|
|
|
$this->_newobj(); |
1322
|
|
|
$pal= $this->compress ? gzcompress($info['pal']) : $info['pal']; |
1323
|
|
|
$this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); |
1324
|
|
|
$this->_putstream($pal); |
1325
|
|
|
$this->_out('endobj'); |
1326
|
|
|
} |
1327
|
|
|
} |
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
function _putxobjectdict() |
|
|
|
|
1331
|
|
|
{ |
1332
|
|
|
foreach($this->images as $image) |
1333
|
|
|
$this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); |
1334
|
|
|
} |
1335
|
|
|
|
1336
|
|
|
function _putresourcedict() |
|
|
|
|
1337
|
|
|
{ |
1338
|
|
|
$this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); |
1339
|
|
|
$this->_out('/Font <<'); |
1340
|
|
|
foreach($this->fonts as $font) |
1341
|
|
|
$this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); |
1342
|
|
|
$this->_out('>>'); |
1343
|
|
|
$this->_out('/XObject <<'); |
1344
|
|
|
$this->_putxobjectdict(); |
1345
|
|
|
$this->_out('>>'); |
1346
|
|
|
} |
1347
|
|
|
|
1348
|
|
|
function _putresources() |
|
|
|
|
1349
|
|
|
{ |
1350
|
|
|
$this->_putfonts(); |
1351
|
|
|
$this->_putimages(); |
1352
|
|
|
//Resource dictionary |
1353
|
|
|
$this->offsets[2]=strlen($this->buffer); |
1354
|
|
|
$this->_out('2 0 obj'); |
1355
|
|
|
$this->_out('<<'); |
1356
|
|
|
$this->_putresourcedict(); |
1357
|
|
|
$this->_out('>>'); |
1358
|
|
|
$this->_out('endobj'); |
1359
|
|
|
} |
1360
|
|
|
|
1361
|
|
|
function _putinfo() |
|
|
|
|
1362
|
|
|
{ |
1363
|
|
|
$this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); |
1364
|
|
|
if(!empty($this->title)) |
1365
|
|
|
$this->_out('/Title '.$this->_textstring($this->title)); |
1366
|
|
|
if(!empty($this->subject)) |
1367
|
|
|
$this->_out('/Subject '.$this->_textstring($this->subject)); |
1368
|
|
|
if(!empty($this->author)) |
1369
|
|
|
$this->_out('/Author '.$this->_textstring($this->author)); |
1370
|
|
|
if(!empty($this->keywords)) |
1371
|
|
|
$this->_out('/Keywords '.$this->_textstring($this->keywords)); |
1372
|
|
|
if(!empty($this->creator)) |
1373
|
|
|
$this->_out('/Creator '.$this->_textstring($this->creator)); |
1374
|
|
|
$this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); |
1375
|
|
|
} |
1376
|
|
|
|
1377
|
|
|
function _putcatalog() |
|
|
|
|
1378
|
|
|
{ |
1379
|
|
|
$this->_out('/Type /Catalog'); |
1380
|
|
|
$this->_out('/Pages 1 0 R'); |
1381
|
|
|
if($this->ZoomMode=='fullpage') |
1382
|
|
|
$this->_out('/OpenAction [3 0 R /Fit]'); |
1383
|
|
|
elseif($this->ZoomMode=='fullwidth') |
1384
|
|
|
$this->_out('/OpenAction [3 0 R /FitH null]'); |
1385
|
|
|
elseif($this->ZoomMode=='real') |
1386
|
|
|
$this->_out('/OpenAction [3 0 R /XYZ null null 1]'); |
1387
|
|
|
elseif(!is_string($this->ZoomMode)) |
1388
|
|
|
$this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); |
1389
|
|
|
if($this->LayoutMode=='single') |
1390
|
|
|
$this->_out('/PageLayout /SinglePage'); |
1391
|
|
|
elseif($this->LayoutMode=='continuous') |
1392
|
|
|
$this->_out('/PageLayout /OneColumn'); |
1393
|
|
|
elseif($this->LayoutMode=='two') |
1394
|
|
|
$this->_out('/PageLayout /TwoColumnLeft'); |
1395
|
|
|
} |
1396
|
|
|
|
1397
|
|
|
function _putheader() |
|
|
|
|
1398
|
|
|
{ |
1399
|
|
|
$this->_out('%PDF-'.$this->PDFVersion); |
1400
|
|
|
} |
1401
|
|
|
|
1402
|
|
|
function _puttrailer() |
|
|
|
|
1403
|
|
|
{ |
1404
|
|
|
$this->_out('/Size '.($this->n+1)); |
1405
|
|
|
$this->_out('/Root '.$this->n.' 0 R'); |
1406
|
|
|
$this->_out('/Info '.($this->n-1).' 0 R'); |
1407
|
|
|
} |
1408
|
|
|
|
1409
|
|
|
function _enddoc() |
|
|
|
|
1410
|
|
|
{ |
1411
|
|
|
$this->_putheader(); |
1412
|
|
|
$this->_putpages(); |
1413
|
|
|
$this->_putresources(); |
1414
|
|
|
//Info |
1415
|
|
|
$this->_newobj(); |
1416
|
|
|
$this->_out('<<'); |
1417
|
|
|
$this->_putinfo(); |
1418
|
|
|
$this->_out('>>'); |
1419
|
|
|
$this->_out('endobj'); |
1420
|
|
|
//Catalog |
1421
|
|
|
$this->_newobj(); |
1422
|
|
|
$this->_out('<<'); |
1423
|
|
|
$this->_putcatalog(); |
1424
|
|
|
$this->_out('>>'); |
1425
|
|
|
$this->_out('endobj'); |
1426
|
|
|
//Cross-ref |
1427
|
|
|
$o=strlen($this->buffer); |
1428
|
|
|
$this->_out('xref'); |
1429
|
|
|
$this->_out('0 '.($this->n+1)); |
1430
|
|
|
$this->_out('0000000000 65535 f '); |
1431
|
|
|
for($i=1;$i<=$this->n;$i++) |
1432
|
|
|
$this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); |
1433
|
|
|
//Trailer |
1434
|
|
|
$this->_out('trailer'); |
1435
|
|
|
$this->_out('<<'); |
1436
|
|
|
$this->_puttrailer(); |
1437
|
|
|
$this->_out('>>'); |
1438
|
|
|
$this->_out('startxref'); |
1439
|
|
|
$this->_out($o); |
1440
|
|
|
$this->_out('%%EOF'); |
1441
|
|
|
$this->state=3; |
1442
|
|
|
} |
1443
|
|
|
|
1444
|
|
|
function _beginpage($orientation) |
|
|
|
|
1445
|
|
|
{ |
1446
|
|
|
$this->page++; |
1447
|
|
|
$this->pages[$this->page]=''; |
1448
|
|
|
$this->state=2; |
1449
|
|
|
$this->x=$this->lMargin; |
1450
|
|
|
$this->y=$this->tMargin; |
1451
|
|
|
$this->FontFamily=''; |
1452
|
|
|
//Page orientation |
1453
|
|
|
if(!$orientation) |
1454
|
|
|
$orientation=$this->DefOrientation; |
1455
|
|
|
else |
1456
|
|
|
{ |
1457
|
|
|
$orientation=strtoupper($orientation{0}); |
1458
|
|
|
if($orientation!=$this->DefOrientation) |
1459
|
|
|
$this->OrientationChanges[$this->page]=true; |
1460
|
|
|
} |
1461
|
|
|
if($orientation!=$this->CurOrientation) |
1462
|
|
|
{ |
1463
|
|
|
//Change orientation |
1464
|
|
|
if($orientation=='P') |
1465
|
|
|
{ |
1466
|
|
|
$this->wPt=$this->fwPt; |
1467
|
|
|
$this->hPt=$this->fhPt; |
1468
|
|
|
$this->w=$this->fw; |
1469
|
|
|
$this->h=$this->fh; |
1470
|
|
|
} |
1471
|
|
|
else |
1472
|
|
|
{ |
1473
|
|
|
$this->wPt=$this->fhPt; |
1474
|
|
|
$this->hPt=$this->fwPt; |
1475
|
|
|
$this->w=$this->fh; |
1476
|
|
|
$this->h=$this->fw; |
1477
|
|
|
} |
1478
|
|
|
$this->PageBreakTrigger=$this->h-$this->bMargin; |
1479
|
|
|
$this->CurOrientation=$orientation; |
1480
|
|
|
} |
1481
|
|
|
} |
1482
|
|
|
|
1483
|
|
|
function _endpage() |
|
|
|
|
1484
|
|
|
{ |
1485
|
|
|
//End of page contents |
1486
|
|
|
$this->state=1; |
1487
|
|
|
} |
1488
|
|
|
|
1489
|
|
|
function _newobj() |
|
|
|
|
1490
|
|
|
{ |
1491
|
|
|
//Begin a new object |
1492
|
|
|
$this->n++; |
1493
|
|
|
$this->offsets[$this->n]=strlen($this->buffer); |
1494
|
|
|
$this->_out($this->n.' 0 obj'); |
1495
|
|
|
} |
1496
|
|
|
|
1497
|
|
|
function _dounderline($x,$y,$txt) |
|
|
|
|
1498
|
|
|
{ |
1499
|
|
|
//Underline text |
1500
|
|
|
$up=$this->CurrentFont['up']; |
1501
|
|
|
$ut=$this->CurrentFont['ut']; |
1502
|
|
|
$w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); |
1503
|
|
|
|
1504
|
|
|
return sprintf('%.2f %.2f %.2f %.2f re f',$x*$this->k,($this->h-($y-$up/1000*$this->FontSize))*$this->k,$w*$this->k,-$ut/1000*$this->FontSizePt); |
1505
|
|
|
} |
1506
|
|
|
|
1507
|
|
|
function _parsejpg($file) |
|
|
|
|
1508
|
|
|
{ |
1509
|
|
|
//Extract info from a JPEG file |
1510
|
|
|
$a=GetImageSize($file); |
1511
|
|
|
if(!$a) |
|
|
|
|
1512
|
|
|
$this->Error('Missing or incorrect image file: '.$file); |
1513
|
|
|
if($a[2]!=2) |
1514
|
|
|
$this->Error('Not a JPEG file: '.$file); |
1515
|
|
|
if(!isset($a['channels']) || $a['channels']==3) |
1516
|
|
|
$colspace='DeviceRGB'; |
1517
|
|
|
elseif($a['channels']==4) |
1518
|
|
|
$colspace='DeviceCMYK'; |
1519
|
|
|
else |
1520
|
|
|
$colspace='DeviceGray'; |
1521
|
|
|
$bpc=isset($a['bits']) ? $a['bits'] : 8; |
1522
|
|
|
//Read whole file |
1523
|
|
|
$f=fopen($file,'rb'); |
1524
|
|
|
$data=''; |
1525
|
|
|
while(!feof($f)) |
1526
|
|
|
$data.=fread($f,4096); |
1527
|
|
|
fclose($f); |
1528
|
|
|
|
1529
|
|
|
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); |
1530
|
|
|
} |
1531
|
|
|
|
1532
|
|
|
function _parsepng($file) |
|
|
|
|
1533
|
|
|
{ |
1534
|
|
|
//Extract info from a PNG file |
1535
|
|
|
$f=fopen($file,'rb'); |
1536
|
|
|
if(!$f) |
1537
|
|
|
$this->Error('Can\'t open image file: '.$file); |
1538
|
|
|
//Check signature |
1539
|
|
|
if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) |
1540
|
|
|
$this->Error('Not a PNG file: '.$file); |
1541
|
|
|
//Read header chunk |
1542
|
|
|
fread($f,4); |
1543
|
|
|
if(fread($f,4)!='IHDR') |
1544
|
|
|
$this->Error('Incorrect PNG file: '.$file); |
1545
|
|
|
$w=$this->_freadint($f); |
1546
|
|
|
$h=$this->_freadint($f); |
1547
|
|
|
$bpc=ord(fread($f,1)); |
1548
|
|
|
if($bpc>8) |
1549
|
|
|
$this->Error('16-bit depth not supported: '.$file); |
1550
|
|
|
$ct=ord(fread($f,1)); |
1551
|
|
|
if($ct==0) |
1552
|
|
|
$colspace='DeviceGray'; |
1553
|
|
|
elseif($ct==2) |
1554
|
|
|
$colspace='DeviceRGB'; |
1555
|
|
|
elseif($ct==3) |
1556
|
|
|
$colspace='Indexed'; |
1557
|
|
|
else |
1558
|
|
|
$this->Error('Alpha channel not supported: '.$file); |
1559
|
|
|
if(ord(fread($f,1))!=0) |
1560
|
|
|
$this->Error('Unknown compression method: '.$file); |
1561
|
|
|
if(ord(fread($f,1))!=0) |
1562
|
|
|
$this->Error('Unknown filter method: '.$file); |
1563
|
|
|
if(ord(fread($f,1))!=0) |
1564
|
|
|
$this->Error('Interlacing not supported: '.$file); |
1565
|
|
|
fread($f,4); |
1566
|
|
|
$parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; |
1567
|
|
|
//Scan chunks looking for palette, transparency and image data |
1568
|
|
|
$pal=''; |
1569
|
|
|
$trns=''; |
1570
|
|
|
$data=''; |
1571
|
|
|
do |
1572
|
|
|
{ |
1573
|
|
|
$n=$this->_freadint($f); |
1574
|
|
|
$type=fread($f,4); |
1575
|
|
|
if($type=='PLTE') |
1576
|
|
|
{ |
1577
|
|
|
//Read palette |
1578
|
|
|
$pal=fread($f,$n); |
1579
|
|
|
fread($f,4); |
1580
|
|
|
} |
1581
|
|
|
elseif($type=='tRNS') |
1582
|
|
|
{ |
1583
|
|
|
//Read transparency info |
1584
|
|
|
$t=fread($f,$n); |
1585
|
|
|
if($ct==0) |
1586
|
|
|
$trns=array(ord(substr($t,1,1))); |
1587
|
|
|
elseif($ct==2) |
1588
|
|
|
$trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); |
1589
|
|
|
else |
1590
|
|
|
{ |
1591
|
|
|
$pos=strpos($t,chr(0)); |
1592
|
|
|
if($pos!==false) |
1593
|
|
|
$trns=array($pos); |
1594
|
|
|
} |
1595
|
|
|
fread($f,4); |
1596
|
|
|
} |
1597
|
|
|
elseif($type=='IDAT') |
1598
|
|
|
{ |
1599
|
|
|
//Read image data block |
1600
|
|
|
$data.=fread($f,$n); |
1601
|
|
|
fread($f,4); |
1602
|
|
|
} |
1603
|
|
|
elseif($type=='IEND') |
1604
|
|
|
break; |
1605
|
|
|
else |
1606
|
|
|
fread($f,$n+4); |
1607
|
|
|
} |
1608
|
|
|
while($n); |
1609
|
|
|
if($colspace=='Indexed' && empty($pal)) |
|
|
|
|
1610
|
|
|
$this->Error('Missing palette in '.$file); |
1611
|
|
|
fclose($f); |
1612
|
|
|
|
1613
|
|
|
return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); |
1614
|
|
|
} |
1615
|
|
|
|
1616
|
|
|
function _freadint($f) |
|
|
|
|
1617
|
|
|
{ |
1618
|
|
|
//Read a 4-byte integer from file |
1619
|
|
|
$a=unpack('Ni',fread($f,4)); |
1620
|
|
|
|
1621
|
|
|
return $a['i']; |
1622
|
|
|
} |
1623
|
|
|
|
1624
|
|
|
function _textstring($s) |
|
|
|
|
1625
|
|
|
{ |
1626
|
|
|
//Format a text string |
1627
|
|
|
return '('.$this->_escape($s).')'; |
1628
|
|
|
} |
1629
|
|
|
|
1630
|
|
|
function _escape($s) |
|
|
|
|
1631
|
|
|
{ |
1632
|
|
|
//Add \ before \, ( and ) |
1633
|
|
|
return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); |
1634
|
|
|
} |
1635
|
|
|
|
1636
|
|
|
function _putstream($s) |
|
|
|
|
1637
|
|
|
{ |
1638
|
|
|
$this->_out('stream'); |
1639
|
|
|
$this->_out($s); |
1640
|
|
|
$this->_out('endstream'); |
1641
|
|
|
} |
1642
|
|
|
|
1643
|
|
|
function _out($s) |
|
|
|
|
1644
|
|
|
{ |
1645
|
|
|
//Add a line to the document |
1646
|
|
|
if($this->state==2) |
1647
|
|
|
$this->pages[$this->page].=$s."\n"; |
1648
|
|
|
else |
1649
|
|
|
$this->buffer.=$s."\n"; |
1650
|
|
|
} |
1651
|
|
|
//End of class |
1652
|
|
|
} |
1653
|
|
|
|
1654
|
|
|
//Handle special IE contype request |
1655
|
|
|
if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') |
1656
|
|
|
{ |
1657
|
|
|
header('Content-Type: application/pdf'); |
1658
|
|
|
exit; |
1659
|
|
|
} |
1660
|
|
|
|
1661
|
|
|
} |
1662
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.