2 /*******************************************************************************
7 * Author: Olivier PLATHEY *
8 *******************************************************************************/
10 // Modified by OpenEMR to work with the Barcode class
11 // Needed to make $k, $w, and $h var.
12 // Thus was unable to bring this in via composer since modified.
14 define('FPDF_VERSION','1.81');
18 protected $page; // current page number
19 protected $n; // current object number
20 protected $offsets; // array of object offsets
21 protected $buffer; // buffer holding in-memory PDF
22 protected $pages; // array containing pages
23 protected $state; // current document state
24 protected $compress; // compression flag
25 var $k; // scale factor (number of points in user unit)
26 protected $DefOrientation; // default orientation
27 protected $CurOrientation; // current orientation
28 protected $StdPageSizes; // standard page sizes
29 protected $DefPageSize; // default page size
30 protected $CurPageSize; // current page size
31 protected $CurRotation; // current page rotation
32 protected $PageInfo; // page-related data
33 protected $wPt, $hPt; // dimensions of current page in points
34 var $w, $h; // dimensions of current page in user unit
35 protected $lMargin; // left margin
36 protected $tMargin; // top margin
37 protected $rMargin; // right margin
38 protected $bMargin; // page break margin
39 protected $cMargin; // cell margin
40 protected $x, $y; // current position in user unit
41 protected $lasth; // height of last printed cell
42 protected $LineWidth; // line width in user unit
43 protected $fontpath; // path containing fonts
44 protected $CoreFonts; // array of core font names
45 protected $fonts; // array of used fonts
46 protected $FontFiles; // array of font files
47 protected $encodings; // array of encodings
48 protected $cmaps; // array of ToUnicode CMaps
49 protected $FontFamily; // current font family
50 protected $FontStyle; // current font style
51 protected $underline; // underlining flag
52 protected $CurrentFont; // current font info
53 protected $FontSizePt; // current font size in points
54 protected $FontSize; // current font size in user unit
55 protected $DrawColor; // commands for drawing color
56 protected $FillColor; // commands for filling color
57 protected $TextColor; // commands for text color
58 protected $ColorFlag; // indicates whether fill and text colors are different
59 protected $WithAlpha; // indicates whether alpha channel is used
60 protected $ws; // word spacing
61 protected $images; // array of used images
62 protected $PageLinks; // array of links in pages
63 protected $links; // array of internal links
64 protected $AutoPageBreak; // automatic page breaking
65 protected $PageBreakTrigger; // threshold used to trigger page breaks
66 protected $InHeader; // flag set when processing header
67 protected $InFooter; // flag set when processing footer
68 protected $AliasNbPages; // alias for total number of pages
69 protected $ZoomMode; // zoom display mode
70 protected $LayoutMode; // layout display mode
71 protected $metadata; // document properties
72 protected $PDFVersion; // PDF version number
74 /*******************************************************************************
76 *******************************************************************************/
78 function __construct($orientation='P', $unit='mm', $size='A4')
82 // Initialization of properties
87 $this->pages
= array();
88 $this->PageInfo
= array();
89 $this->fonts
= array();
90 $this->FontFiles
= array();
91 $this->encodings
= array();
92 $this->cmaps
= array();
93 $this->images
= array();
94 $this->links
= array();
95 $this->InHeader
= false;
96 $this->InFooter
= false;
98 $this->FontFamily
= '';
99 $this->FontStyle
= '';
100 $this->FontSizePt
= 12;
101 $this->underline
= false;
102 $this->DrawColor
= '0 G';
103 $this->FillColor
= '0 g';
104 $this->TextColor
= '0 g';
105 $this->ColorFlag
= false;
106 $this->WithAlpha
= false;
109 if(defined('FPDF_FONTPATH'))
111 $this->fontpath
= FPDF_FONTPATH
;
112 if(substr($this->fontpath
,-1)!='/' && substr($this->fontpath
,-1)!='\\')
113 $this->fontpath
.= '/';
115 elseif(is_dir(dirname(__FILE__
).'/font'))
116 $this->fontpath
= dirname(__FILE__
).'/font/';
118 $this->fontpath
= '';
120 $this->CoreFonts
= array('courier', 'helvetica', 'times', 'symbol', 'zapfdingbats');
131 $this->Error('Incorrect unit: '.$unit);
133 $this->StdPageSizes
= array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
134 'letter'=>array(612,792), 'legal'=>array(612,1008));
135 $size = $this->_getpagesize($size);
136 $this->DefPageSize
= $size;
137 $this->CurPageSize
= $size;
139 $orientation = strtolower($orientation);
140 if($orientation=='p' ||
$orientation=='portrait')
142 $this->DefOrientation
= 'P';
146 elseif($orientation=='l' ||
$orientation=='landscape')
148 $this->DefOrientation
= 'L';
153 $this->Error('Incorrect orientation: '.$orientation);
154 $this->CurOrientation
= $this->DefOrientation
;
155 $this->wPt
= $this->w
*$this->k
;
156 $this->hPt
= $this->h
*$this->k
;
158 $this->CurRotation
= 0;
159 // Page margins (1 cm)
160 $margin = 28.35/$this->k
;
161 $this->SetMargins($margin,$margin);
162 // Interior cell margin (1 mm)
163 $this->cMargin
= $margin/10;
164 // Line width (0.2 mm)
165 $this->LineWidth
= .567/$this->k
;
166 // Automatic page break
167 $this->SetAutoPageBreak(true,2*$margin);
168 // Default display mode
169 $this->SetDisplayMode('default');
170 // Enable compression
171 $this->SetCompression(true);
172 // Set default PDF version number
173 $this->PDFVersion
= '1.3';
176 function SetMargins($left, $top, $right=null)
178 // Set left, top and right margins
179 $this->lMargin
= $left;
180 $this->tMargin
= $top;
183 $this->rMargin
= $right;
186 function SetLeftMargin($margin)
189 $this->lMargin
= $margin;
190 if($this->page
>0 && $this->x
<$margin)
194 function SetTopMargin($margin)
197 $this->tMargin
= $margin;
200 function SetRightMargin($margin)
203 $this->rMargin
= $margin;
206 function SetAutoPageBreak($auto, $margin=0)
208 // Set auto page break mode and triggering margin
209 $this->AutoPageBreak
= $auto;
210 $this->bMargin
= $margin;
211 $this->PageBreakTrigger
= $this->h
-$margin;
214 function SetDisplayMode($zoom, $layout='default')
216 // Set display mode in viewer
217 if($zoom=='fullpage' ||
$zoom=='fullwidth' ||
$zoom=='real' ||
$zoom=='default' ||
!is_string($zoom))
218 $this->ZoomMode
= $zoom;
220 $this->Error('Incorrect zoom display mode: '.$zoom);
221 if($layout=='single' ||
$layout=='continuous' ||
$layout=='two' ||
$layout=='default')
222 $this->LayoutMode
= $layout;
224 $this->Error('Incorrect layout display mode: '.$layout);
227 function SetCompression($compress)
229 // Set page compression
230 if(function_exists('gzcompress'))
231 $this->compress
= $compress;
233 $this->compress
= false;
236 function SetTitle($title, $isUTF8=false)
239 $this->metadata
['Title'] = $isUTF8 ?
$title : utf8_encode($title);
242 function SetAuthor($author, $isUTF8=false)
244 // Author of document
245 $this->metadata
['Author'] = $isUTF8 ?
$author : utf8_encode($author);
248 function SetSubject($subject, $isUTF8=false)
250 // Subject of document
251 $this->metadata
['Subject'] = $isUTF8 ?
$subject : utf8_encode($subject);
254 function SetKeywords($keywords, $isUTF8=false)
256 // Keywords of document
257 $this->metadata
['Keywords'] = $isUTF8 ?
$keywords : utf8_encode($keywords);
260 function SetCreator($creator, $isUTF8=false)
262 // Creator of document
263 $this->metadata
['Creator'] = $isUTF8 ?
$creator : utf8_encode($creator);
266 function AliasNbPages($alias='{nb}')
268 // Define an alias for total number of pages
269 $this->AliasNbPages
= $alias;
275 throw new Exception('FPDF error: '.$msg);
280 // Terminate document
286 $this->InFooter
= true;
288 $this->InFooter
= false;
295 function AddPage($orientation='', $size='', $rotation=0)
299 $this->Error('The document is closed');
300 $family = $this->FontFamily
;
301 $style = $this->FontStyle
.($this->underline ?
'U' : '');
302 $fontsize = $this->FontSizePt
;
303 $lw = $this->LineWidth
;
304 $dc = $this->DrawColor
;
305 $fc = $this->FillColor
;
306 $tc = $this->TextColor
;
307 $cf = $this->ColorFlag
;
311 $this->InFooter
= true;
313 $this->InFooter
= false;
318 $this->_beginpage($orientation,$size,$rotation);
319 // Set line cap style to square
322 $this->LineWidth
= $lw;
323 $this->_out(sprintf('%.2F w',$lw*$this->k
));
326 $this->SetFont($family,$style,$fontsize);
328 $this->DrawColor
= $dc;
331 $this->FillColor
= $fc;
334 $this->TextColor
= $tc;
335 $this->ColorFlag
= $cf;
337 $this->InHeader
= true;
339 $this->InHeader
= false;
340 // Restore line width
341 if($this->LineWidth
!=$lw)
343 $this->LineWidth
= $lw;
344 $this->_out(sprintf('%.2F w',$lw*$this->k
));
348 $this->SetFont($family,$style,$fontsize);
350 if($this->DrawColor
!=$dc)
352 $this->DrawColor
= $dc;
355 if($this->FillColor
!=$fc)
357 $this->FillColor
= $fc;
360 $this->TextColor
= $tc;
361 $this->ColorFlag
= $cf;
366 // To be implemented in your own inherited class
371 // To be implemented in your own inherited class
376 // Get current page number
380 function SetDrawColor($r, $g=null, $b=null)
382 // Set color for all stroking operations
383 if(($r==0 && $g==0 && $b==0) ||
$g===null)
384 $this->DrawColor
= sprintf('%.3F G',$r/255);
386 $this->DrawColor
= sprintf('%.3F %.3F %.3F RG',$r/255,$g/255,$b/255);
388 $this->_out($this->DrawColor
);
391 function SetFillColor($r, $g=null, $b=null)
393 // Set color for all filling operations
394 if(($r==0 && $g==0 && $b==0) ||
$g===null)
395 $this->FillColor
= sprintf('%.3F g',$r/255);
397 $this->FillColor
= sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
398 $this->ColorFlag
= ($this->FillColor
!=$this->TextColor
);
400 $this->_out($this->FillColor
);
403 function SetTextColor($r, $g=null, $b=null)
405 // Set color for text
406 if(($r==0 && $g==0 && $b==0) ||
$g===null)
407 $this->TextColor
= sprintf('%.3F g',$r/255);
409 $this->TextColor
= sprintf('%.3F %.3F %.3F rg',$r/255,$g/255,$b/255);
410 $this->ColorFlag
= ($this->FillColor
!=$this->TextColor
);
413 function GetStringWidth($s)
415 // Get width of a string in the current font
417 $cw = &$this->CurrentFont
['cw'];
422 return $w*$this->FontSize
/1000;
425 function SetLineWidth($width)
428 $this->LineWidth
= $width;
430 $this->_out(sprintf('%.2F w',$width*$this->k
));
433 function Line($x1, $y1, $x2, $y2)
436 $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
));
439 function Rect($x, $y, $w, $h, $style='')
444 elseif($style=='FD' ||
$style=='DF')
448 $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k
,($this->h
-$y)*$this->k
,$w*$this->k
,-$h*$this->k
,$op));
451 function AddFont($family, $style='', $file='')
453 // Add a TrueType, OpenType or Type1 font
454 $family = strtolower($family);
456 $file = str_replace(' ','',$family).strtolower($style).'.php';
457 $style = strtoupper($style);
460 $fontkey = $family.$style;
461 if(isset($this->fonts
[$fontkey]))
463 $info = $this->_loadfont($file);
464 $info['i'] = count($this->fonts
)+
1;
465 if(!empty($info['file']))
468 if($info['type']=='TrueType')
469 $this->FontFiles
[$info['file']] = array('length1'=>$info['originalsize']);
471 $this->FontFiles
[$info['file']] = array('length1'=>$info['size1'], 'length2'=>$info['size2']);
473 $this->fonts
[$fontkey] = $info;
476 function SetFont($family, $style='', $size=0)
478 // Select a font; size given in points
480 $family = $this->FontFamily
;
482 $family = strtolower($family);
483 $style = strtoupper($style);
484 if(strpos($style,'U')!==false)
486 $this->underline
= true;
487 $style = str_replace('U','',$style);
490 $this->underline
= false;
494 $size = $this->FontSizePt
;
495 // Test if font is already selected
496 if($this->FontFamily
==$family && $this->FontStyle
==$style && $this->FontSizePt
==$size)
498 // Test if font is already loaded
499 $fontkey = $family.$style;
500 if(!isset($this->fonts
[$fontkey]))
502 // Test if one of the core fonts
504 $family = 'helvetica';
505 if(in_array($family,$this->CoreFonts
))
507 if($family=='symbol' ||
$family=='zapfdingbats')
509 $fontkey = $family.$style;
510 if(!isset($this->fonts
[$fontkey]))
511 $this->AddFont($family,$style);
514 $this->Error('Undefined font: '.$family.' '.$style);
517 $this->FontFamily
= $family;
518 $this->FontStyle
= $style;
519 $this->FontSizePt
= $size;
520 $this->FontSize
= $size/$this->k
;
521 $this->CurrentFont
= &$this->fonts
[$fontkey];
523 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont
['i'],$this->FontSizePt
));
526 function SetFontSize($size)
528 // Set font size in points
529 if($this->FontSizePt
==$size)
531 $this->FontSizePt
= $size;
532 $this->FontSize
= $size/$this->k
;
534 $this->_out(sprintf('BT /F%d %.2F Tf ET',$this->CurrentFont
['i'],$this->FontSizePt
));
539 // Create a new internal link
540 $n = count($this->links
)+
1;
541 $this->links
[$n] = array(0, 0);
545 function SetLink($link, $y=0, $page=-1)
547 // Set destination of internal link
552 $this->links
[$link] = array($page, $y);
555 function Link($x, $y, $w, $h, $link)
557 // Put a link on the page
558 $this->PageLinks
[$this->page
][] = array($x*$this->k
, $this->hPt
-$y*$this->k
, $w*$this->k
, $h*$this->k
, $link);
561 function Text($x, $y, $txt)
564 if(!isset($this->CurrentFont
))
565 $this->Error('No font has been set');
566 $s = sprintf('BT %.2F %.2F Td (%s) Tj ET',$x*$this->k
,($this->h
-$y)*$this->k
,$this->_escape($txt));
567 if($this->underline
&& $txt!='')
568 $s .= ' '.$this->_dounderline($x,$y,$txt);
570 $s = 'q '.$this->TextColor
.' '.$s.' Q';
574 function AcceptPageBreak()
576 // Accept automatic page break or not
577 return $this->AutoPageBreak
;
580 function Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
584 if($this->y+
$h>$this->PageBreakTrigger
&& !$this->InHeader
&& !$this->InFooter
&& $this->AcceptPageBreak())
586 // Automatic page break
594 $this->AddPage($this->CurOrientation
,$this->CurPageSize
,$this->CurRotation
);
599 $this->_out(sprintf('%.3F Tw',$ws*$k));
603 $w = $this->w
-$this->rMargin
-$this->x
;
605 if($fill ||
$border==1)
608 $op = ($border==1) ?
'B' : 'f';
611 $s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x
*$k,($this->h
-$this->y
)*$k,$w*$k,-$h*$k,$op);
613 if(is_string($border))
617 if(strpos($border,'L')!==false)
618 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-$y)*$k,$x*$k,($this->h
-($y+
$h))*$k);
619 if(strpos($border,'T')!==false)
620 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-$y)*$k);
621 if(strpos($border,'R')!==false)
622 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',($x+
$w)*$k,($this->h
-$y)*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
623 if(strpos($border,'B')!==false)
624 $s .= sprintf('%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->h
-($y+
$h))*$k,($x+
$w)*$k,($this->h
-($y+
$h))*$k);
628 if(!isset($this->CurrentFont
))
629 $this->Error('No font has been set');
631 $dx = $w-$this->cMargin
-$this->GetStringWidth($txt);
633 $dx = ($w-$this->GetStringWidth($txt))/2;
635 $dx = $this->cMargin
;
637 $s .= 'q '.$this->TextColor
.' ';
638 $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));
640 $s .= ' '.$this->_dounderline($this->x+
$dx,$this->y+
.5*$h+
.3*$this->FontSize
,$txt);
644 $this->Link($this->x+
$dx,$this->y+
.5*$h-.5*$this->FontSize
,$this->GetStringWidth($txt),$this->FontSize
,$link);
654 $this->x
= $this->lMargin
;
660 function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=false)
662 // Output text with automatic or explicit line breaks
663 if(!isset($this->CurrentFont
))
664 $this->Error('No font has been set');
665 $cw = &$this->CurrentFont
['cw'];
667 $w = $this->w
-$this->rMargin
-$this->x
;
668 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
669 $s = str_replace("\r",'',$txt);
671 if($nb>0 && $s[$nb-1]=="\n")
685 if(strpos($border,'L')!==false)
687 if(strpos($border,'R')!==false)
689 $b = (strpos($border,'T')!==false) ?
$b2.'T' : $b2;
700 // Get next character
704 // Explicit line break
710 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
717 if($border && $nl==2)
730 // Automatic line break
740 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
746 $this->ws
= ($ns>1) ?
($wmax-$ls)/1000*$this->FontSize
/($ns-1) : 0;
747 $this->_out(sprintf('%.3F Tw',$this->ws
*$this->k
));
749 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
757 if($border && $nl==2)
769 if($border && strpos($border,'B')!==false)
771 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
772 $this->x
= $this->lMargin
;
775 function Write($h, $txt, $link='')
777 // Output text in flowing mode
778 if(!isset($this->CurrentFont
))
779 $this->Error('No font has been set');
780 $cw = &$this->CurrentFont
['cw'];
781 $w = $this->w
-$this->rMargin
-$this->x
;
782 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
783 $s = str_replace("\r",'',$txt);
792 // Get next character
796 // Explicit line break
797 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
804 $this->x
= $this->lMargin
;
805 $w = $this->w
-$this->rMargin
-$this->x
;
806 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
816 // Automatic line break
819 if($this->x
>$this->lMargin
)
822 $this->x
= $this->lMargin
;
824 $w = $this->w
-$this->rMargin
-$this->x
;
825 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
832 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',false,$link);
836 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',false,$link);
844 $this->x
= $this->lMargin
;
845 $w = $this->w
-$this->rMargin
-$this->x
;
846 $wmax = ($w-2*$this->cMargin
)*1000/$this->FontSize
;
855 $this->Cell($l/1000*$this->FontSize
,$h,substr($s,$j),0,0,'',false,$link);
860 // Line feed; default value is the last cell height
861 $this->x
= $this->lMargin
;
863 $this->y +
= $this->lasth
;
868 function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='')
870 // Put an image on the page
872 $this->Error('Image file name is empty');
873 if(!isset($this->images
[$file]))
875 // First use of this image, get info
878 $pos = strrpos($file,'.');
880 $this->Error('Image file has no extension and no type was specified: '.$file);
881 $type = substr($file,$pos+
1);
883 $type = strtolower($type);
886 $mtd = '_parse'.$type;
887 if(!method_exists($this,$mtd))
888 $this->Error('Unsupported image type: '.$type);
889 $info = $this->$mtd($file);
890 $info['i'] = count($this->images
)+
1;
891 $this->images
[$file] = $info;
894 $info = $this->images
[$file];
896 // Automatic width and height calculation if needed
899 // Put image at 96 dpi
904 $w = -$info['w']*72/$w/$this->k
;
906 $h = -$info['h']*72/$h/$this->k
;
908 $w = $h*$info['w']/$info['h'];
910 $h = $w*$info['h']/$info['w'];
915 if($this->y+
$h>$this->PageBreakTrigger
&& !$this->InHeader
&& !$this->InFooter
&& $this->AcceptPageBreak())
917 // Automatic page break
919 $this->AddPage($this->CurOrientation
,$this->CurPageSize
,$this->CurRotation
);
928 $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']));
930 $this->Link($x,$y,$w,$h,$link);
933 function GetPageWidth()
935 // Get current page width
939 function GetPageHeight()
941 // Get current page height
957 $this->x
= $this->w+
$x;
966 function SetY($y, $resetX=true)
968 // Set y position and optionally reset x
972 $this->y
= $this->h+
$y;
974 $this->x
= $this->lMargin
;
977 function SetXY($x, $y)
979 // Set x and y positions
981 $this->SetY($y,false);
984 function Output($dest='', $name='', $isUTF8=false)
986 // Output PDF to some destination
988 if(strlen($name)==1 && strlen($dest)!=1)
990 // Fix parameter order
999 switch(strtoupper($dest))
1002 // Send to standard output
1003 $this->_checkoutput();
1006 // We send to a browser
1007 header('Content-Type: application/pdf');
1008 header('Content-Disposition: inline; '.$this->_httpencode('filename',$name,$isUTF8));
1009 header('Cache-Control: private, max-age=0, must-revalidate');
1010 header('Pragma: public');
1016 $this->_checkoutput();
1017 header('Content-Type: application/x-download');
1018 header('Content-Disposition: attachment; '.$this->_httpencode('filename',$name,$isUTF8));
1019 header('Cache-Control: private, max-age=0, must-revalidate');
1020 header('Pragma: public');
1024 // Save to local file
1025 if(!file_put_contents($name,$this->buffer
))
1026 $this->Error('Unable to create output file: '.$name);
1029 // Return as a string
1030 return $this->buffer
;
1032 $this->Error('Incorrect output destination: '.$dest);
1037 /*******************************************************************************
1038 * Protected methods *
1039 *******************************************************************************/
1041 protected function _dochecks()
1043 // Check mbstring overloading
1044 if(ini_get('mbstring.func_overload') & 2)
1045 $this->Error('mbstring overloading must be disabled');
1046 // Ensure runtime magic quotes are disabled
1047 if(get_magic_quotes_runtime())
1048 @set_magic_quotes_runtime
(0);
1051 protected function _checkoutput()
1055 if(headers_sent($file,$line))
1056 $this->Error("Some data has already been output, can't send PDF file (output started at $file:$line)");
1060 // The output buffer is not empty
1061 if(preg_match('/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
1063 // It contains only a UTF-8 BOM and/or whitespace, let's clean it
1067 $this->Error("Some data has already been output, can't send PDF file");
1071 protected function _getpagesize($size)
1073 if(is_string($size))
1075 $size = strtolower($size);
1076 if(!isset($this->StdPageSizes
[$size]))
1077 $this->Error('Unknown page size: '.$size);
1078 $a = $this->StdPageSizes
[$size];
1079 return array($a[0]/$this->k
, $a[1]/$this->k
);
1083 if($size[0]>$size[1])
1084 return array($size[1], $size[0]);
1090 protected function _beginpage($orientation, $size, $rotation)
1093 $this->pages
[$this->page
] = '';
1095 $this->x
= $this->lMargin
;
1096 $this->y
= $this->tMargin
;
1097 $this->FontFamily
= '';
1098 // Check page size and orientation
1099 if($orientation=='')
1100 $orientation = $this->DefOrientation
;
1102 $orientation = strtoupper($orientation[0]);
1104 $size = $this->DefPageSize
;
1106 $size = $this->_getpagesize($size);
1107 if($orientation!=$this->CurOrientation ||
$size[0]!=$this->CurPageSize
[0] ||
$size[1]!=$this->CurPageSize
[1])
1109 // New size or orientation
1110 if($orientation=='P')
1112 $this->w
= $size[0];
1113 $this->h
= $size[1];
1117 $this->w
= $size[1];
1118 $this->h
= $size[0];
1120 $this->wPt
= $this->w
*$this->k
;
1121 $this->hPt
= $this->h
*$this->k
;
1122 $this->PageBreakTrigger
= $this->h
-$this->bMargin
;
1123 $this->CurOrientation
= $orientation;
1124 $this->CurPageSize
= $size;
1126 if($orientation!=$this->DefOrientation ||
$size[0]!=$this->DefPageSize
[0] ||
$size[1]!=$this->DefPageSize
[1])
1127 $this->PageInfo
[$this->page
]['size'] = array($this->wPt
, $this->hPt
);
1131 $this->Error('Incorrect rotation value: '.$rotation);
1132 $this->CurRotation
= $rotation;
1133 $this->PageInfo
[$this->page
]['rotation'] = $rotation;
1137 protected function _endpage()
1142 protected function _loadfont($font)
1144 // Load a font definition file from the font directory
1145 if(strpos($font,'/')!==false ||
strpos($font,"\\")!==false)
1146 $this->Error('Incorrect font definition file name: '.$font);
1147 include($this->fontpath
.$font);
1149 $this->Error('Could not include font definition file');
1151 $enc = strtolower($enc);
1152 if(!isset($subsetted))
1154 return get_defined_vars();
1157 protected function _isascii($s)
1159 // Test if string is ASCII
1161 for($i=0;$i<$nb;$i++
)
1169 protected function _httpencode($param, $value, $isUTF8)
1171 // Encode HTTP header field parameter
1172 if($this->_isascii($value))
1173 return $param.'="'.$value.'"';
1175 $value = utf8_encode($value);
1176 if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')!==false)
1177 return $param.'="'.rawurlencode($value).'"';
1179 return $param."*=UTF-8''".rawurlencode($value);
1182 protected function _UTF8toUTF16($s)
1184 // Convert UTF-8 to UTF-16BE with BOM
1190 $c1 = ord($s[$i++
]);
1194 $c2 = ord($s[$i++
]);
1195 $c3 = ord($s[$i++
]);
1196 $res .= chr((($c1 & 0x0F)<<4) +
(($c2 & 0x3C)>>2));
1197 $res .= chr((($c2 & 0x03)<<6) +
($c3 & 0x3F));
1202 $c2 = ord($s[$i++
]);
1203 $res .= chr(($c1 & 0x1C)>>2);
1204 $res .= chr((($c1 & 0x03)<<6) +
($c2 & 0x3F));
1208 // Single-byte character
1209 $res .= "\0".chr($c1);
1215 protected function _escape($s)
1217 // Escape special characters
1218 if(strpos($s,'(')!==false ||
strpos($s,')')!==false ||
strpos($s,'\\')!==false ||
strpos($s,"\r")!==false)
1219 return str_replace(array('\\','(',')',"\r"), array('\\\\','\\(','\\)','\\r'), $s);
1224 protected function _textstring($s)
1226 // Format a text string
1227 if(!$this->_isascii($s))
1228 $s = $this->_UTF8toUTF16($s);
1229 return '('.$this->_escape($s).')';
1232 protected function _dounderline($x, $y, $txt)
1235 $up = $this->CurrentFont
['up'];
1236 $ut = $this->CurrentFont
['ut'];
1237 $w = $this->GetStringWidth($txt)+
$this->ws
*substr_count($txt,' ');
1238 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
);
1241 protected function _parsejpg($file)
1243 // Extract info from a JPEG file
1244 $a = getimagesize($file);
1246 $this->Error('Missing or incorrect image file: '.$file);
1248 $this->Error('Not a JPEG file: '.$file);
1249 if(!isset($a['channels']) ||
$a['channels']==3)
1250 $colspace = 'DeviceRGB';
1251 elseif($a['channels']==4)
1252 $colspace = 'DeviceCMYK';
1254 $colspace = 'DeviceGray';
1255 $bpc = isset($a['bits']) ?
$a['bits'] : 8;
1256 $data = file_get_contents($file);
1257 return array('w'=>$a[0], 'h'=>$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>$data);
1260 protected function _parsepng($file)
1262 // Extract info from a PNG file
1263 $f = fopen($file,'rb');
1265 $this->Error('Can\'t open image file: '.$file);
1266 $info = $this->_parsepngstream($f,$file);
1271 protected function _parsepngstream($f, $file)
1274 if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
1275 $this->Error('Not a PNG file: '.$file);
1277 // Read header chunk
1278 $this->_readstream($f,4);
1279 if($this->_readstream($f,4)!='IHDR')
1280 $this->Error('Incorrect PNG file: '.$file);
1281 $w = $this->_readint($f);
1282 $h = $this->_readint($f);
1283 $bpc = ord($this->_readstream($f,1));
1285 $this->Error('16-bit depth not supported: '.$file);
1286 $ct = ord($this->_readstream($f,1));
1287 if($ct==0 ||
$ct==4)
1288 $colspace = 'DeviceGray';
1289 elseif($ct==2 ||
$ct==6)
1290 $colspace = 'DeviceRGB';
1292 $colspace = 'Indexed';
1294 $this->Error('Unknown color type: '.$file);
1295 if(ord($this->_readstream($f,1))!=0)
1296 $this->Error('Unknown compression method: '.$file);
1297 if(ord($this->_readstream($f,1))!=0)
1298 $this->Error('Unknown filter method: '.$file);
1299 if(ord($this->_readstream($f,1))!=0)
1300 $this->Error('Interlacing not supported: '.$file);
1301 $this->_readstream($f,4);
1302 $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ?
3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w;
1304 // Scan chunks looking for palette, transparency and image data
1310 $n = $this->_readint($f);
1311 $type = $this->_readstream($f,4);
1315 $pal = $this->_readstream($f,$n);
1316 $this->_readstream($f,4);
1318 elseif($type=='tRNS')
1320 // Read transparency info
1321 $t = $this->_readstream($f,$n);
1323 $trns = array(ord(substr($t,1,1)));
1325 $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
1328 $pos = strpos($t,chr(0));
1330 $trns = array($pos);
1332 $this->_readstream($f,4);
1334 elseif($type=='IDAT')
1336 // Read image data block
1337 $data .= $this->_readstream($f,$n);
1338 $this->_readstream($f,4);
1340 elseif($type=='IEND')
1343 $this->_readstream($f,$n+
4);
1347 if($colspace=='Indexed' && empty($pal))
1348 $this->Error('Missing palette in '.$file);
1349 $info = array('w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
1352 // Extract alpha channel
1353 if(!function_exists('gzuncompress'))
1354 $this->Error('Zlib not available, can\'t handle alpha channel: '.$file);
1355 $data = gzuncompress($data);
1362 for($i=0;$i<$h;$i++
)
1365 $color .= $data[$pos];
1366 $alpha .= $data[$pos];
1367 $line = substr($data,$pos+
1,$len);
1368 $color .= preg_replace('/(.)./s','$1',$line);
1369 $alpha .= preg_replace('/.(.)/s','$1',$line);
1376 for($i=0;$i<$h;$i++
)
1379 $color .= $data[$pos];
1380 $alpha .= $data[$pos];
1381 $line = substr($data,$pos+
1,$len);
1382 $color .= preg_replace('/(.{3})./s','$1',$line);
1383 $alpha .= preg_replace('/.{3}(.)/s','$1',$line);
1387 $data = gzcompress($color);
1388 $info['smask'] = gzcompress($alpha);
1389 $this->WithAlpha
= true;
1390 if($this->PDFVersion
<'1.4')
1391 $this->PDFVersion
= '1.4';
1393 $info['data'] = $data;
1397 protected function _readstream($f, $n)
1399 // Read n bytes from stream
1401 while($n>0 && !feof($f))
1405 $this->Error('Error while reading stream');
1410 $this->Error('Unexpected end of stream');
1414 protected function _readint($f)
1416 // Read a 4-byte integer from stream
1417 $a = unpack('Ni',$this->_readstream($f,4));
1421 protected function _parsegif($file)
1423 // Extract info from a GIF file (via PNG conversion)
1424 if(!function_exists('imagepng'))
1425 $this->Error('GD extension is required for GIF support');
1426 if(!function_exists('imagecreatefromgif'))
1427 $this->Error('GD has no GIF read support');
1428 $im = imagecreatefromgif($file);
1430 $this->Error('Missing or incorrect image file: '.$file);
1431 imageinterlace($im,0);
1434 $data = ob_get_clean();
1436 $f = fopen('php://temp','rb+');
1438 $this->Error('Unable to create memory stream');
1441 $info = $this->_parsepngstream($f,$file);
1448 // Add a line to the document
1450 $this->pages
[$this->page
] .= $s."\n";
1451 elseif($this->state
==1)
1453 elseif($this->state
==0)
1454 $this->Error('No page has been added yet');
1455 elseif($this->state
==3)
1456 $this->Error('The document is closed');
1459 protected function _put($s)
1461 $this->buffer
.= $s."\n";
1464 protected function _getoffset()
1466 return strlen($this->buffer
);
1469 protected function _newobj($n=null)
1471 // Begin a new object
1474 $this->offsets
[$n] = $this->_getoffset();
1475 $this->_put($n.' 0 obj');
1478 protected function _putstream($data)
1480 $this->_put('stream');
1482 $this->_put('endstream');
1485 protected function _putstreamobject($data)
1489 $entries = '/Filter /FlateDecode ';
1490 $data = gzcompress($data);
1494 $entries .= '/Length '.strlen($data);
1496 $this->_put('<<'.$entries.'>>');
1497 $this->_putstream($data);
1498 $this->_put('endobj');
1501 protected function _putpage($n)
1504 $this->_put('<</Type /Page');
1505 $this->_put('/Parent 1 0 R');
1506 if(isset($this->PageInfo
[$n]['size']))
1507 $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageInfo
[$n]['size'][0],$this->PageInfo
[$n]['size'][1]));
1508 if(isset($this->PageInfo
[$n]['rotation']))
1509 $this->_put('/Rotate '.$this->PageInfo
[$n]['rotation']);
1510 $this->_put('/Resources 2 0 R');
1511 if(isset($this->PageLinks
[$n]))
1514 $annots = '/Annots [';
1515 foreach($this->PageLinks
[$n] as $pl)
1517 $rect = sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+
$pl[2],$pl[1]-$pl[3]);
1518 $annots .= '<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] ';
1519 if(is_string($pl[4]))
1520 $annots .= '/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>';
1523 $l = $this->links
[$pl[4]];
1524 if(isset($this->PageInfo
[$l[0]]['size']))
1525 $h = $this->PageInfo
[$l[0]]['size'][1];
1527 $h = ($this->DefOrientation
=='P') ?
$this->DefPageSize
[1]*$this->k
: $this->DefPageSize
[0]*$this->k
;
1528 $annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo
[$l[0]]['n'],$h-$l[1]*$this->k
);
1531 $this->_put($annots.']');
1533 if($this->WithAlpha
)
1534 $this->_put('/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
1535 $this->_put('/Contents '.($this->n+
1).' 0 R>>');
1536 $this->_put('endobj');
1538 if(!empty($this->AliasNbPages
))
1539 $this->pages
[$n] = str_replace($this->AliasNbPages
,$this->page
,$this->pages
[$n]);
1540 $this->_putstreamobject($this->pages
[$n]);
1543 protected function _putpages()
1546 for($n=1;$n<=$nb;$n++
)
1547 $this->PageInfo
[$n]['n'] = $this->n+
1+
2*($n-1);
1548 for($n=1;$n<=$nb;$n++
)
1549 $this->_putpage($n);
1552 $this->_put('<</Type /Pages');
1554 for($n=1;$n<=$nb;$n++
)
1555 $kids .= $this->PageInfo
[$n]['n'].' 0 R ';
1556 $this->_put($kids.']');
1557 $this->_put('/Count '.$nb);
1558 if($this->DefOrientation
=='P')
1560 $w = $this->DefPageSize
[0];
1561 $h = $this->DefPageSize
[1];
1565 $w = $this->DefPageSize
[1];
1566 $h = $this->DefPageSize
[0];
1568 $this->_put(sprintf('/MediaBox [0 0 %.2F %.2F]',$w*$this->k
,$h*$this->k
));
1570 $this->_put('endobj');
1573 protected function _putfonts()
1575 foreach($this->FontFiles
as $file=>$info)
1577 // Font file embedding
1579 $this->FontFiles
[$file]['n'] = $this->n
;
1580 $font = file_get_contents($this->fontpath
.$file,true);
1582 $this->Error('Font file not found: '.$file);
1583 $compressed = (substr($file,-2)=='.z');
1584 if(!$compressed && isset($info['length2']))
1585 $font = substr($font,6,$info['length1']).substr($font,6+
$info['length1']+
6,$info['length2']);
1586 $this->_put('<</Length '.strlen($font));
1588 $this->_put('/Filter /FlateDecode');
1589 $this->_put('/Length1 '.$info['length1']);
1590 if(isset($info['length2']))
1591 $this->_put('/Length2 '.$info['length2'].' /Length3 0');
1593 $this->_putstream($font);
1594 $this->_put('endobj');
1596 foreach($this->fonts
as $k=>$font)
1599 if(isset($font['diff']))
1601 if(!isset($this->encodings
[$font['enc']]))
1604 $this->_put('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$font['diff'].']>>');
1605 $this->_put('endobj');
1606 $this->encodings
[$font['enc']] = $this->n
;
1610 if(isset($font['uv']))
1612 if(isset($font['enc']))
1613 $cmapkey = $font['enc'];
1615 $cmapkey = $font['name'];
1616 if(!isset($this->cmaps
[$cmapkey]))
1618 $cmap = $this->_tounicodecmap($font['uv']);
1619 $this->_putstreamobject($cmap);
1620 $this->cmaps
[$cmapkey] = $this->n
;
1624 $this->fonts
[$k]['n'] = $this->n+
1;
1625 $type = $font['type'];
1626 $name = $font['name'];
1627 if($font['subsetted'])
1628 $name = 'AAAAAA+'.$name;
1633 $this->_put('<</Type /Font');
1634 $this->_put('/BaseFont /'.$name);
1635 $this->_put('/Subtype /Type1');
1636 if($name!='Symbol' && $name!='ZapfDingbats')
1637 $this->_put('/Encoding /WinAnsiEncoding');
1638 if(isset($font['uv']))
1639 $this->_put('/ToUnicode '.$this->cmaps
[$cmapkey].' 0 R');
1641 $this->_put('endobj');
1643 elseif($type=='Type1' ||
$type=='TrueType')
1645 // Additional Type1 or TrueType/OpenType font
1647 $this->_put('<</Type /Font');
1648 $this->_put('/BaseFont /'.$name);
1649 $this->_put('/Subtype /'.$type);
1650 $this->_put('/FirstChar 32 /LastChar 255');
1651 $this->_put('/Widths '.($this->n+
1).' 0 R');
1652 $this->_put('/FontDescriptor '.($this->n+
2).' 0 R');
1653 if(isset($font['diff']))
1654 $this->_put('/Encoding '.$this->encodings
[$font['enc']].' 0 R');
1656 $this->_put('/Encoding /WinAnsiEncoding');
1657 if(isset($font['uv']))
1658 $this->_put('/ToUnicode '.$this->cmaps
[$cmapkey].' 0 R');
1660 $this->_put('endobj');
1665 for($i=32;$i<=255;$i++
)
1666 $s .= $cw[chr($i)].' ';
1667 $this->_put($s.']');
1668 $this->_put('endobj');
1671 $s = '<</Type /FontDescriptor /FontName /'.$name;
1672 foreach($font['desc'] as $k=>$v)
1673 $s .= ' /'.$k.' '.$v;
1674 if(!empty($font['file']))
1675 $s .= ' /FontFile'.($type=='Type1' ?
'' : '2').' '.$this->FontFiles
[$font['file']]['n'].' 0 R';
1676 $this->_put($s.'>>');
1677 $this->_put('endobj');
1681 // Allow for additional types
1682 $mtd = '_put'.strtolower($type);
1683 if(!method_exists($this,$mtd))
1684 $this->Error('Unsupported font type: '.$type);
1690 protected function _tounicodecmap($uv)
1696 foreach($uv as $c=>$v)
1700 $ranges .= sprintf("<%02X> <%02X> <%04X>\n",$c,$c+
$v[1]-1,$v[0]);
1705 $chars .= sprintf("<%02X> <%04X>\n",$c,$v);
1709 $s = "/CIDInit /ProcSet findresource begin\n";
1710 $s .= "12 dict begin\n";
1711 $s .= "begincmap\n";
1712 $s .= "/CIDSystemInfo\n";
1713 $s .= "<</Registry (Adobe)\n";
1714 $s .= "/Ordering (UCS)\n";
1715 $s .= "/Supplement 0\n";
1717 $s .= "/CMapName /Adobe-Identity-UCS def\n";
1718 $s .= "/CMapType 2 def\n";
1719 $s .= "1 begincodespacerange\n";
1720 $s .= "<00> <FF>\n";
1721 $s .= "endcodespacerange\n";
1724 $s .= "$nbr beginbfrange\n";
1726 $s .= "endbfrange\n";
1730 $s .= "$nbc beginbfchar\n";
1732 $s .= "endbfchar\n";
1735 $s .= "CMapName currentdict /CMap defineresource pop\n";
1741 protected function _putimages()
1743 foreach(array_keys($this->images
) as $file)
1745 $this->_putimage($this->images
[$file]);
1746 unset($this->images
[$file]['data']);
1747 unset($this->images
[$file]['smask']);
1751 protected function _putimage(&$info)
1754 $info['n'] = $this->n
;
1755 $this->_put('<</Type /XObject');
1756 $this->_put('/Subtype /Image');
1757 $this->_put('/Width '.$info['w']);
1758 $this->_put('/Height '.$info['h']);
1759 if($info['cs']=='Indexed')
1760 $this->_put('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+
1).' 0 R]');
1763 $this->_put('/ColorSpace /'.$info['cs']);
1764 if($info['cs']=='DeviceCMYK')
1765 $this->_put('/Decode [1 0 1 0 1 0 1 0]');
1767 $this->_put('/BitsPerComponent '.$info['bpc']);
1768 if(isset($info['f']))
1769 $this->_put('/Filter /'.$info['f']);
1770 if(isset($info['dp']))
1771 $this->_put('/DecodeParms <<'.$info['dp'].'>>');
1772 if(isset($info['trns']) && is_array($info['trns']))
1775 for($i=0;$i<count($info['trns']);$i++
)
1776 $trns .= $info['trns'][$i].' '.$info['trns'][$i].' ';
1777 $this->_put('/Mask ['.$trns.']');
1779 if(isset($info['smask']))
1780 $this->_put('/SMask '.($this->n+
1).' 0 R');
1781 $this->_put('/Length '.strlen($info['data']).'>>');
1782 $this->_putstream($info['data']);
1783 $this->_put('endobj');
1785 if(isset($info['smask']))
1787 $dp = '/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '.$info['w'];
1788 $smask = array('w'=>$info['w'], 'h'=>$info['h'], 'cs'=>'DeviceGray', 'bpc'=>8, 'f'=>$info['f'], 'dp'=>$dp, 'data'=>$info['smask']);
1789 $this->_putimage($smask);
1792 if($info['cs']=='Indexed')
1793 $this->_putstreamobject($info['pal']);
1796 protected function _putxobjectdict()
1798 foreach($this->images
as $image)
1799 $this->_put('/I'.$image['i'].' '.$image['n'].' 0 R');
1802 protected function _putresourcedict()
1804 $this->_put('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
1805 $this->_put('/Font <<');
1806 foreach($this->fonts
as $font)
1807 $this->_put('/F'.$font['i'].' '.$font['n'].' 0 R');
1809 $this->_put('/XObject <<');
1810 $this->_putxobjectdict();
1814 protected function _putresources()
1817 $this->_putimages();
1818 // Resource dictionary
1821 $this->_putresourcedict();
1823 $this->_put('endobj');
1826 protected function _putinfo()
1828 $this->metadata
['Producer'] = 'FPDF '.FPDF_VERSION
;
1829 $this->metadata
['CreationDate'] = 'D:'.@date
('YmdHis');
1830 foreach($this->metadata
as $key=>$value)
1831 $this->_put('/'.$key.' '.$this->_textstring($value));
1834 protected function _putcatalog()
1836 $n = $this->PageInfo
[1]['n'];
1837 $this->_put('/Type /Catalog');
1838 $this->_put('/Pages 1 0 R');
1839 if($this->ZoomMode
=='fullpage')
1840 $this->_put('/OpenAction ['.$n.' 0 R /Fit]');
1841 elseif($this->ZoomMode
=='fullwidth')
1842 $this->_put('/OpenAction ['.$n.' 0 R /FitH null]');
1843 elseif($this->ZoomMode
=='real')
1844 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null 1]');
1845 elseif(!is_string($this->ZoomMode
))
1846 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null '.sprintf('%.2F',$this->ZoomMode
/100).']');
1847 if($this->LayoutMode
=='single')
1848 $this->_put('/PageLayout /SinglePage');
1849 elseif($this->LayoutMode
=='continuous')
1850 $this->_put('/PageLayout /OneColumn');
1851 elseif($this->LayoutMode
=='two')
1852 $this->_put('/PageLayout /TwoColumnLeft');
1855 protected function _putheader()
1857 $this->_put('%PDF-'.$this->PDFVersion
);
1860 protected function _puttrailer()
1862 $this->_put('/Size '.($this->n+
1));
1863 $this->_put('/Root '.$this->n
.' 0 R');
1864 $this->_put('/Info '.($this->n
-1).' 0 R');
1867 protected function _enddoc()
1869 $this->_putheader();
1871 $this->_putresources();
1877 $this->_put('endobj');
1881 $this->_putcatalog();
1883 $this->_put('endobj');
1885 $offset = $this->_getoffset();
1886 $this->_put('xref');
1887 $this->_put('0 '.($this->n+
1));
1888 $this->_put('0000000000 65535 f ');
1889 for($i=1;$i<=$this->n
;$i++
)
1890 $this->_put(sprintf('%010d 00000 n ',$this->offsets
[$i]));
1892 $this->_put('trailer');
1894 $this->_puttrailer();
1896 $this->_put('startxref');
1897 $this->_put($offset);
1898 $this->_put('%%EOF');