14const VERSION =
'1.33';
15protected $unifontSubset;
24protected $DefOrientation;
25protected $CurOrientation;
26protected $StdPageSizes;
27protected $DefPageSize;
28protected $CurPageSize;
29protected $CurRotation;
50protected $CurrentFont;
62protected $AutoPageBreak;
63protected $PageBreakTrigger;
66protected $AliasNbPages;
70protected $CreationDate;
77function __construct($orientation=
'P', $unit=
'mm',
$size=
'A4')
86 $this->pages = array();
87 $this->PageInfo = array();
88 $this->fonts = array();
89 $this->FontFiles = array();
90 $this->encodings = array();
91 $this->cmaps = array();
92 $this->images = array();
93 $this->links = array();
94 $this->InHeader =
false;
95 $this->InFooter =
false;
97 $this->FontFamily =
'';
98 $this->FontStyle =
'';
99 $this->FontSizePt = 12;
100 $this->underline =
false;
101 $this->DrawColor =
'0 G';
102 $this->FillColor =
'0 g';
103 $this->TextColor =
'0 g';
104 $this->ColorFlag =
false;
105 $this->WithAlpha =
false;
108 if(defined(
'FPDF_FONTPATH'))
110 $this->fontpath = FPDF_FONTPATH;
111 if(substr($this->fontpath,-1)!=
'/' && substr($this->fontpath,-1)!=
'\\')
112 $this->fontpath .=
'/';
114 elseif(is_dir(dirname(__FILE__).
'/font'))
115 $this->fontpath = dirname(__FILE__).
'/font/';
117 $this->fontpath =
'';
119 $this->CoreFonts = array(
'courier',
'helvetica',
'times',
'symbol',
'zapfdingbats');
130 $this->Error('Incorrect unit: '.$unit);
132 $this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28),
133 'letter'=>array(612,792), 'legal'=>array(612,1008));
135 $this->DefPageSize =
$size;
136 $this->CurPageSize =
$size;
138 $orientation = strtolower($orientation);
139 if($orientation=='
p' || $orientation=='portrait')
141 $this->DefOrientation =
'P';
145 elseif($orientation==
'l' || $orientation==
'landscape')
147 $this->DefOrientation =
'L';
152 $this->Error(
'Incorrect orientation: '.$orientation);
153 $this->CurOrientation = $this->DefOrientation;
154 $this->wPt = $this->w*$this->k;
155 $this->hPt = $this->
h*$this->k;
157 $this->CurRotation = 0;
159 $margin = 28.35/$this->k;
160 $this->SetMargins($margin,$margin);
162 $this->cMargin = $margin/10;
164 $this->LineWidth = .567/$this->k;
166 $this->SetAutoPageBreak(
true,2*$margin);
168 $this->SetDisplayMode(
'default');
170 $this->SetCompression(
true);
172 $this->metadata = array(
'Producer'=>
'tFPDF '.self::VERSION);
174 $this->PDFVersion =
'1.3';
177function SetMargins($left, $top, $right=
null)
180 $this->lMargin = $left;
181 $this->tMargin = $top;
184 $this->rMargin = $right;
187function SetLeftMargin($margin)
190 $this->lMargin = $margin;
191 if($this->page>0 && $this->x<$margin)
195function SetTopMargin($margin)
198 $this->tMargin = $margin;
201function SetRightMargin($margin)
204 $this->rMargin = $margin;
207function SetAutoPageBreak($auto, $margin=0)
210 $this->AutoPageBreak = $auto;
211 $this->bMargin = $margin;
212 $this->PageBreakTrigger = $this->
h-$margin;
215function SetDisplayMode($zoom, $layout=
'default')
218 if($zoom==
'fullpage' || $zoom==
'fullwidth' || $zoom==
'real' || $zoom==
'default' || !is_string($zoom))
219 $this->ZoomMode = $zoom;
221 $this->Error(
'Incorrect zoom display mode: '.$zoom);
222 if($layout==
'single' || $layout==
'continuous' || $layout==
'two' || $layout==
'default')
223 $this->LayoutMode = $layout;
225 $this->Error(
'Incorrect layout display mode: '.$layout);
228function SetCompression($compress)
231 if(function_exists(
'gzcompress'))
232 $this->compress = $compress;
234 $this->compress =
false;
237function SetTitle(
$title, $isUTF8=
false)
240 $this->metadata[
'Title'] = $isUTF8 ?
$title : $this->_UTF8encode(
$title);
243function SetAuthor($author, $isUTF8=
false)
246 $this->metadata[
'Author'] = $isUTF8 ? $author : $this->_UTF8encode($author);
249function SetSubject($subject, $isUTF8=
false)
252 $this->metadata[
'Subject'] = $isUTF8 ? $subject : $this->_UTF8encode($subject);
255function SetKeywords($keywords, $isUTF8=
false)
258 $this->metadata[
'Keywords'] = $isUTF8 ? $keywords : $this->_UTF8encode($keywords);
261function SetCreator($creator, $isUTF8=
false)
264 $this->metadata[
'Creator'] = $isUTF8 ? $creator : $this->_UTF8encode($creator);
267function AliasNbPages($alias=
'{nb}')
270 $this->AliasNbPages = $alias;
276 throw new Exception(
'tFPDF error: '.
$msg);
287 $this->InFooter =
true;
289 $this->InFooter =
false;
296function AddPage($orientation=
'',
$size=
'', $rotation=0)
300 $this->Error(
'The document is closed');
301 $family = $this->FontFamily;
302 $style = $this->FontStyle.($this->underline ?
'U' :
'');
303 $fontsize = $this->FontSizePt;
304 $lw = $this->LineWidth;
305 $dc = $this->DrawColor;
306 $fc = $this->FillColor;
307 $tc = $this->TextColor;
308 $cf = $this->ColorFlag;
312 $this->InFooter =
true;
314 $this->InFooter =
false;
319 $this->_beginpage($orientation,
$size,$rotation);
323 $this->LineWidth = $lw;
324 $this->_out(sprintf(
'%.2F w',$lw*$this->k));
327 $this->SetFont($family,
$style,$fontsize);
329 $this->DrawColor = $dc;
332 $this->FillColor = $fc;
335 $this->TextColor = $tc;
336 $this->ColorFlag = $cf;
338 $this->InHeader =
true;
340 $this->InHeader =
false;
342 if($this->LineWidth!=$lw)
344 $this->LineWidth = $lw;
345 $this->_out(sprintf(
'%.2F w',$lw*$this->k));
349 $this->SetFont($family,
$style,$fontsize);
351 if($this->DrawColor!=$dc)
353 $this->DrawColor = $dc;
356 if($this->FillColor!=$fc)
358 $this->FillColor = $fc;
361 $this->TextColor = $tc;
362 $this->ColorFlag = $cf;
381function SetDrawColor(
$r, $g=
null,
$b=
null)
384 if((
$r==0 && $g==0 &&
$b==0) || $g===
null)
385 $this->DrawColor = sprintf(
'%.3F G',
$r/255);
387 $this->DrawColor = sprintf(
'%.3F %.3F %.3F RG',
$r/255,$g/255,
$b/255);
389 $this->_out($this->DrawColor);
392function SetFillColor(
$r, $g=
null,
$b=
null)
395 if((
$r==0 && $g==0 &&
$b==0) || $g===
null)
396 $this->FillColor = sprintf(
'%.3F g',
$r/255);
398 $this->FillColor = sprintf(
'%.3F %.3F %.3F rg',
$r/255,$g/255,
$b/255);
399 $this->ColorFlag = ($this->FillColor!=$this->TextColor);
401 $this->_out($this->FillColor);
404function SetTextColor(
$r, $g=
null,
$b=
null)
407 if((
$r==0 && $g==0 &&
$b==0) || $g===
null)
408 $this->TextColor = sprintf(
'%.3F g',
$r/255);
410 $this->TextColor = sprintf(
'%.3F %.3F %.3F rg',
$r/255,$g/255,
$b/255);
411 $this->ColorFlag = ($this->FillColor!=$this->TextColor);
414function GetStringWidth(
$s)
418 $cw = $this->CurrentFont[
'cw'];
420 if ($this->unifontSubset) {
421 $unicode = $this->UTF8StringToArray(
$s);
422 foreach($unicode as $char) {
423 if (isset(
$cw[2*$char])) {
$w += (ord(
$cw[2*$char])<<8) + ord(
$cw[2*$char+1]); }
424 else if($char>0 && $char<128 && isset(
$cw[chr($char)])) {
$w +=
$cw[chr($char)]; }
425 else if(isset($this->CurrentFont[
'desc'][
'MissingWidth'])) {
$w += $this->CurrentFont[
'desc'][
'MissingWidth']; }
426 else if(isset($this->CurrentFont[
'MissingWidth'])) {
$w += $this->CurrentFont[
'MissingWidth']; }
435 return $w*$this->FontSize/1000;
438function SetLineWidth(
$width)
441 $this->LineWidth =
$width;
443 $this->_out(sprintf(
'%.2F w',
$width*$this->k));
446function Line($x1, $y1, $x2, $y2)
449 $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));
452function Rect($x, $y,
$w, $h,
$style=
'')
461 $this->_out(sprintf('%.2F %.2F %.2F %.2F re %s',$x*$this->k,($this->
h-$y)*$this->k,
$w*$this->k,-$h*$this->k,
$op));
464function AddFont($family,
$style='',
$file='', $uni=false)
467 $family = strtolower($family);
473 $file = str_replace(
' ',
'',$family).strtolower(
$style).
'.ttf';
476 $file = str_replace(
' ',
'',$family).strtolower(
$style).
'.php';
483 if (defined(
"_SYSTEM_TTFONTS") && file_exists(_SYSTEM_TTFONTS.$file )) { $ttffilename = _SYSTEM_TTFONTS.$file ; }
484 else { $ttffilename = $this->fontpath.
'unifont/'.
$file ; }
485 $unifilename = $this->fontpath.
'unifont/'.strtolower(substr(
$file ,0,(strpos(
$file ,
'.'))));
488 $ttfstat = stat($ttffilename);
489 if (file_exists($unifilename.
'.mtx.php')) {
490 include($unifilename.
'.mtx.php');
494 require_once($this->fontpath.
'unifont/ttfonts.php');
497 $cw = $ttf->charWidths;
498 $name = preg_replace(
'/[ ()]/',
'',$ttf->fullName);
500 $desc= array(
'Ascent'=>round($ttf->ascent),
501 'Descent'=>round($ttf->descent),
502 'CapHeight'=>round($ttf->capHeight),
503 'Flags'=>$ttf->flags,
504 'FontBBox'=>
'['.round($ttf->bbox[0]).
" ".round($ttf->bbox[1]).
" ".round($ttf->bbox[2]).
" ".round($ttf->bbox[3]).
']',
505 'ItalicAngle'=>$ttf->italicAngle,
506 'StemV'=>round($ttf->stemV),
507 'MissingWidth'=>round($ttf->defaultWidth));
508 $up = round($ttf->underlinePosition);
509 $ut = round($ttf->underlineThickness);
514 $s.=
'$name=\''.$name.
"';\n";
515 $s.=
'$type=\''.$type.
"';\n";
516 $s.=
'$desc='.var_export(
$desc,
true).
";\n";
517 $s.=
'$up='.$up.
";\n";
518 $s.=
'$ut='.$ut.
";\n";
519 $s.=
'$ttffile=\''.$ttffile.
"';\n";
520 $s.=
'$originalsize='.$originalsize.
";\n";
521 $s.=
'$fontkey=\''.$fontkey.
"';\n";
523 if (is_writable(dirname($this->fontpath.
'unifont/'.
'x'))) {
524 $fh = fopen($unifilename.
'.mtx.php',
"w");
525 fwrite($fh,
$s,strlen(
$s));
527 $fh = fopen($unifilename.
'.cw.dat',
"wb");
528 fwrite($fh,
$cw,strlen(
$cw));
530 @unlink($unifilename.
'.cw127.php');
535 $cw = @file_get_contents($unifilename.
'.cw.dat');
537 $i = count($this->fonts)+1;
538 if(!empty($this->AliasNbPages))
539 $sbarr = range(0,57);
541 $sbarr = range(0,32);
542 $this->fonts[
$fontkey] = array(
'i'=>
$i,
'type'=>
$type,
'name'=>
$name,
'desc'=>
$desc,
'up'=>
$up,
'ut'=>
$ut,
'cw'=>
$cw,
'ttffile'=>
$ttffile,
'fontkey'=>
$fontkey,
'subset'=>$sbarr,
'unifilename'=>$unifilename);
545 $this->FontFiles[
$file]=array(
'type'=>
"TTF");
549 $info = $this->_loadfont(
$file);
550 $info[
'i'] = count($this->fonts)+1;
551 if(!empty($info[
'file']))
554 if($info[
'type']==
'TrueType')
555 $this->FontFiles[$info[
'file']] = array(
'length1'=>$info[
'originalsize']);
557 $this->FontFiles[$info[
'file']] = array(
'length1'=>$info[
'size1'],
'length2'=>$info[
'size2']);
567 $family = $this->FontFamily;
569 $family = strtolower($family);
571 if(strpos(
$style,
'U')!==
false)
573 $this->underline =
true;
577 $this->underline =
false;
581 $size = $this->FontSizePt;
583 if($this->FontFamily==$family && $this->FontStyle==
$style && $this->FontSizePt==
$size)
592 $family =
'helvetica';
593 if(in_array($family,$this->CoreFonts))
595 if($family==
'symbol' || $family==
'zapfdingbats')
599 $this->AddFont($family,
$style);
602 $this->Error(
'Undefined font: '.$family.
' '.
$style);
605 $this->FontFamily = $family;
606 $this->FontStyle =
$style;
607 $this->FontSizePt =
$size;
608 $this->FontSize =
$size/$this->k;
609 $this->CurrentFont = &$this->fonts[
$fontkey];
610 if ($this->fonts[
$fontkey][
'type']==
'TTF') { $this->unifontSubset =
true; }
611 else { $this->unifontSubset =
false; }
613 $this->_out(sprintf(
'BT /F%d %.2F Tf ET',$this->CurrentFont[
'i'],$this->FontSizePt));
616function SetFontSize(
$size)
619 if($this->FontSizePt==
$size)
621 $this->FontSizePt =
$size;
622 $this->FontSize =
$size/$this->k;
624 $this->_out(sprintf(
'BT /F%d %.2F Tf ET',$this->CurrentFont[
'i'],$this->FontSizePt));
630 $n = count($this->links)+1;
631 $this->links[$n] = array(0, 0);
635function SetLink($link, $y=0,
$page=-1)
642 $this->links[$link] = array(
$page, $y);
645function Link($x, $y,
$w, $h, $link)
648 $this->PageLinks[
$this->page][] = array($x*$this->k, $this->hPt-$y*$this->k,
$w*$this->k, $h*$this->k, $link);
651function Text($x, $y, $txt)
655 if(!isset($this->CurrentFont))
656 $this->Error(
'No font has been set');
657 if ($this->unifontSubset)
659 $txt2 =
'('.$this->_escape($this->UTF8ToUTF16BE($txt,
false)).
')';
660 foreach($this->UTF8StringToArray($txt) as $uni)
661 $this->CurrentFont[
'subset'][$uni] = $uni;
664 $txt2 =
'('.$this->_escape($txt).
')';
665 $s = sprintf(
'BT %.2F %.2F Td %s Tj ET',$x*$this->k,($this->
h-$y)*$this->k,$txt2);
666 if($this->underline && $txt!=
'')
667 $s .=
' '.$this->_dounderline($x,$y,$txt);
669 $s =
'q '.$this->TextColor.
' '.
$s.
' Q';
673function AcceptPageBreak()
676 return $this->AutoPageBreak;
679function Cell(
$w, $h=0, $txt=
'', $border=0, $ln=0,
$align=
'', $fill=
false, $link=
'')
684 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
694 $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation);
699 $this->_out(sprintf(
'%.3F Tw',$ws*$k));
703 $w = $this->w-$this->rMargin-$this->x;
705 if($fill || $border==1)
708 $op = ($border==1) ?
'B' :
'f';
711 $s = sprintf(
'%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->
h-$this->y)*$k,
$w*$k,-$h*$k,
$op);
713 if(is_string($border))
717 if(strpos($border,
'L')!==
false)
718 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->
h-$y)*$k,$x*$k,($this->
h-($y+$h))*$k);
719 if(strpos($border,
'T')!==
false)
720 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->
h-$y)*$k,($x+
$w)*$k,($this->
h-$y)*$k);
721 if(strpos($border,
'R')!==
false)
722 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ',($x+
$w)*$k,($this->
h-$y)*$k,($x+
$w)*$k,($this->
h-($y+$h))*$k);
723 if(strpos($border,
'B')!==
false)
724 $s .= sprintf(
'%.2F %.2F m %.2F %.2F l S ',$x*$k,($this->
h-($y+$h))*$k,($x+
$w)*$k,($this->
h-($y+$h))*$k);
728 if(!isset($this->CurrentFont))
729 $this->Error(
'No font has been set');
731 $dx =
$w-$this->cMargin-$this->GetStringWidth($txt);
733 $dx = (
$w-$this->GetStringWidth($txt))/2;
735 $dx = $this->cMargin;
737 $s .= 'q '.$this->TextColor.' ';
739 if ($this->ws && $this->unifontSubset) {
740 foreach($this->UTF8StringToArray($txt) as $uni)
741 $this->CurrentFont[
'subset'][$uni] = $uni;
742 $space = $this->_escape($this->UTF8ToUTF16BE(
' ',
false));
743 $s .= sprintf(
'BT 0 Tw %.2F %.2F Td [',($this->x+$dx)*$k,($this->
h-($this->y+.5*$h+.3*$this->FontSize))*$k);
744 $t = explode(
' ',$txt);
748 $tx =
'('.$this->_escape($this->UTF8ToUTF16BE($tx,
false)).
')';
749 $s .= sprintf(
'%s ',$tx);
751 $adj = -($this->ws*$this->k)*1000/$this->FontSizePt;
752 $s .= sprintf(
'%d(%s) ',$adj,$space);
759 if ($this->unifontSubset)
761 $txt2 =
'('.$this->_escape($this->UTF8ToUTF16BE($txt,
false)).
')';
762 foreach($this->UTF8StringToArray($txt) as $uni)
763 $this->CurrentFont[
'subset'][$uni] = $uni;
766 $txt2=
'('.$this->_escape($txt).
')';
767 $s .= sprintf(
'BT %.2F %.2F Td %s Tj ET',($this->x+$dx)*$k,($this->
h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
770 $s .=
' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
774 $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
784 $this->x = $this->lMargin;
790function MultiCell(
$w, $h, $txt, $border=0,
$align=
'J', $fill=
false)
793 if(!isset($this->CurrentFont))
794 $this->Error(
'No font has been set');
795 $cw = $this->CurrentFont[
'cw'];
797 $w = $this->w-$this->rMargin-$this->x;
798 $wmax = (
$w-2*$this->cMargin);
800 $s = str_replace(
"\r",
'',(
string)$txt);
801 if ($this->unifontSubset) {
802 $nb=mb_strlen(
$s,
'utf-8');
803 while(
$nb>0 && mb_substr(
$s,
$nb-1,1,
'utf-8')==
"\n")
$nb--;
822 if(strpos($border,
'L')!==
false)
824 if(strpos($border,
'R')!==
false)
826 $b = (strpos($border,
'T')!==
false) ? $b2.
'T' : $b2;
838 if ($this->unifontSubset) {
839 $c = mb_substr(
$s,
$i,1,
'UTF-8');
852 if ($this->unifontSubset) {
853 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),
$b,2,
$align,$fill);
864 if($border && $nl==2)
875 if ($this->unifontSubset) {
$l += $this->GetStringWidth($c); }
876 else {
$l +=
$cw[$c]*$this->FontSize/1000; }
890 if ($this->unifontSubset) {
891 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),
$b,2,
$align,$fill);
901 $this->ws = ($ns>1) ? ($wmax-$ls)/($ns-1) : 0;
902 $this->_out(sprintf(
'%.3F Tw',$this->ws*$this->k));
904 if ($this->unifontSubset) {
917 if($border && $nl==2)
929 if($border && strpos($border,
'B')!==
false)
931 if ($this->unifontSubset) {
932 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),
$b,2,
$align,$fill);
937 $this->x = $this->lMargin;
940function Write($h, $txt, $link=
'')
943 if(!isset($this->CurrentFont))
944 $this->Error(
'No font has been set');
945 $cw = $this->CurrentFont[
'cw'];
946 $w = $this->w-$this->rMargin-$this->x;
947 $wmax = (
$w-2*$this->cMargin);
948 $s = str_replace(
"\r",
'',(
string)$txt);
949 if ($this->unifontSubset) {
950 $nb = mb_strlen(
$s,
'UTF-8');
951 if(
$nb==1 &&
$s==
" ") {
952 $this->x += $this->GetStringWidth(
$s);
967 if ($this->unifontSubset) {
968 $c = mb_substr(
$s,
$i,1,
'UTF-8');
976 if ($this->unifontSubset) {
977 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),0,2,
'',
false,$link);
980 $this->Cell(
$w,$h,substr(
$s,$j,
$i-$j),0,2,
'',
false,$link);
988 $this->x = $this->lMargin;
989 $w = $this->w-$this->rMargin-$this->x;
990 $wmax = (
$w-2*$this->cMargin);
998 if ($this->unifontSubset) {
$l += $this->GetStringWidth($c); }
999 else {
$l +=
$cw[$c]*$this->FontSize/1000; }
1006 if($this->x>$this->lMargin)
1009 $this->x = $this->lMargin;
1011 $w = $this->w-$this->rMargin-$this->x;
1012 $wmax = (
$w-2*$this->cMargin);
1019 if ($this->unifontSubset) {
1020 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),0,2,
'',
false,$link);
1023 $this->Cell(
$w,$h,substr(
$s,$j,
$i-$j),0,2,
'',
false,$link);
1028 if ($this->unifontSubset) {
1029 $this->Cell(
$w,$h,mb_substr(
$s,$j,
$sep-$j,
'UTF-8'),0,2,
'',
false,$link);
1032 $this->Cell(
$w,$h,substr(
$s,$j,
$sep-$j),0,2,
'',
false,$link);
1041 $this->x = $this->lMargin;
1042 $w = $this->w-$this->rMargin-$this->x;
1043 $wmax = (
$w-2*$this->cMargin);
1052 if ($this->unifontSubset) {
1053 $this->Cell(
$l,$h,mb_substr(
$s,$j,
$i-$j,
'UTF-8'),0,0,
'',
false,$link);
1056 $this->Cell(
$l,$h,substr(
$s,$j),0,0,
'',
false,$link);
1064 $this->x = $this->lMargin;
1066 $this->y += $this->lasth;
1071function Image(
$file, $x=
null, $y=
null,
$w=0, $h=0,
$type=
'', $link=
'')
1075 $this->Error(
'Image file name is empty');
1076 if(!isset($this->images[
$file]))
1083 $this->Error(
'Image file has no extension and no type was specified: '.
$file);
1089 $mtd =
'_parse'.$type;
1090 if(!method_exists($this,$mtd))
1091 $this->Error(
'Unsupported image type: '.
$type);
1092 $info = $this->$mtd(
$file);
1093 $info[
'i'] = count($this->images)+1;
1094 $this->images[
$file] = $info;
1097 $info = $this->images[
$file];
1107 $w = -$info[
'w']*72/
$w/$this->k;
1109 $h = -$info[
'h']*72/$h/$this->k;
1111 $w = $h*$info[
'w']/$info[
'h'];
1113 $h =
$w*$info[
'h']/$info[
'w'];
1118 if($this->y+$h>$this->PageBreakTrigger && !$this->InHeader && !$this->InFooter && $this->AcceptPageBreak())
1122 $this->AddPage($this->CurOrientation,$this->CurPageSize,$this->CurRotation);
1131 $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']));
1133 $this->Link($x,$y,
$w,$h,$link);
1136function GetPageWidth()
1142function GetPageHeight()
1160 $this->x = $this->w+$x;
1169function SetY($y, $resetX=
true)
1175 $this->y = $this->
h+$y;
1177 $this->x = $this->lMargin;
1180function SetXY($x, $y)
1184 $this->SetY($y,
false);
1187function Output(
$dest=
'',
$name=
'', $isUTF8=
false)
1202 switch(strtoupper(
$dest))
1206 $this->_checkoutput();
1210 header(
'Content-Type: application/pdf');
1211 header(
'Content-Disposition: inline; '.$this->_httpencode(
'filename',
$name,$isUTF8));
1212 header(
'Cache-Control: private, max-age=0, must-revalidate');
1213 header(
'Pragma: public');
1219 $this->_checkoutput();
1220 header(
'Content-Type: application/pdf');
1221 header(
'Content-Disposition: attachment; '.$this->_httpencode(
'filename',
$name,$isUTF8));
1222 header(
'Cache-Control: private, max-age=0, must-revalidate');
1223 header(
'Pragma: public');
1228 if(!file_put_contents(
$name,$this->buffer))
1229 $this->Error(
'Unable to create output file: '.
$name);
1233 return $this->buffer;
1235 $this->Error(
'Incorrect output destination: '.
$dest);
1244protected function _dochecks()
1247 if(!function_exists(
'mb_strlen'))
1248 $this->Error(
'mbstring extension is not available');
1251protected function _checkoutput()
1256 $this->Error(
"Some data has already been output, can't send PDF file (output started at $file:$line)");
1261 if(preg_match(
'/^(\xEF\xBB\xBF)?\s*$/',ob_get_contents()))
1267 $this->Error(
"Some data has already been output, can't send PDF file");
1271protected function _getpagesize(
$size)
1273 if(is_string(
$size))
1276 if(!isset($this->StdPageSizes[
$size]))
1277 $this->Error(
'Unknown page size: '.
$size);
1278 $a = $this->StdPageSizes[
$size];
1279 return array(
$a[0]/$this->k,
$a[1]/$this->k);
1290protected function _beginpage($orientation,
$size, $rotation)
1296 $this->x = $this->lMargin;
1297 $this->y = $this->tMargin;
1298 $this->FontFamily =
'';
1300 if($orientation==
'')
1301 $orientation = $this->DefOrientation;
1303 $orientation = strtoupper($orientation[0]);
1305 $size = $this->DefPageSize;
1308 if($orientation!=$this->CurOrientation ||
$size[0]!=$this->CurPageSize[0] ||
$size[1]!=$this->CurPageSize[1])
1311 if($orientation==
'P')
1313 $this->w =
$size[0];
1318 $this->w =
$size[1];
1321 $this->wPt = $this->w*$this->k;
1322 $this->hPt = $this->
h*$this->k;
1323 $this->PageBreakTrigger = $this->
h-$this->bMargin;
1324 $this->CurOrientation = $orientation;
1325 $this->CurPageSize =
$size;
1327 if($orientation!=$this->DefOrientation ||
$size[0]!=$this->DefPageSize[0] ||
$size[1]!=$this->DefPageSize[1])
1328 $this->PageInfo[
$this->page][
'size'] = array($this->wPt, $this->hPt);
1332 $this->Error(
'Incorrect rotation value: '.$rotation);
1333 $this->PageInfo[
$this->page][
'rotation'] = $rotation;
1335 $this->CurRotation = $rotation;
1338protected function _endpage()
1343protected function _loadfont($font)
1346 if(strpos($font,
'/')!==
false || strpos($font,
"\\")!==
false)
1347 $this->Error(
'Incorrect font definition file name: '.$font);
1348 include($this->fontpath.$font);
1350 $this->Error(
'Could not include font definition file');
1352 $enc = strtolower($enc);
1353 if(!isset($subsetted))
1355 return get_defined_vars();
1358protected function _isascii(
$s)
1370protected function _httpencode($param,
$value, $isUTF8)
1373 if($this->_isascii(
$value))
1374 return $param.
'="'.
$value.
'"';
1377 return $param.
"*=UTF-8''".rawurlencode(
$value);
1380protected function _UTF8encode(
$s)
1383 return mb_convert_encoding(
$s,
'UTF-8',
'ISO-8859-1');
1386protected function _UTF8toUTF16(
$s)
1389 return "\xFE\xFF".mb_convert_encoding(
$s,
'UTF-16BE',
'UTF-8');
1392protected function _escape(
$s)
1395 if(strpos(
$s,
'(')!==
false || strpos(
$s,
')')!==
false || strpos(
$s,
'\\')!==
false || strpos(
$s,
"\r")!==
false)
1396 return str_replace(array(
'\\',
'(',
')',
"\r"), array(
'\\\\',
'\\(',
'\\)',
'\\r'),
$s);
1401protected function _textstring(
$s)
1404 if(!$this->_isascii(
$s))
1405 $s = $this->_UTF8toUTF16(
$s);
1406 return '('.$this->_escape(
$s).
')';
1409protected function _dounderline($x, $y, $txt)
1412 $up = $this->CurrentFont[
'up'];
1413 $ut = $this->CurrentFont[
'ut'];
1414 $w = $this->GetStringWidth($txt)+$this->ws*substr_count($txt,
' ');
1415 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);
1418protected function _parsejpg(
$file)
1423 $this->Error(
'Missing or incorrect image file: '.
$file);
1425 $this->Error(
'Not a JPEG file: '.
$file);
1426 if(!isset(
$a[
'channels']) ||
$a[
'channels']==3)
1427 $colspace =
'DeviceRGB';
1429 $colspace = 'DeviceCMYK';
1431 $colspace = 'DeviceGray';
1432 $bpc = isset(
$a['bits']) ?
$a['bits'] : 8;
1434 return array('w'=>
$a[0], '
h'=>
$a[1], 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'DCTDecode', 'data'=>
$data);
1437protected function _parsepng(
$file)
1442 $this->Error(
'Can\'t open image file: '.
$file);
1443 $info = $this->_parsepngstream(
$f,
$file);
1448protected function _parsepngstream(
$f,
$file)
1451 if($this->_readstream(
$f,8)!=chr(137).
'PNG'.chr(13).chr(10).chr(26).chr(10))
1452 $this->Error(
'Not a PNG file: '.
$file);
1455 $this->_readstream(
$f,4);
1456 if($this->_readstream(
$f,4)!=
'IHDR')
1457 $this->Error(
'Incorrect PNG file: '.
$file);
1458 $w = $this->_readint(
$f);
1459 $h = $this->_readint(
$f);
1460 $bpc = ord($this->_readstream(
$f,1));
1462 $this->Error(
'16-bit depth not supported: '.
$file);
1463 $ct = ord($this->_readstream(
$f,1));
1464 if($ct==0 || $ct==4)
1465 $colspace =
'DeviceGray';
1467 $colspace = 'DeviceRGB';
1469 $colspace = 'Indexed';
1471 $this->Error('Unknown color
type: '.
$file);
1472 if(ord($this->_readstream(
$f,1))!=0)
1473 $this->Error('Unknown compression method: '.
$file);
1474 if(ord($this->_readstream(
$f,1))!=0)
1475 $this->Error('Unknown filter method: '.
$file);
1476 if(ord($this->_readstream(
$f,1))!=0)
1477 $this->Error('Interlacing not supported: '.
$file);
1478 $this->_readstream(
$f,4);
1479 $dp = '/Predictor 15 /Colors '.($colspace=='DeviceRGB' ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.
$w;
1487 $n = $this->_readint(
$f);
1488 $type = $this->_readstream(
$f,4);
1492 $pal = $this->_readstream(
$f,$n);
1493 $this->_readstream(
$f,4);
1498 $t = $this->_readstream(
$f,$n);
1500 $trns = array(ord(substr($t,1,1)));
1502 $trns = array(ord(substr($t,1,1)), ord(substr($t,3,1)), ord(substr($t,5,1)));
1505 $pos = strpos($t,chr(0));
1507 $trns = array(
$pos);
1509 $this->_readstream(
$f,4);
1514 $data .= $this->_readstream(
$f,$n);
1515 $this->_readstream(
$f,4);
1520 $this->_readstream(
$f,$n+4);
1524 if($colspace=='Indexed' && empty($pal))
1525 $this->Error('Missing palette in '.
$file);
1526 $info = array('w'=>
$w, '
h'=>$h, 'cs'=>$colspace, 'bpc'=>$bpc, 'f'=>'FlateDecode', 'dp'=>$dp, 'pal'=>$pal, 'trns'=>$trns);
1530 if(!function_exists(
'gzuncompress'))
1531 $this->Error(
'Zlib not available, can\'t handle alpha channel: '.
$file);
1546 $alpha .= preg_replace(
'/.(.)/s',
'$1',
$line);
1560 $alpha .= preg_replace(
'/.{3}(.)/s',
'$1',
$line);
1565 $info[
'smask'] = gzcompress($alpha);
1566 $this->WithAlpha =
true;
1567 if($this->PDFVersion<
'1.4')
1568 $this->PDFVersion =
'1.4';
1570 $info[
'data'] =
$data;
1574protected function _readstream(
$f, $n)
1578 while($n>0 && !feof(
$f))
1582 $this->Error(
'Error while reading stream');
1587 $this->Error(
'Unexpected end of stream');
1591protected function _readint(
$f)
1594 $a = unpack(
'Ni',$this->_readstream(
$f,4));
1598protected function _parsegif(
$file)
1601 if(!function_exists(
'imagepng'))
1602 $this->Error(
'GD extension is required for GIF support');
1603 if(!function_exists(
'imagecreatefromgif'))
1604 $this->Error(
'GD has no GIF read support');
1605 $im = imagecreatefromgif(
$file);
1607 $this->Error(
'Missing or incorrect image file: '.
$file);
1608 imageinterlace($im,0);
1611 $data = ob_get_clean();
1613 $f = fopen(
'php://temp',
'rb+');
1615 $this->Error(
'Unable to create memory stream');
1618 $info = $this->_parsepngstream(
$f,
$file);
1623protected function _out(
$s)
1631 $this->Error('No page has been added yet');
1633 $this->Error('The document is closed');
1636protected function _put(
$s)
1638 $this->buffer .=
$s.
"\n";
1641protected function _getoffset()
1643 return strlen($this->buffer);
1646protected function _newobj($n=
null)
1651 $this->offsets[$n] = $this->_getoffset();
1652 $this->_put($n.
' 0 obj');
1655protected function _putstream(
$data)
1657 $this->_put(
'stream');
1659 $this->_put(
'endstream');
1662protected function _putstreamobject(
$data)
1666 $entries =
'/Filter /FlateDecode ';
1671 $entries .=
'/Length '.strlen(
$data);
1673 $this->_put(
'<<'.$entries.
'>>');
1674 $this->_putstream(
$data);
1675 $this->_put(
'endobj');
1678protected function _putlinks($n)
1680 foreach($this->PageLinks[$n] as $pl)
1683 $rect = sprintf(
'%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
1684 $s =
'<</Type /Annot /Subtype /Link /Rect ['.$rect.
'] /Border [0 0 0] ';
1685 if(is_string($pl[4]))
1686 $s .=
'/A <</S /URI /URI '.$this->_textstring($pl[4]).
'>>>>';
1689 $l = $this->links[$pl[4]];
1690 if(isset($this->PageInfo[
$l[0]][
'size']))
1691 $h = $this->PageInfo[
$l[0]][
'size'][1];
1693 $h = ($this->DefOrientation==
'P') ? $this->DefPageSize[1]*$this->k : $this->DefPageSize[0]*$this->k;
1694 $s .= sprintf(
'/Dest [%d 0 R /XYZ 0 %.2F null]>>',$this->PageInfo[
$l[0]][
'n'],$h-
$l[1]*$this->k);
1697 $this->_put(
'endobj');
1701protected function _putpage($n)
1704 $this->_put(
'<</Type /Page');
1705 $this->_put(
'/Parent 1 0 R');
1706 if(isset($this->PageInfo[$n][
'size']))
1707 $this->_put(sprintf(
'/MediaBox [0 0 %.2F %.2F]',$this->PageInfo[$n][
'size'][0],$this->PageInfo[$n][
'size'][1]));
1708 if(isset($this->PageInfo[$n][
'rotation']))
1709 $this->_put(
'/Rotate '.$this->PageInfo[$n][
'rotation']);
1710 $this->_put(
'/Resources 2 0 R');
1711 if(!empty($this->PageLinks[$n]))
1714 foreach($this->PageLinks[$n] as $pl)
1715 $s .= $pl[5].
' 0 R ';
1719 if($this->WithAlpha)
1720 $this->_put(
'/Group <</Type /Group /S /Transparency /CS /DeviceRGB>>');
1721 $this->_put(
'/Contents '.($this->
n+1).
' 0 R>>');
1722 $this->_put(
'endobj');
1724 if(!empty($this->AliasNbPages)) {
1725 $alias = $this->UTF8ToUTF16BE($this->AliasNbPages,
false);
1726 $r = $this->UTF8ToUTF16BE($this->page,
false);
1727 $this->pages[$n] = str_replace($alias,
$r,$this->pages[$n]);
1729 $this->pages[$n] = str_replace($this->AliasNbPages,$this->page,$this->pages[$n]);
1731 $this->_putstreamobject($this->pages[$n]);
1733 $this->_putlinks($n);
1736protected function _putpages()
1742 $this->PageInfo[
$i][
'n'] = ++$n;
1744 foreach($this->PageLinks[
$i] as &$pl)
1749 $this->_putpage(
$i);
1752 $this->_put(
'<</Type /Pages');
1755 $kids .= $this->PageInfo[
$i][
'n'].
' 0 R ';
1758 $this->_put(
'/Count '.
$nb);
1759 if($this->DefOrientation==
'P')
1761 $w = $this->DefPageSize[0];
1762 $h = $this->DefPageSize[1];
1766 $w = $this->DefPageSize[1];
1767 $h = $this->DefPageSize[0];
1769 $this->_put(sprintf(
'/MediaBox [0 0 %.2F %.2F]',
$w*$this->k,$h*$this->k));
1771 $this->_put(
'endobj');
1774protected function _putfonts()
1776 foreach($this->FontFiles as
$file=>$info)
1778 if (!isset($info[
'type']) || $info[
'type']!=
'TTF') {
1781 $this->FontFiles[
$file][
'n'] = $this->n;
1782 $font = file_get_contents($this->fontpath.$file,
true);
1784 $this->Error(
'Font file not found: '.
$file);
1785 $compressed = (substr(
$file,-2)==
'.z');
1786 if(!$compressed && isset($info[
'length2']))
1787 $font = substr($font,6,$info[
'length1']).substr($font,6+$info[
'length1']+6,$info[
'length2']);
1788 $this->_put(
'<</Length '.strlen($font));
1790 $this->_put(
'/Filter /FlateDecode');
1791 $this->_put(
'/Length1 '.$info[
'length1']);
1792 if(isset($info[
'length2']))
1793 $this->_put(
'/Length2 '.$info[
'length2'].
' /Length3 0');
1795 $this->_putstream($font);
1796 $this->_put(
'endobj');
1799 foreach($this->fonts as $k=>$font)
1802 if(isset($font[
'diff']))
1804 if(!isset($this->encodings[$font[
'enc']]))
1807 $this->_put(
'<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$font[
'diff'].
']>>');
1808 $this->_put(
'endobj');
1809 $this->encodings[$font[
'enc']] = $this->n;
1813 if(isset($font[
'uv']))
1815 if(isset($font[
'enc']))
1816 $cmapkey = $font[
'enc'];
1818 $cmapkey = $font[
'name'];
1819 if(!isset($this->cmaps[$cmapkey]))
1821 $cmap = $this->_tounicodecmap($font[
'uv']);
1822 $this->_putstreamobject($cmap);
1823 $this->cmaps[$cmapkey] = $this->n;
1827 $type = $font[
'type'];
1828 $name = $font[
'name'];
1832 $this->fonts[$k][
'n'] = $this->
n+1;
1834 $this->_put(
'<</Type /Font');
1835 $this->_put(
'/BaseFont /'.
$name);
1836 $this->_put(
'/Subtype /Type1');
1838 $this->_put(
'/Encoding /WinAnsiEncoding');
1839 if(isset($font[
'uv']))
1840 $this->_put(
'/ToUnicode '.$this->cmaps[$cmapkey].
' 0 R');
1842 $this->_put(
'endobj');
1847 if(isset($font[
'subsetted']) && $font[
'subsetted'])
1848 $name =
'AAAAAA+'.$name;
1849 $this->fonts[$k][
'n'] = $this->
n+1;
1851 $this->_put(
'<</Type /Font');
1852 $this->_put(
'/BaseFont /'.
$name);
1853 $this->_put(
'/Subtype /'.
$type);
1854 $this->_put(
'/FirstChar 32 /LastChar 255');
1855 $this->_put(
'/Widths '.($this->
n+1).
' 0 R');
1856 $this->_put(
'/FontDescriptor '.($this->
n+2).
' 0 R');
1860 if(isset($font[
'diff']))
1861 $this->_put(
'/Encoding '.$this->encodings[$font[
'enc']].
' 0 R');
1863 $this->_put(
'/Encoding /WinAnsiEncoding');
1866 if(isset($font[
'uv']))
1867 $this->_put(
'/ToUnicode '.$this->cmaps[$cmapkey].
' 0 R');
1869 $this->_put(
'endobj');
1876 $this->_put(
$s.
']');
1877 $this->_put(
'endobj');
1880 $s =
'<</Type /FontDescriptor /FontName /'.$name;
1881 foreach($font[
'desc'] as $k=>$v)
1882 $s .=
' /'.$k.
' '.$v;
1884 if(!empty($font[
'file']))
1885 $s .=
' /FontFile'.($type==
'Type1' ?
'' :
'2').
' '.$this->FontFiles[$font[
'file']][
'n'].
' 0 R';
1886 $this->_put(
$s.
'>>');
1887 $this->_put(
'endobj');
1890 else if (
$type==
'TTF') {
1891 $this->fonts[$k][
'n']=$this->
n+1;
1892 require_once($this->fontpath.
'unifont/ttfonts.php');
1894 $fontname =
'MPDFAA'.
'+'.$font[
'name'];
1895 $subset = $font[
'subset'];
1897 $ttfontstream = $ttf->makeSubset($font[
'ttffile'], $subset);
1898 $ttfontsize = strlen($ttfontstream);
1899 $fontstream = gzcompress($ttfontstream);
1900 $codeToGlyph = $ttf->codeToGlyph;
1901 unset($codeToGlyph[0]);
1906 $this->_put(
'<</Type /Font');
1907 $this->_put(
'/Subtype /Type0');
1908 $this->_put(
'/BaseFont /'.$fontname.
'');
1909 $this->_put(
'/Encoding /Identity-H');
1910 $this->_put(
'/DescendantFonts ['.($this->
n + 1).
' 0 R]');
1911 $this->_put(
'/ToUnicode '.($this->
n + 2).
' 0 R');
1913 $this->_put(
'endobj');
1918 $this->_put(
'<</Type /Font');
1919 $this->_put(
'/Subtype /CIDFontType2');
1920 $this->_put(
'/BaseFont /'.$fontname.
'');
1921 $this->_put(
'/CIDSystemInfo '.($this->
n + 2).
' 0 R');
1922 $this->_put(
'/FontDescriptor '.($this->
n + 3).
' 0 R');
1923 if (isset($font[
'desc'][
'MissingWidth'])){
1924 $this->_out(
'/DW '.$font[
'desc'][
'MissingWidth'].
'');
1927 $this->_putTTfontwidths($font, $ttf->maxUni);
1929 $this->_put(
'/CIDToGIDMap '.($this->
n + 4).
' 0 R');
1931 $this->_put(
'endobj');
1935 $toUni =
"/CIDInit /ProcSet findresource begin\n";
1936 $toUni .=
"12 dict begin\n";
1937 $toUni .=
"begincmap\n";
1938 $toUni .=
"/CIDSystemInfo\n";
1939 $toUni .=
"<</Registry (Adobe)\n";
1940 $toUni .=
"/Ordering (UCS)\n";
1941 $toUni .=
"/Supplement 0\n";
1942 $toUni .=
">> def\n";
1943 $toUni .=
"/CMapName /Adobe-Identity-UCS def\n";
1944 $toUni .=
"/CMapType 2 def\n";
1945 $toUni .=
"1 begincodespacerange\n";
1946 $toUni .=
"<0000> <FFFF>\n";
1947 $toUni .=
"endcodespacerange\n";
1948 $toUni .=
"1 beginbfrange\n";
1949 $toUni .=
"<0000> <FFFF> <0000>\n";
1950 $toUni .=
"endbfrange\n";
1951 $toUni .=
"endcmap\n";
1952 $toUni .=
"CMapName currentdict /CMap defineresource pop\n";
1955 $this->_put(
'<</Length '.(strlen($toUni)).
'>>');
1956 $this->_putstream($toUni);
1957 $this->_put(
'endobj');
1961 $this->_put(
'<</Registry (Adobe)');
1962 $this->_put(
'/Ordering (UCS)');
1963 $this->_put(
'/Supplement 0');
1965 $this->_put(
'endobj');
1969 $this->_put(
'<</Type /FontDescriptor');
1970 $this->_put(
'/FontName /'.$fontname);
1971 foreach($font[
'desc'] as $kd=>$v) {
1972 if ($kd ==
'Flags') { $v = $v | 4; $v = $v & ~32; }
1973 $this->_out(
' /'.$kd.
' '.$v);
1975 $this->_put(
'/FontFile2 '.($this->
n + 2).
' 0 R');
1977 $this->_put(
'endobj');
1982 $cidtogidmap = str_pad(
'', 256*256*2,
"\x00");
1983 foreach($codeToGlyph as $cc=>$glyph) {
1984 $cidtogidmap[$cc*2] = chr($glyph >> 8);
1985 $cidtogidmap[$cc*2 + 1] = chr($glyph & 0xFF);
1987 $cidtogidmap = gzcompress($cidtogidmap);
1989 $this->_put(
'<</Length '.strlen($cidtogidmap).
'');
1990 $this->_put(
'/Filter /FlateDecode');
1992 $this->_putstream($cidtogidmap);
1993 $this->_put(
'endobj');
1997 $this->_put(
'<</Length '.strlen($fontstream));
1998 $this->_put(
'/Filter /FlateDecode');
1999 $this->_put(
'/Length1 '.$ttfontsize);
2001 $this->_putstream($fontstream);
2002 $this->_put(
'endobj');
2008 $this->fonts[$k][
'n'] = $this->
n+1;
2009 $mtd =
'_put'.strtolower(
$type);
2010 if(!method_exists($this,$mtd))
2011 $this->Error(
'Unsupported font type: '.
$type);
2017protected function _putTTfontwidths($font, $maxUni) {
2018 if (file_exists($font[
'unifilename'].
'.cw127.php')) {
2019 include($font[
'unifilename'].
'.cw127.php') ;
2030 $cwlen = $maxUni + 1;
2033 for ($cid=$startcid; $cid<$cwlen; $cid++) {
2034 if ($cid==128 && (!file_exists($font[
'unifilename'].
'.cw127.php'))) {
2035 if (is_writable(dirname($this->fontpath.
'unifont/x'))) {
2036 $fh = fopen($font[
'unifilename'].
'.cw127.php',
"wb");
2037 $cw127=
'<?php'.
"\n";
2038 $cw127.=
'$rangeid='.$rangeid.
";\n";
2039 $cw127.=
'$prevcid='.$prevcid.
";\n";
2040 $cw127.=
'$prevwidth='.$prevwidth.
";\n";
2041 if (
$interval) { $cw127.=
'$interval=true'.
";\n"; }
2042 else { $cw127.=
'$interval=false'.
";\n"; }
2043 $cw127.=
'$range='.var_export(
$range,
true).
";\n";
2045 fwrite($fh,$cw127,strlen($cw127));
2049 if ((!isset($font[
'cw'][$cid*2]) || !isset($font[
'cw'][$cid*2+1])) ||
2050 ($font[
'cw'][$cid*2] ==
"\00" && $font[
'cw'][$cid*2+1] ==
"\00")) {
continue; }
2052 $width = (ord($font[
'cw'][$cid*2]) << 8) + ord($font[
'cw'][$cid*2+1]);
2054 if ($cid > 255 && (!isset($font[
'subset'][$cid]) || !$font[
'subset'][$cid])) {
continue; }
2055 if (!isset($font[
'dw']) || (isset($font[
'dw']) &&
$width != $font[
'dw'])) {
2094 foreach (
$range as $k => $ws) {
2096 if (($k == $nextk) AND (!$prevint) AND ((!isset($ws[
'interval'])) OR ($cws < 4))) {
2097 if (isset(
$range[$k][
'interval'])) { unset(
$range[$k][
'interval']); }
2101 else { $prevk = $k; }
2103 if (isset($ws[
'interval'])) {
2104 if ($cws > 3) { $prevint =
true; }
2105 else { $prevint =
false; }
2106 unset(
$range[$k][
'interval']);
2109 else { $prevint =
false; }
2112 foreach (
$range as $k => $ws) {
2113 if (count(array_count_values($ws)) == 1) {
$w .=
' '.$k.
' '.($k + count($ws) - 1).
' '.$ws[0]; }
2114 else {
$w .=
' '.$k.
' [ '.implode(
' ', $ws).
' ]' .
"\n"; }
2116 $this->_out(
'/W ['.
$w.
' ]');
2119protected function _tounicodecmap($uv)
2125 foreach($uv as $c=>$v)
2129 $ranges .= sprintf(
"<%02X> <%02X> <%04X>\n",$c,$c+$v[1]-1,$v[0]);
2134 $chars .= sprintf(
"<%02X> <%04X>\n",$c,$v);
2138 $s =
"/CIDInit /ProcSet findresource begin\n";
2139 $s .=
"12 dict begin\n";
2140 $s .=
"begincmap\n";
2141 $s .=
"/CIDSystemInfo\n";
2142 $s .=
"<</Registry (Adobe)\n";
2143 $s .=
"/Ordering (UCS)\n";
2144 $s .=
"/Supplement 0\n";
2146 $s .=
"/CMapName /Adobe-Identity-UCS def\n";
2147 $s .=
"/CMapType 2 def\n";
2148 $s .=
"1 begincodespacerange\n";
2149 $s .=
"<00> <FF>\n";
2150 $s .=
"endcodespacerange\n";
2153 $s .=
"$nbr beginbfrange\n";
2155 $s .=
"endbfrange\n";
2159 $s .=
"$nbc beginbfchar\n";
2161 $s .=
"endbfchar\n";
2164 $s .=
"CMapName currentdict /CMap defineresource pop\n";
2170protected function _putimages()
2172 foreach(array_keys($this->images) as
$file)
2174 $this->_putimage($this->images[
$file]);
2175 unset($this->images[
$file][
'data']);
2176 unset($this->images[
$file][
'smask']);
2180protected function _putimage(&$info)
2183 $info[
'n'] = $this->n;
2184 $this->_put(
'<</Type /XObject');
2185 $this->_put(
'/Subtype /Image');
2186 $this->_put(
'/Width '.$info[
'w']);
2187 $this->_put(
'/Height '.$info[
'h']);
2188 if($info[
'cs']==
'Indexed')
2189 $this->_put(
'/ColorSpace [/Indexed /DeviceRGB '.(strlen($info[
'pal'])/3-1).
' '.($this->
n+1).
' 0 R]');
2192 $this->_put(
'/ColorSpace /'.$info[
'cs']);
2193 if($info[
'cs']==
'DeviceCMYK')
2194 $this->_put(
'/Decode [1 0 1 0 1 0 1 0]');
2196 $this->_put(
'/BitsPerComponent '.$info[
'bpc']);
2197 if(isset($info[
'f']))
2198 $this->_put(
'/Filter /'.$info[
'f']);
2199 if(isset($info[
'dp']))
2200 $this->_put(
'/DecodeParms <<'.$info[
'dp'].
'>>');
2201 if(isset($info[
'trns']) && is_array($info[
'trns']))
2204 for(
$i=0;
$i<count($info[
'trns']);
$i++)
2205 $trns .= $info[
'trns'][
$i].
' '.$info[
'trns'][
$i].
' ';
2206 $this->_put(
'/Mask ['.$trns.
']');
2208 if(isset($info[
'smask']))
2209 $this->_put(
'/SMask '.($this->
n+1).
' 0 R');
2210 $this->_put(
'/Length '.strlen($info[
'data']).
'>>');
2211 $this->_putstream($info[
'data']);
2212 $this->_put(
'endobj');
2214 if(isset($info[
'smask']))
2216 $dp =
'/Predictor 15 /Colors 1 /BitsPerComponent 8 /Columns '.$info[
'w'];
2217 $smask = array(
'w'=>$info[
'w'],
'h'=>$info[
'h'],
'cs'=>
'DeviceGray',
'bpc'=>8,
'f'=>$info[
'f'],
'dp'=>$dp,
'data'=>$info[
'smask']);
2218 $this->_putimage($smask);
2221 if($info[
'cs']==
'Indexed')
2222 $this->_putstreamobject($info[
'pal']);
2225protected function _putxobjectdict()
2227 foreach($this->images as $image)
2228 $this->_put(
'/I'.$image[
'i'].
' '.$image[
'n'].
' 0 R');
2231protected function _putresourcedict()
2233 $this->_put(
'/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
2234 $this->_put(
'/Font <<');
2235 foreach($this->fonts as $font)
2236 $this->_put(
'/F'.$font[
'i'].
' '.$font[
'n'].
' 0 R');
2238 $this->_put(
'/XObject <<');
2239 $this->_putxobjectdict();
2243protected function _putresources()
2246 $this->_putimages();
2250 $this->_putresourcedict();
2252 $this->_put(
'endobj');
2255protected function _putinfo()
2257 $date = @date(
'YmdHisO',$this->CreationDate);
2258 $this->metadata[
'CreationDate'] =
'D:'.substr(
$date,0,-2).
"'".substr(
$date,-2).
"'";
2259 foreach($this->metadata as $key=>
$value)
2260 $this->_put(
'/'.$key.
' '.$this->_textstring(
$value));
2263protected function _putcatalog()
2265 $n = $this->PageInfo[1][
'n'];
2266 $this->_put(
'/Type /Catalog');
2267 $this->_put(
'/Pages 1 0 R');
2268 if($this->ZoomMode==
'fullpage')
2269 $this->_put(
'/OpenAction ['.$n.
' 0 R /Fit]');
2270 elseif($this->ZoomMode==
'fullwidth')
2271 $this->_put('/OpenAction ['.$n.' 0 R /FitH null]');
2272 elseif($this->ZoomMode=='real')
2273 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null 1]');
2274 elseif(!is_string($this->ZoomMode))
2275 $this->_put('/OpenAction ['.$n.' 0 R /XYZ null null '.sprintf('%.2F',$this->ZoomMode/100).']');
2276 if($this->LayoutMode=='single')
2277 $this->_put('/PageLayout /SinglePage');
2278 elseif($this->LayoutMode=='continuous')
2279 $this->_put('/PageLayout /OneColumn');
2280 elseif($this->LayoutMode=='two')
2281 $this->_put('/PageLayout /TwoColumnLeft');
2284protected function _putheader()
2286 $this->_put(
'%PDF-'.$this->PDFVersion);
2289protected function _puttrailer()
2291 $this->_put(
'/Size '.($this->
n+1));
2292 $this->_put(
'/Root '.$this->
n.
' 0 R');
2293 $this->_put(
'/Info '.($this->
n-1).
' 0 R');
2296protected function _enddoc()
2298 $this->CreationDate = time();
2299 $this->_putheader();
2301 $this->_putresources();
2307 $this->_put(
'endobj');
2311 $this->_putcatalog();
2313 $this->_put(
'endobj');
2315 $offset = $this->_getoffset();
2316 $this->_put(
'xref');
2317 $this->_put(
'0 '.($this->
n+1));
2318 $this->_put(
'0000000000 65535 f ');
2319 for(
$i=1;
$i<=$this->n;
$i++)
2320 $this->_put(sprintf(
'%010d 00000 n ',$this->offsets[
$i]));
2322 $this->_put(
'trailer');
2324 $this->_puttrailer();
2326 $this->_put(
'startxref');
2328 $this->_put(
'%%EOF');
2334protected function UTF8ToUTF16BE(
$str, $setbom=
true) {
2337 $outstr .=
"\xFE\xFF";
2339 $outstr .= mb_convert_encoding(
$str,
'UTF-16BE',
'UTF-8');
2344protected function UTF8StringToArray(
$str) {
2346 $len = strlen(
$str);
2347 for (
$i = 0;
$i < $len;
$i++) {
2353 if ( ($h <= 0xDF) && (
$i < $len -1) )
2354 $uni = ($h & 0x1F) << 6 | (ord(
$str[++
$i]) & 0x3F);
2355 elseif ( ($h <= 0xEF) && (
$i < $len -2) )
2356 $uni = ($h & 0x0F) << 12 | (ord(
$str[++
$i]) & 0x3F) << 6
2357 | (ord(
$str[++
$i]) & 0x3F);
2358 elseif ( ($h <= 0xF4) && (
$i < $len -3) )
2359 $uni = ($h & 0x0F) << 18 | (ord(
$str[++
$i]) & 0x3F) << 12
2360 | (ord(
$str[++
$i]) & 0x3F) << 6
2361 | (ord(
$str[++
$i]) & 0x3F);
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
foreach($array as $idx=> $m) $w
while(!feof( $file)) echo fread( $file
if(count($array)==0) $size
if( $delta< 0) elseif( $delta==0)