2 /*******************************************************************************
7 * Author: Olivier PLATHEY *
8 *******************************************************************************/
10 define('FPDF_VERSION','1.81');
14 protected $page; // current page number
15 protected $n; // current object number
16 protected $offsets; // array of object offsets
17 protected $buffer; // buffer holding in-memory PDF
18 protected $pages; // array containing pages
19 protected $state; // current document state
20 protected $compress; // compression flag
21 var $k; // scale factor (number of points in user unit)
22 protected $DefOrientation; // default orientation
23 protected $CurOrientation; // current orientation
24 protected $StdPageSizes; // standard page sizes
25 protected $DefPageSize; // default page size
26 protected $CurPageSize; // current page size
27 protected $CurRotation; // current page rotation
28 protected $PageInfo; // page-related data
29 protected $wPt, $hPt; // dimensions of current page in points
30 var $w, $h; // dimensions of current page in user unit
31 protected $lMargin; // left margin
32 protected $tMargin; // top margin
33 protected $rMargin; // right margin
34 protected $bMargin; // page break margin
35 protected $cMargin; // cell margin
36 protected $x, $y; // current position in user unit
37 protected $lasth; // height of last printed cell
38 protected $LineWidth; // line width in user unit
39 protected $fontpath; // path containing fonts
40 protected $CoreFonts; // array of core font names
41 protected $fonts; // array of used fonts
42 protected $FontFiles; // array of font files
43 protected $encodings; // array of encodings
44 protected $cmaps; // array of ToUnicode CMaps
45 protected $FontFamily; // current font family
46 protected $FontStyle; // current font style
47 protected $underline; // underlining flag
48 protected $CurrentFont; // current font info
49 protected $FontSizePt; // current font size in points
50 protected $FontSize; // current font size in user unit
51 protected $DrawColor; // commands for drawing color
52 protected $FillColor; // commands for filling color
53 protected $TextColor; // commands for text color
54 protected $ColorFlag; // indicates whether fill and text colors are different
55 protected $WithAlpha; // indicates whether alpha channel is used
56 protected $ws; // word spacing
57 protected $images; // array of used images
58 protected $PageLinks; // array of links in pages
59 protected $links; // array of internal links
60 protected $AutoPageBreak; // automatic page breaking
61 protected $PageBreakTrigger; // threshold used to trigger page breaks
62 protected $InHeader; // flag set when processing header
63 protected $InFooter; // flag set when processing footer
64 protected $AliasNbPages; // alias for total number of pages
65 protected $ZoomMode; // zoom display mode
66 protected $LayoutMode; // layout display mode
67 protected $metadata; // document properties
68 protected $PDFVersion; // PDF version number
70 /*******************************************************************************
72 *******************************************************************************/
74 function __construct($orientation='P', $unit='mm', $size='A4')
78 // Initialization of properties
83 $this->pages
= array();
84 $this->PageInfo
= array();
85 $this->fonts
= array();
86 $this->FontFiles
= array();
87 $this->encodings
= array();
88 $this->cmaps
= array();
89 $this->images
= array();
90 $this->links
= array();
91 $this->InHeader
= false;
92 $this->InFooter
= false;
94 $this->FontFamily
= '';
95 $this->FontStyle
= '';
96 $this->FontSizePt
= 12;
97 $this->underline
= false;
98 $this->DrawColor
= '0 G';
99 $this->FillColor
= '0 g';
100 $this->TextColor
= '0 g';
101 $this->ColorFlag
= false;
102 $this->WithAlpha
= false;
105 if(defined('FPDF_FONTPATH'))
107 $this->fontpath
= FPDF_FONTPATH
;
108 if(substr($this->fontpath
,-1)!='/' && substr($this->fontpath
,-1)!='\\')
109 $this->fontpath
.= '/';
111 elseif(is_dir(dirname(__FILE__
).'/font'))
112 $this->fontpath
= dirname(__FILE__
).'/font/';
114 $this->fontpath
= '';
116 $this->CoreFonts
= array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
127 $this->Error('Incorrect unit: '.$unit);
129 $this->StdPageSizes
= array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
130 'letter'=>array(612,792), 'legal'=>array(612,1008));
131 $size = $this->_getpagesize($size);
132 $this->DefPageSize
= $size;
133 $this->CurPageSize
= $size;
135 $orientation = strtolower($orientation);
136 if($orientation=='p' ||
$orientation=='portrait')
138 $this->DefOrientation
= 'P';
142 elseif($orientation=='l' ||
$orientation=='landscape')
144 $this->DefOrientation
= 'L';
149 $this->Error('Incorrect orientation: '.$orientation);
150 $this->CurOrientation
= $this->DefOrientation
;
151 $this->wPt
= $this->w
*$this->k
;
152 $this->hPt
= $this->h
*$this->k
;
154 $this->CurRotation
= 0;
155 // Page margins (1 cm)
156 $margin = 28.35/$this->k
;
157 $this->SetMargins($margin,$margin);
158 // Interior cell margin (1 mm)
159 $this->cMargin
= $margin/10;
160 // Line width (0.2 mm)
161 $this->LineWidth
= .567/$this->k
;
162 // Automatic page break
163 $this->SetAutoPageBreak(true,2*$margin);
164 // Default display mode
165 $this->SetDisplayMode('default');
166 // Enable compression
167 $this->SetCompression(true);
168 // Set default PDF version number
169 $this->PDFVersion
= '1.3';
172 function SetMargins($left, $top, $right=null)
174 // Set left, top and right margins
175 $this->lMargin
= $left;
176 $this->tMargin
= $top;
179 $this->rMargin
= $right;
182 function SetLeftMargin($margin)
185 $this->lMargin
= $margin;
186 if($this->page
>0 && $this->x
<$margin)
190 function SetTopMargin($margin)
193 $this->tMargin
= $margin;
196 function SetRightMargin($margin)
199 $this->rMargin
= $margin;
202 function SetAutoPageBreak($auto, $margin=0)
204 // Set auto page break mode and triggering margin
205 $this->AutoPageBreak
= $auto;
206 $this->bMargin
= $margin;
207 $this->PageBreakTrigger
= $this->h
-$margin;
210 function SetDisplayMode($zoom, $layout='default')
212 // Set display mode in viewer
213 if($zoom=='fullpage' ||
$zoom=='fullwidth' ||
$zoom=='real' ||
$zoom=='default' ||
!is_string($zoom))
214 $this->ZoomMode
= $zoom;
216 $this->Error('Incorrect zoom display mode: '.$zoom);
217 if($layout=='single' ||
$layout=='continuous' ||
$layout=='two' ||
$layout=='default')
218 $this->LayoutMode
= $layout;
220 $this->Error('Incorrect layout display mode: '.$layout);
223 function SetCompression($compress)
225 // Set page compression
226 if(function_exists('gzcompress'))
227 $this->compress
= $compress;
229 $this->compress
= false;
232 function SetTitle($title, $isUTF8=false)
235 $this->metadata
['Title'] = $isUTF8 ?
$title : utf8_encode($title);
238 function SetAuthor($author, $isUTF8=false)
240 // Author of document
241 $this->metadata
['Author'] = $isUTF8 ?
$author : utf8_encode($author);
244 function SetSubject($subject, $isUTF8=false)
246 // Subject of document
247 $this->metadata
['Subject'] = $isUTF8 ?
$subject : utf8_encode($subject);
250 function SetKeywords($keywords, $isUTF8=false)
252 // Keywords of document
253 $this->metadata
['Keywords'] = $isUTF8 ?
$keywords : utf8_encode($keywords);
256 function SetCreator($creator, $isUTF8=false)
258 // Creator of document
259 $this->metadata
['Creator'] = $isUTF8 ?
$creator : utf8_encode($creator);
262 function AliasNbPages($alias='{nb}')
264 // Define an alias for total number of pages
265 $this->AliasNbPages
= $alias;
271 throw new Exception('FPDF error: '.$msg);
276 // Terminate document
282 $this->InFooter
= true;
284 $this->InFooter
= false;
291 function AddPage($orientation='', $size='', $rotation=0)
295 $this->Error('The document is closed');
296 $family = $this->FontFamily
;
297 $style = $this->FontStyle
.($this->underline ?
'U' : '');
298 $fontsize = $this->FontSizePt
;
299 $lw = $this->LineWidth
;
300 $dc = $this->DrawColor
;
301 $fc = $this->FillColor
;
302 $tc = $this->TextColor
;
303 $cf = $this->ColorFlag
;
307 $this->InFooter
= true;
309 $this->InFooter
= false;
314 $this->_beginpage($orientation,$size,$rotation);
315 // Set line cap style to square
318 $this->LineWidth
= $lw;
319 $this->_out(sprintf('%.2F w',$lw*$this->k
));
322 $this->SetFont($family,$style,$fontsize);
324 $this->DrawColor
= $dc;
327 $this->FillColor
= $fc;
330 $this->TextColor
= $tc;
331 $this->ColorFlag
= $cf;
333 $this->InHeader
= true;
335 $this->InHeader
= false;
336 // Restore line width
337 if($this->LineWidth
!=$lw)
339 $this->LineWidth
= $lw;
340 $this->_out(sprintf('%.2F w',$lw*$this->k
));
344 $this->SetFont($family,$style,$fontsize);
346 if($this->DrawColor
!=$dc)
348 $this->DrawColor
= $dc;
351 if($this->FillColor
!=$fc)
353 $this->FillColor
= $fc;
356 $this->TextColor
= $tc;
357 $this->ColorFlag
= $cf;
362 // To be implemented in your own inherited class
367 // To be implemented in your own inherited class
372 // Get current page number
376 function SetDrawColor($r, $g=null, $b=null)
378 // Set color for all stroking operations
379 if(($r==0 && $g==0 && $b==0) ||
$g===null)
380 $this->DrawColor
= sprintf('%.3F G',$r/255);
382 $this->DrawColor
= sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255);
384 $this->_out($this->DrawColor
);
387 function SetFillColor($r, $g=null, $b=null)
389 // Set color for all filling operations
390 if(($r==0 && $g==0 && $b==0) ||
$g===null)
391 $this->FillColor
= sprintf('%.3F g',$r/255);
393 $this->FillColor
= sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
394 $this->ColorFlag
= ($this->FillColor
!=$this->TextColor
);
396 $this->_out($this->FillColor
);
399 function SetTextColor($r, $g=null, $b=null)
401 // Set color for text
402 if(($r==0 && $g==0 && $b==0) ||
$g===null)
403 $this->TextColor
= sprintf('%.3F g',$r/255);
405 $this->TextColor
= sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
406 $this->ColorFlag
= ($this->FillColor
!=$this->TextColor
);
409 function GetStringWidth($s)
411 // Get width of a string in the current font
413 $cw = &$this->CurrentFont
['cw'];
418 return $w*$this->FontSize
/1000;
421 function SetLineWidth($width)
424 $this->LineWidth
= $width;
426 $this->_out(sprintf('%.2F w',$width*$this->k
));
429 function Line($x1, $y1, $x2, $y2)
432 $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
));
435 function Rect($x, $y, $w, $h, $style='')
440 elseif($style=='FD' ||
$style=='DF')
444 $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k
,($this->h
-$y)*$this->k
,$w*$this->k
,-$h*$this->k
,$op));
447 function AddFont($family, $style='', $file='')
449 // Add a TrueType, OpenType or Type1 font
450 $family = strtolower($family);
452 $file = str_replace(' ','',$family).strtolower($style).'.php';
453 $style = strtoupper($style);
456 $fontkey = $family.$style;
457 if(isset($this->fonts
[$fontkey]))
459 $info = $this->_loadfont($file);
460 $info['i'] = count($this->fonts
)+
1;
461 if(!empty($info['file']))
464 if($info['type']=='TrueType')
465 $this->FontFiles
[$info['file']] = array('length1'=>$info['originalsize']);
467 $this->FontFiles
[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
469 $this->fonts
[$fontkey] = $info;
472 function SetFont($family, $style='', $size=0)
474 // Select a font; size given in points
476 $family = $this->FontFamily
;
478 $family = strtolower($family);
479 $style = strtoupper($style);
480 if(strpos($style,'U')!==false)
482 $this->underline
= true;
483 $style = str_replace('U','',$style);
486 $this->underline
= false;
490 $size = $this->FontSizePt
;
491 // Test if font is already selected
492 if($this->FontFamily
==$family && $this->FontStyle
==$style && $this->FontSizePt
==$size)
494 // Test if font is already loaded
495 $fontkey = $family.$style;
496 if(!isset($this->fonts
[$fontkey]))
498 // Test if one of the core fonts
500 $family = 'helvetica';
501 if(in_array($family,$this->CoreFonts
))
503 if($family=='symbol' ||
$family=='zapfdingbats')
505 $fontkey = $family.$style;
506 if(!isset($this->fonts
[$fontkey]))
507 $this->AddFont($family,$style);
510 $this->Error('Undefined font: '.$family.' '.$style);
513 $this->FontFamily
= $family;
514 $this->FontStyle
= $style;
515 $this->FontSizePt
= $size;
516 $this->FontSize
= $size/$this->k
;
517 $this->CurrentFont
= &$this->fonts
[$fontkey];
519 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont
['i'],$this->FontSizePt
));
522 function SetFontSize($size)
524 // Set font size in points
525 if($this->FontSizePt
==$size)
527 $this->FontSizePt
= $size;
528 $this->FontSize
= $size/$this->k
;
530 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont
['i'],$this->FontSizePt
));
535 // Create a new internal link
536 $n = count($this->links
)+
1;
537 $this->links
[$n] = array(0, 0);
541 function SetLink($link, $y=0, $page=-1)
543 // Set destination of internal link
548 $this->links
[$link] = array($page, $y);
551 function Link($x, $y, $w, $h, $link)
553 // Put a link on the page
554 $this->PageLinks
[$this->page
][] = array($x*$this->k
, $this->hPt
-$y*$this->k
, $w*$this->k
, $h*$this->k
, $link);
557 function Text($x, $y, $txt)
560 if(!isset($this->CurrentFont
))
561 $this->Error('No font has been set');
562 $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k
,($this->h
-$y)*$this->k
,$this->_escape($txt));
563 if($this->underline
&& $txt!='')
564 $s .= ' '.$this->_dounderline($x,$y,$txt);
566 $s = 'q '.$this->TextColor
.' '.$s.' Q';
570 function AcceptPageBreak()
572 // Accept automatic page break or not
573 return $this->AutoPageBreak
;
576 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
580 if($this->y+
$h>$this->PageBreakTrigger
&& !$this->InHeader
&& !$this->InFooter
&& $this->AcceptPageBreak())
582 // Automatic page break
590 $this->AddPage($this->CurOrientation
,$this->CurPageSize
,$this->CurRotation
);
595 $this->_out(sprintf('%.3F Tw',$ws*$k));
599 $w = $this->w
-$this->rMargin
-$this->x
;
601 if($fill ||
$border==1)
604 $op = ($border==1) ?
'B' : 'f';
607 $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x
*$k,($this->h
-$this->y
)*$k,$w*$k,-$h*$k,$op);
609 if(is_string($border))
613 if(strpos($border,'L')!==false)
614 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-$y)*$k,$x*$k,($this->h
-($y+
$h))*$k);
615 if(strpos($border,'T')!==false)
616 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-$y)*$k);
617 if(strpos($border,'R')!==false)
618 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+
$w)*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
619 if(strpos($border,'B')!==false)
620 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-($y+
$h))*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
624 if(!isset($this->CurrentFont
))
625 $this->Error('No font has been set');
627 $dx = $w-$this->cMargin
-$this->GetStringWidth($txt);
629 $dx = ($w-$this->GetStringWidth($txt))/2;
631 $dx = $this->cMargin
;
633 $s .= 'q '.$this->TextColor
.' ';
634 $s .= sprintf('BT %.2F %.2F Td (%s) Tj ET',($this->x+
$dx)*$k,($this->h
-($this->y+
.5*$h+
.3*$this->FontSize
))*$k,$this->_escape($txt));
636 $s .= ' '.$this->_dounderline($this->x+
$dx,$this->y+
.5*$h+
.3*$this->FontSize
,$txt);
640 $this->Link($this->x+
$dx,$this->y+
.5*$h-.5*$this->FontSize
,$this->GetStringWidth($txt),$this->FontSize
,$link);
650 $this->x
= $this->lMargin
;
656 function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false)
658 // Output text with automatic or explicit line breaks
659 if(!isset($this->CurrentFont
))
660 $this->Error('No font has been set');
661 $cw = &$this->CurrentFont
['cw'];
663 $w = $this->w
-$this->rMargin
-$this->x
;
664 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
665 $s = str_replace("\r",'',$txt);
667 if($nb>0 && $s[$nb-1]=="\n")
681 if(strpos($border,'L')!==false)
683 if(strpos($border,'R')!==false)
685 $b = (strpos($border,'T')!==false) ?
$b2.'T' : $b2;
696 // Get next character
700 // Explicit line break
706 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
713 if($border && $nl==2)
726 // Automatic line break
736 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
742 $this->ws
= ($ns>1) ?
($wmax-$ls)/1000*$this->FontSize
/($ns-1) : 0;
743 $this->_out(sprintf('%.3F Tw',$this->ws
*$this->k
));
745 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
753 if($border && $nl==2)
765 if($border && strpos($border,'B')!==false)
767 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
768 $this->x
= $this->lMargin
;
771 function Write($h, $txt, $link='')
773 // Output text in flowing mode
774 if(!isset($this->CurrentFont
))
775 $this->Error('No font has been set');
776 $cw = &$this->CurrentFont
['cw'];
777 $w = $this->w
-$this->rMargin
-$this->x
;
778 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
779 $s = str_replace("\r",'',$txt);
788 // Get next character
792 // Explicit line break
793 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
800 $this->x
= $this->lMargin
;
801 $w = $this->w
-$this->rMargin
-$this->x
;
802 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
812 // Automatic line break
815 if($this->x
>$this->lMargin
)
818 $this->x
= $this->lMargin
;
820 $w = $this->w
-$this->rMargin
-$this->x
;
821 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
828 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
832 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link);
840 $this->x
= $this->lMargin
;
841 $w = $this->w
-$this->rMargin
-$this->x
;
842 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
851 $this->Cell($l/1000*$this->FontSize
,$h,substr($s,$j),0,0,'',false,$link);
856 // Line feed; default value is the last cell height
857 $this->x
= $this->lMargin
;
859 $this->y +
= $this->lasth
;
864 function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
866 // Put an image on the page
868 $this->Error('Image file name is empty');
869 if(!isset($this->images
[$file]))
871 // First use of this image, get info
874 $pos = strrpos($file,'.');
876 $this->Error('Image file has no extension and no type was specified: '.$file);
877 $type = substr($file,$pos+
1);
879 $type = strtolower($type);
882 $mtd = '_parse'.$type;
883 if(!method_exists($this,$mtd))
884 $this->Error('Unsupported image type: '.$type);
885 $info = $this->$mtd($file);
886 $info['i'] = count($this->images
)+
1;
887 $this->images
[$file] = $info;
890 $info = $this->images
[$file];
892 // Automatic width and height calculation if needed
895 // Put image at 96 dpi
900 $w = -$info['w']*72/$w/$this->k
;
902 $h = -$info['h']*72/$h/$this->k
;
904 $w = $h*$info['w']/$info['h'];
906 $h = $w*$info['h']/$info['w'];
911 if($this->y+
$h>$this->PageBreakTrigger
&& !$this->InHeader
&& !$this->InFooter
&& $this->AcceptPageBreak())
913 // Automatic page break
915 $this->AddPage($this->CurOrientation
,$this->CurPageSize
,$this->CurRotation
);
924 $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']));
926 $this->Link($x,$y,$w,$h,$link);
929 function GetPageWidth()
931 // Get current page width
935 function GetPageHeight()
937 // Get current page height
953 $this->x
= $this->w+
$x;
962 function SetY($y, $resetX=true)
964 // Set y position and optionally reset x
968 $this->y
= $this->h+
$y;
970 $this->x
= $this->lMargin
;
973 function SetXY($x, $y)
975 // Set x and y positions
977 $this->SetY($y,false);
980 function Output($dest='', $name='', $isUTF8=false)
982 // Output PDF to some destination
984 if(strlen($name)==1 && strlen($dest)!=1)
986 // Fix parameter order
995 switch(strtoupper($dest))
998 // Send to standard output
999 $this->_checkoutput();
1002 // We send to a browser
1003 header('Content-Type: application/pdf');
1004 header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
1005 header('Cache-Control: private, max-age=0, must-revalidate');
1006 header('Pragma: public');
1012 $this->_checkoutput();
1013 header('Content-Type: application/x-download');
1014 header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
1015 header('Cache-Control: private, max-age=0, must-revalidate');
1016 header('Pragma: public');
1020 // Save to local file
1021 if(!file_put_contents($name,$this->buffer
))
1022 $this->Error('Unable to create output file: '.$name);
1025 // Return as a string
1026 return $this->buffer
;
1028 $this->Error('Incorrect output destination: '.$dest);
1033 /*******************************************************************************
1034 * Protected methods *
1035 *******************************************************************************/
1037 protected function _dochecks()
1039 // Check mbstring overloading
1040 if(ini_get('mbstring.func_overload') & 2)
1041 $this->Error('mbstring overloading must be disabled');
1042 // Ensure runtime magic quotes are disabled
1043 if(get_magic_quotes_runtime())
1044 @set_magic_quotes_runtime
(0);
1047 protected function _checkoutput()
1051 if(headers_sent($file,$line))
1052 $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
1056 // The output buffer is not empty
1057 if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
1059 // It contains only a UTF-8 BOM and/or whitespace, let's clean it
1063 $this->Error("Some data has already been output, can't send PDF file");
1067 protected function _getpagesize($size)
1069 if(is_string($size))
1071 $size = strtolower($size);
1072 if(!isset($this->StdPageSizes
[$size]))
1073 $this->Error('Unknown page size: '.$size);
1074 $a = $this->StdPageSizes
[$size];
1075 return array($a[0]/$this->k
, $a[1]/$this->k
);
1079 if($size[0]>$size[1])
1080 return array($size[1], $size[0]);
1086 protected function _beginpage($orientation, $size, $rotation)
1089 $this->pages
[$this->page
] = '';
1091 $this->x
= $this->lMargin
;
1092 $this->y
= $this->tMargin
;
1093 $this->FontFamily
= '';
1094 // Check page size and orientation
1095 if($orientation=='')
1096 $orientation = $this->DefOrientation
;
1098 $orientation = strtoupper($orientation[0]);
1100 $size = $this->DefPageSize
;
1102 $size = $this->_getpagesize($size);
1103 if($orientation!=$this->CurOrientation ||
$size[0]!=$this->CurPageSize
[0] ||
$size[1]!=$this->CurPageSize
[1])
1105 // New size or orientation
1106 if($orientation=='P')
1108 $this->w
= $size[0];
1109 $this->h
= $size[1];
1113 $this->w
= $size[1];
1114 $this->h
= $size[0];
1116 $this->wPt
= $this->w
*$this->k
;
1117 $this->hPt
= $this->h
*$this->k
;
1118 $this->PageBreakTrigger
= $this->h
-$this->bMargin
;
1119 $this->CurOrientation
= $orientation;
1120 $this->CurPageSize
= $size;
1122 if($orientation!=$this->DefOrientation ||
$size[0]!=$this->DefPageSize
[0] ||
$size[1]!=$this->DefPageSize
[1])
1123 $this->PageInfo
[$this->page
]['size'] = array($this->wPt
, $this->hPt
);
1127 $this->Error('Incorrect rotation value: '.$rotation);
1128 $this->CurRotation
= $rotation;
1129 $this->PageInfo
[$this->page
]['rotation'] = $rotation;
1133 protected function _endpage()
1138 protected function _loadfont($font)
1140 // Load a font definition file from the font directory
1141 if(strpos($font,'/')!==false ||
strpos($font,"\\")!==false)
1142 $this->Error('Incorrect font definition file name: '.$font);
1143 include($this->fontpath
.$font);
1145 $this->Error('Could not include font definition file');
1147 $enc = strtolower($enc);
1148 if(!isset($subsetted))
1150 return get_defined_vars();
1153 protected function _isascii($s)
1155 // Test if string is ASCII
1157 for($i=0;$i<$nb;$i++
)
1165 protected function _httpencode($param, $value, $isUTF8)
1167 // Encode HTTP header field parameter
1168 if($this->_isascii($value))
1169 return $param.'="'.$value.'"';
1171 $value = utf8_encode($value);
1172 if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false)
1173 return $param.'="'.rawurlencode($value).'"';
1175 return $param."*=UTF-8''".rawurlencode($value);
1178 protected function _UTF8toUTF16($s)
1180 // Convert UTF-8 to UTF-16BE with BOM
1186 $c1 = ord($s[$i++
]);
1190 $c2 = ord($s[$i++
]);
1191 $c3 = ord($s[$i++
]);
1192 $res .= chr((($c1 & 0x0F)<<4) +
(($c2 & 0x3C)>>2));
1193 $res .= chr((($c2 & 0x03)<<6) +
($c3 & 0x3F));
1198 $c2 = ord($s[$i++
]);
1199 $res .= chr(($c1 & 0x1C)>>2);
1200 $res .= chr((($c1 & 0x03)<<6) +
($c2 & 0x3F));
1204 // Single-byte character
1205 $res .= "\0".chr($c1);
1211 protected function _escape($s)
1213 // Escape special characters
1214 if(strpos($s,'(')!==false ||
strpos($s,')')!==false ||
strpos($s,'\\')!==false ||
strpos($s,"\r")!==false)
1215 return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
1220 protected function _textstring($s)
1222 // Format a text string
1223 if(!$this->_isascii($s))
1224 $s = $this->_UTF8toUTF16($s);
1225 return '('.$this->_escape($s).')';
1228 protected function _dounderline($x, $y, $txt)
1231 $up = $this->CurrentFont
['up'];
1232 $ut = $this->CurrentFont
['ut'];
1233 $w = $this->GetStringWidth($txt)+
$this->ws
*substr_count($txt,' ');
1234 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
);
1237 protected function _parsejpg($file)
1239 // Extract info from a JPEG file
1240 $a = getimagesize($file);
1242 $this->Error('Missing or incorrect image file: '.$file);
1244 $this->Error('Not a JPEG file: '.$file);
1245 if(!isset($a['channels']) ||
$a['channels']==3)
1246 $colspace = 'DeviceRGB';
1247 elseif($a['channels']==4)
1248 $colspace = 'DeviceCMYK';
1250 $colspace = 'DeviceGray';
1251 $bpc = isset($a['bits']) ?
$a['bits'] : 8;
1252 $data = file_get_contents($file);
1253 return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
1256 protected function _parsepng($file)
1258 // Extract info from a PNG file
1259 $f = fopen($file,'rb');
1261 $this->Error('Can\'t open image file: '.$file);
1262 $info = $this->_parsepngstream($f,$file);
1267 protected function _parsepngstream($f, $file)
1270 if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
1271 $this->Error('Not a PNG file: '.$file);
1273 // Read header chunk
1274 $this->_readstream($f,4);
1275 if($this->_readstream($f,4)!='IHDR')
1276 $this->Error('Incorrect PNG file: '.$file);
1277 $w = $this->_readint($f);
1278 $h = $this->_readint($f);
1279 $bpc = ord($this->_readstream($f,1));
1281 $this->Error('16-bit depth not supported: '.$file);
1282 $ct = ord($this->_readstream($f,1));
1283 if($ct==0 ||
$ct==4)
1284 $colspace = 'DeviceGray';
1285 elseif($ct==2 ||
$ct==6)
1286 $colspace = 'DeviceRGB';
1288 $colspace = 'Indexed';
1290 $this->Error('Unknown color type: '.$file);
1291 if(ord($this->_readstream($f,1))!=0)
1292 $this->Error('Unknown compression method: '.$file);
1293 if(ord($this->_readstream($f,1))!=0)
1294 $this->Error('Unknown filter method: '.$file);
1295 if(ord($this->_readstream($f,1))!=0)
1296 $this->Error('Interlacing not supported: '.$file);
1297 $this->_readstream($f,4);
1298 $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ?
3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w;
1300 // Scan chunks looking for palette, transparency and image data
1306 $n = $this->_readint($f);
1307 $type = $this->_readstream($f,4);
1311 $pal = $this->_readstream($f,$n);
1312 $this->_readstream($f,4);
1314 elseif($type=='tRNS')
1316 // Read transparency info
1317 $t = $this->_readstream($f,$n);
1319 $trns = array(ord(substr($t,1,1)));
1321 $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
1324 $pos = strpos($t,chr(0));
1326 $trns = array($pos);
1328 $this->_readstream($f,4);
1330 elseif($type=='IDAT')
1332 // Read image data block
1333 $data .= $this->_readstream($f,$n);
1334 $this->_readstream($f,4);
1336 elseif($type=='IEND')
1339 $this->_readstream($f,$n+
4);
1343 if($colspace=='Indexed' && empty($pal))
1344 $this->Error('Missing palette in '.$file);
1345 $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
1348 // Extract alpha channel
1349 if(!function_exists('gzuncompress'))
1350 $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
1351 $data = gzuncompress($data);
1358 for($i=0;$i<$h;$i++
)
1361 $color .= $data[$pos];
1362 $alpha .= $data[$pos];
1363 $line = substr($data,$pos+
1,$len);
1364 $color .= preg_replace('/(.)./s','$1',$line);
1365 $alpha .= preg_replace('/.(.)/s','$1',$line);
1372 for($i=0;$i<$h;$i++
)
1375 $color .= $data[$pos];
1376 $alpha .= $data[$pos];
1377 $line = substr($data,$pos+
1,$len);
1378 $color .= preg_replace('/(.{3})./s','$1',$line);
1379 $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
1383 $data = gzcompress($color);
1384 $info['smask'] = gzcompress($alpha);
1385 $this->WithAlpha
= true;
1386 if($this->PDFVersion
<'1.4')
1387 $this->PDFVersion
= '1.4';
1389 $info['data'] = $data;
1393 protected function _readstream($f, $n)
1395 // Read n bytes from stream
1397 while($n>0 && !feof($f))
1401 $this->Error('Error while reading stream');
1406 $this->Error('Unexpected end of stream');
1410 protected function _readint($f)
1412 // Read a 4-byte integer from stream
1413 $a = unpack('Ni',$this->_readstream($f,4));
1417 protected function _parsegif($file)
1419 // Extract info from a GIF file (via PNG conversion)
1420 if(!function_exists('imagepng'))
1421 $this->Error('GD extension is required for GIF support');
1422 if(!function_exists('imagecreatefromgif'))
1423 $this->Error('GD has no GIF read support');
1424 $im = imagecreatefromgif($file);
1426 $this->Error('Missing or incorrect image file: '.$file);
1427 imageinterlace($im,0);
1430 $data = ob_get_clean();
1432 $f = fopen('php://temp','rb+');
1434 $this->Error('Unable to create memory stream');
1437 $info = $this->_parsepngstream($f,$file);
1444 // Add a line to the document
1446 $this->pages
[$this->page
] .= $s."\n";
1447 elseif($this->state
==1)
1449 elseif($this->state
==0)
1450 $this->Error('No page has been added yet');
1451 elseif($this->state
==3)
1452 $this->Error('The document is closed');
1455 protected function _put($s)
1457 $this->buffer
.= $s."\n";
1460 protected function _getoffset()
1462 return strlen($this->buffer
);
1465 protected function _newobj($n=null)
1467 // Begin a new object
1470 $this->offsets
[$n] = $this->_getoffset();
1471 $this->_put($n.' 0 obj');
1474 protected function _putstream($data)
1476 $this->_put('stream');
1478 $this->_put('endstream');
1481 protected function _putstreamobject($data)
1485 $entries = '/Filter /FlateDecode ';
1486 $data = gzcompress($data);
1490 $entries .= '/Length '.strlen($data);
1492 $this->_put('<<'.$entries.'>>');
1493 $this->_putstream($data);
1494 $this->_put('endobj');
1497 protected function _putpage($n)
1500 $this->_put('<</Type /Page');
1501 $this->_put('/Parent 1 0 R');
1502 if(isset($this->PageInfo
[$n]['size']))
1503 $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo
[$n]['size'][0],$this->PageInfo
[$n]['size'][1]));
1504 if(isset($this->PageInfo
[$n]['rotation']))
1505 $this->_put('/Rotate '.$this->PageInfo
[$n]['rotation']);
1506 $this->_put('/Resources 2 0 R');
1507 if(isset($this->PageLinks
[$n]))
1510 $annots = '/Annots [';
1511 foreach($this->PageLinks
[$n] as $pl)
1513 $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+
$pl[2],$pl[1]-$pl[3]);
1514 $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
1515 if(is_string($pl[4]))
1516 $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
1519 $l = $this->links
[$pl[4]];
1520 if(isset($this->PageInfo
[$l[0]]['size']))
1521 $h = $this->PageInfo
[$l[0]]['size'][1];
1523 $h = ($this->DefOrientation
=='P') ?
$this->DefPageSize
[1]*$this->k
: $this->DefPageSize
[0]*$this->k
;
1524 $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo
[$l[0]]['n'],$h-$l[1]*$this->k
);
1527 $this->_put($annots.']');
1529 if($this->WithAlpha
)
1530 $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
1531 $this->_put('/Contents '.($this->n+
1).' 0 R>>');
1532 $this->_put('endobj');
1534 if(!empty($this->AliasNbPages
))
1535 $this->pages
[$n] = str_replace($this->AliasNbPages
,$this->page
,$this->pages
[$n]);
1536 $this->_putstreamobject($this->pages
[$n]);
1539 protected function _putpages()
1542 for($n=1;$n<=$nb;$n++
)
1543 $this->PageInfo
[$n]['n'] = $this->n+
1+
2*($n-1);
1544 for($n=1;$n<=$nb;$n++
)
1545 $this->_putpage($n);
1548 $this->_put('<</Type /Pages');
1550 for($n=1;$n<=$nb;$n++
)
1551 $kids .= $this->PageInfo
[$n]['n'].' 0 R ';
1552 $this->_put($kids.']');
1553 $this->_put('/Count '.$nb);
1554 if($this->DefOrientation
=='P')
1556 $w = $this->DefPageSize
[0];
1557 $h = $this->DefPageSize
[1];
1561 $w = $this->DefPageSize
[1];
1562 $h = $this->DefPageSize
[0];
1564 $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k
,$h*$this->k
));
1566 $this->_put('endobj');
1569 protected function _putfonts()
1571 foreach($this->FontFiles
as $file=>$info)
1573 // Font file embedding
1575 $this->FontFiles
[$file]['n'] = $this->n
;
1576 $font = file_get_contents($this->fontpath
.$file,true);
1578 $this->Error('Font file not found: '.$file);
1579 $compressed = (substr($file,-2)=='.z');
1580 if(!$compressed && isset($info['length2']))
1581 $font = substr($font,6,$info['length1']).substr($font,6+
$info['length1']+
6,$info['length2']);
1582 $this->_put('<</Length '.strlen($font));
1584 $this->_put('/Filter /FlateDecode');
1585 $this->_put('/Length1 '.$info['length1']);
1586 if(isset($info['length2']))
1587 $this->_put('/Length2 '.$info['length2'].' /Length3 0');
1589 $this->_putstream($font);
1590 $this->_put('endobj');
1592 foreach($this->fonts
as $k=>$font)
1595 if(isset($font['diff']))
1597 if(!isset($this->encodings
[$font['enc']]))
1600 $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$font['diff'].']>>');
1601 $this->_put('endobj');
1602 $this->encodings
[$font['enc']] = $this->n
;
1606 if(isset($font['uv']))
1608 if(isset($font['enc']))
1609 $cmapkey = $font['enc'];
1611 $cmapkey = $font['name'];
1612 if(!isset($this->cmaps
[$cmapkey]))
1614 $cmap = $this->_tounicodecmap($font['uv']);
1615 $this->_putstreamobject($cmap);
1616 $this->cmaps
[$cmapkey] = $this->n
;
1620 $this->fonts
[$k]['n'] = $this->n+
1;
1621 $type = $font['type'];
1622 $name = $font['name'];
1623 if($font['subsetted'])
1624 $name = 'AAAAAA+'.$name;
1629 $this->_put('<</Type /Font');
1630 $this->_put('/BaseFont /'.$name);
1631 $this->_put('/Subtype /Type1');
1632 if($name!='Symbol' && $name!='ZapfDingbats')
1633 $this->_put('/Encoding /WinAnsiEncoding');
1634 if(isset($font['uv']))
1635 $this->_put('/ToUnicode '.$this->cmaps
[$cmapkey].' 0 R');
1637 $this->_put('endobj');
1639 elseif($type=='Type1' ||
$type=='TrueType')
1641 // Additional Type1 or TrueType/OpenType font
1643 $this->_put('<</Type /Font');
1644 $this->_put('/BaseFont /'.$name);
1645 $this->_put('/Subtype /'.$type);
1646 $this->_put('/FirstChar 32 /LastChar 255');
1647 $this->_put('/Widths '.($this->n+
1).' 0 R');
1648 $this->_put('/FontDescriptor '.($this->n+
2).' 0 R');
1649 if(isset($font['diff']))
1650 $this->_put('/Encoding '.$this->encodings
[$font['enc']].' 0 R');
1652 $this->_put('/Encoding /WinAnsiEncoding');
1653 if(isset($font['uv']))
1654 $this->_put('/ToUnicode '.$this->cmaps
[$cmapkey].' 0 R');
1656 $this->_put('endobj');
1661 for($i=32;$i<=255;$i++
)
1662 $s .= $cw[chr($i)].' ';
1663 $this->_put($s.']');
1664 $this->_put('endobj');
1667 $s = '<</Type /FontDescriptor /FontName /'.$name;
1668 foreach($font['desc'] as $k=>$v)
1669 $s .= ' /'.$k.' '.$v;
1670 if(!empty($font['file']))
1671 $s .= ' /FontFile'.($type=='Type1' ?
'' : '2').' '.$this->FontFiles
[$font['file']]['n'].' 0 R';
1672 $this->_put($s.'>>');
1673 $this->_put('endobj');
1677 // Allow for additional types
1678 $mtd = '_put'.strtolower($type);
1679 if(!method_exists($this,$mtd))
1680 $this->Error('Unsupported font type: '.$type);
1686 protected function _tounicodecmap($uv)
1692 foreach($uv as $c=>$v)
1696 $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+
$v[1]-1,$v[0]);
1701 $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
1705 $s = "/CIDInit /ProcSet findresource begin\n";
1706 $s .= "12 dict begin\n";
1707 $s .= "begincmap\n";
1708 $s .= "/CIDSystemInfo\n";
1709 $s .= "<</Registry (Adobe)\n";
1710 $s .= "/Ordering (UCS)\n";
1711 $s .= "/Supplement 0\n";
1713 $s .= "/CMapName /Adobe-Identity-UCS def\n";
1714 $s .= "/CMapType 2 def\n";
1715 $s .= "1 begincodespacerange\n";
1716 $s .= "<00> <FF>\n";
1717 $s .= "endcodespacerange\n";
1720 $s .= "$nbr beginbfrange\n";
1722 $s .= "endbfrange\n";
1726 $s .= "$nbc beginbfchar\n";
1728 $s .= "endbfchar\n";
1731 $s .= "CMapName currentdict /CMap defineresource pop\n";
1737 protected function _putimages()
1739 foreach(array_keys($this->images
) as $file)
1741 $this->_putimage($this->images
[$file]);
1742 unset($this->images
[$file]['data']);
1743 unset($this->images
[$file]['smask']);
1747 protected function _putimage(&$info)
1750 $info['n'] = $this->n
;
1751 $this->_put('<</Type /XObject');
1752 $this->_put('/Subtype /Image');
1753 $this->_put('/Width '.$info['w']);
1754 $this->_put('/Height '.$info['h']);
1755 if($info['cs']=='Indexed')
1756 $this->_put('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+
1).' 0 R]');
1759 $this->_put('/ColorSpace /'.$info['cs']);
1760 if($info['cs']=='DeviceCMYK')
1761 $this->_put('/Decode [1 0 1 0 1 0 1 0]');
1763 $this->_put('/BitsPerComponent '.$info['bpc']);
1764 if(isset($info['f']))
1765 $this->_put('/Filter /'.$info['f']);
1766 if(isset($info['dp']))
1767 $this->_put('/DecodeParms <<'.$info['dp'].'>>');
1768 if(isset($info['trns']) && is_array($info['trns']))
1771 for($i=0;$i<count($info['trns']);$i++
)
1772 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
1773 $this->_put('/Mask ['.$trns.']');
1775 if(isset($info['smask']))
1776 $this->_put('/SMask '.($this->n+
1).' 0 R');
1777 $this->_put('/Length '.strlen($info['data']).'>>');
1778 $this->_putstream($info['data']);
1779 $this->_put('endobj');
1781 if(isset($info['smask']))
1783 $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '.$info['w'];
1784 $smask = array('w'=>$info['w'], 'h'=>$info['h'], 'cs'=>'DeviceGray', 'bpc'=>8, 'f'=>$info['f'], 'dp'=>$dp, 'data'=>$info['smask']);
1785 $this->_putimage($smask);
1788 if($info['cs']=='Indexed')
1789 $this->_putstreamobject($info['pal']);
1792 protected function _putxobjectdict()
1794 foreach($this->images
as $image)
1795 $this->_put('/I'.$image['i'].' '.$image['n'].' 0 R');
1798 protected function _putresourcedict()
1800 $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
1801 $this->_put('/Font <<');
1802 foreach($this->fonts
as $font)
1803 $this->_put('/F'.$font['i'].' '.$font['n'].' 0 R');
1805 $this->_put('/XObject <<');
1806 $this->_putxobjectdict();
1810 protected function _putresources()
1813 $this->_putimages();
1814 // Resource dictionary
1817 $this->_putresourcedict();
1819 $this->_put('endobj');
1822 protected function _putinfo()
1824 $this->metadata
['Producer'] = 'FPDF '.FPDF_VERSION
;
1825 $this->metadata
['CreationDate'] = 'D:'.@date
('YmdHis');
1826 foreach($this->metadata
as $key=>$value)
1827 $this->_put('/'.$key.' '.$this->_textstring($value));
1830 protected function _putcatalog()
1832 $n = $this->PageInfo
[1]['n'];
1833 $this->_put('/Type /Catalog');
1834 $this->_put('/Pages 1 0 R');
1835 if($this->ZoomMode
=='fullpage')
1836 $this->_put('/OpenAction ['.$n.' 0 R /Fit]');
1837 elseif($this->ZoomMode
=='fullwidth')
1838 $this->_put('/OpenAction ['.$n.' 0 R /FitH null]');
1839 elseif($this->ZoomMode
=='real')
1840 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null 1]');
1841 elseif(!is_string($this->ZoomMode
))
1842 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null '.sprintf('%.2F',$this->ZoomMode
/100).']');
1843 if($this->LayoutMode
=='single')
1844 $this->_put('/PageLayout /SinglePage');
1845 elseif($this->LayoutMode
=='continuous')
1846 $this->_put('/PageLayout /OneColumn');
1847 elseif($this->LayoutMode
=='two')
1848 $this->_put('/PageLayout /TwoColumnLeft');
1851 protected function _putheader()
1853 $this->_put('%PDF-'.$this->PDFVersion
);
1856 protected function _puttrailer()
1858 $this->_put('/Size '.($this->n+
1));
1859 $this->_put('/Root '.$this->n
.' 0 R');
1860 $this->_put('/Info '.($this->n
-1).' 0 R');
1863 protected function _enddoc()
1865 $this->_putheader();
1867 $this->_putresources();
1873 $this->_put('endobj');
1877 $this->_putcatalog();
1879 $this->_put('endobj');
1881 $offset = $this->_getoffset();
1882 $this->_put('xref');
1883 $this->_put('0 '.($this->n+
1));
1884 $this->_put('0000000000 65535 f ');
1885 for($i=1;$i<=$this->n
;$i++
)
1886 $this->_put(sprintf('%010d 00000 n ',$this->offsets
[$i]));
1888 $this->_put('trailer');
1890 $this->_puttrailer();
1892 $this->_put('startxref');
1893 $this->_put($offset);
1894 $this->_put('%%EOF');