Documentation TYPO3 par Ameos |
00001 <?php 00002 /******************************************************************************* 00003 * Software: FPDF * 00004 * Version: 1.52 * 00005 * Date: 2003-12-30 * 00006 * Author: Olivier PLATHEY * 00007 * License: Freeware * 00008 * * 00009 * You may use, modify and redistribute this software as you wish. * 00010 *******************************************************************************/ 00011 00012 if(!class_exists('FPDF')) 00013 { 00014 define('FPDF_VERSION','1.52'); 00015 00016 class FPDF 00017 { 00018 //Private properties 00019 var $page; //current page number 00020 var $n; //current object number 00021 var $offsets; //array of object offsets 00022 var $buffer; //buffer holding in-memory PDF 00023 var $pages; //array containing pages 00024 var $state; //current document state 00025 var $compress; //compression flag 00026 var $DefOrientation; //default orientation 00027 var $CurOrientation; //current orientation 00028 var $OrientationChanges; //array indicating orientation changes 00029 var $k; //scale factor (number of points in user unit) 00030 var $fwPt,$fhPt; //dimensions of page format in points 00031 var $fw,$fh; //dimensions of page format in user unit 00032 var $wPt,$hPt; //current dimensions of page in points 00033 var $w,$h; //current dimensions of page in user unit 00034 var $lMargin; //left margin 00035 var $tMargin; //top margin 00036 var $rMargin; //right margin 00037 var $bMargin; //page break margin 00038 var $cMargin; //cell margin 00039 var $x,$y; //current position in user unit for cell positioning 00040 var $lasth; //height of last cell printed 00041 var $LineWidth; //line width in user unit 00042 var $CoreFonts; //array of standard font names 00043 var $fonts; //array of used fonts 00044 var $FontFiles; //array of font files 00045 var $diffs; //array of encoding differences 00046 var $images; //array of used images 00047 var $PageLinks; //array of links in pages 00048 var $links; //array of internal links 00049 var $FontFamily; //current font family 00050 var $FontStyle; //current font style 00051 var $underline; //underlining flag 00052 var $CurrentFont; //current font info 00053 var $FontSizePt; //current font size in points 00054 var $FontSize; //current font size in user unit 00055 var $DrawColor; //commands for drawing color 00056 var $FillColor; //commands for filling color 00057 var $TextColor; //commands for text color 00058 var $ColorFlag; //indicates whether fill and text colors are different 00059 var $ws; //word spacing 00060 var $AutoPageBreak; //automatic page breaking 00061 var $PageBreakTrigger; //threshold used to trigger page breaks 00062 var $InFooter; //flag set when processing footer 00063 var $ZoomMode; //zoom display mode 00064 var $LayoutMode; //layout display mode 00065 var $title; //title 00066 var $subject; //subject 00067 var $author; //author 00068 var $keywords; //keywords 00069 var $creator; //creator 00070 var $AliasNbPages; //alias for total number of pages 00071 00072 /******************************************************************************* 00073 * * 00074 * Public methods * 00075 * * 00076 *******************************************************************************/ 00077 function FPDF($orientation='P',$unit='mm',$format='A4') 00078 { 00079 //Some checks 00080 $this->_dochecks(); 00081 //Initialization of properties 00082 $this->page=0; 00083 $this->n=2; 00084 $this->buffer=''; 00085 $this->pages=array(); 00086 $this->OrientationChanges=array(); 00087 $this->state=0; 00088 $this->fonts=array(); 00089 $this->FontFiles=array(); 00090 $this->diffs=array(); 00091 $this->images=array(); 00092 $this->links=array(); 00093 $this->InFooter=false; 00094 $this->lasth=0; 00095 $this->FontFamily=''; 00096 $this->FontStyle=''; 00097 $this->FontSizePt=12; 00098 $this->underline=false; 00099 $this->DrawColor='0 G'; 00100 $this->FillColor='0 g'; 00101 $this->TextColor='0 g'; 00102 $this->ColorFlag=false; 00103 $this->ws=0; 00104 //Standard fonts 00105 $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', 00106 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', 00107 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', 00108 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); 00109 //Scale factor 00110 if($unit=='pt') 00111 $this->k=1; 00112 elseif($unit=='mm') 00113 $this->k=72/25.4; 00114 elseif($unit=='cm') 00115 $this->k=72/2.54; 00116 elseif($unit=='in') 00117 $this->k=72; 00118 else 00119 $this->Error('Incorrect unit: '.$unit); 00120 //Page format 00121 if(is_string($format)) 00122 { 00123 $format=strtolower($format); 00124 if($format=='a3') 00125 $format=array(841.89,1190.55); 00126 elseif($format=='a4') 00127 $format=array(595.28,841.89); 00128 elseif($format=='a5') 00129 $format=array(420.94,595.28); 00130 elseif($format=='letter') 00131 $format=array(612,792); 00132 elseif($format=='legal') 00133 $format=array(612,1008); 00134 else 00135 $this->Error('Unknown page format: '.$format); 00136 $this->fwPt=$format[0]; 00137 $this->fhPt=$format[1]; 00138 } 00139 else 00140 { 00141 $this->fwPt=$format[0]*$this->k; 00142 $this->fhPt=$format[1]*$this->k; 00143 } 00144 $this->fw=$this->fwPt/$this->k; 00145 $this->fh=$this->fhPt/$this->k; 00146 //Page orientation 00147 $orientation=strtolower($orientation); 00148 if($orientation=='p' or $orientation=='portrait') 00149 { 00150 $this->DefOrientation='P'; 00151 $this->wPt=$this->fwPt; 00152 $this->hPt=$this->fhPt; 00153 } 00154 elseif($orientation=='l' or $orientation=='landscape') 00155 { 00156 $this->DefOrientation='L'; 00157 $this->wPt=$this->fhPt; 00158 $this->hPt=$this->fwPt; 00159 } 00160 else 00161 $this->Error('Incorrect orientation: '.$orientation); 00162 $this->CurOrientation=$this->DefOrientation; 00163 $this->w=$this->wPt/$this->k; 00164 $this->h=$this->hPt/$this->k; 00165 //Page margins (1 cm) 00166 $margin=28.35/$this->k; 00167 $this->SetMargins($margin,$margin); 00168 //Interior cell margin (1 mm) 00169 $this->cMargin=$margin/10; 00170 //Line width (0.2 mm) 00171 $this->LineWidth=.567/$this->k; 00172 //Automatic page break 00173 $this->SetAutoPageBreak(true,2*$margin); 00174 //Full width display mode 00175 $this->SetDisplayMode('fullwidth'); 00176 //Compression 00177 $this->SetCompression(true); 00178 } 00179 00180 function SetMargins($left,$top,$right=-1) 00181 { 00182 //Set left, top and right margins 00183 $this->lMargin=$left; 00184 $this->tMargin=$top; 00185 if($right==-1) 00186 $right=$left; 00187 $this->rMargin=$right; 00188 } 00189 00190 function SetLeftMargin($margin) 00191 { 00192 //Set left margin 00193 $this->lMargin=$margin; 00194 if($this->page>0 and $this->x<$margin) 00195 $this->x=$margin; 00196 } 00197 00198 function SetTopMargin($margin) 00199 { 00200 //Set top margin 00201 $this->tMargin=$margin; 00202 } 00203 00204 function SetRightMargin($margin) 00205 { 00206 //Set right margin 00207 $this->rMargin=$margin; 00208 } 00209 00210 function SetAutoPageBreak($auto,$margin=0) 00211 { 00212 //Set auto page break mode and triggering margin 00213 $this->AutoPageBreak=$auto; 00214 $this->bMargin=$margin; 00215 $this->PageBreakTrigger=$this->h-$margin; 00216 } 00217 00218 function SetDisplayMode($zoom,$layout='continuous') 00219 { 00220 //Set display mode in viewer 00221 if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) 00222 $this->ZoomMode=$zoom; 00223 else 00224 $this->Error('Incorrect zoom display mode: '.$zoom); 00225 if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') 00226 $this->LayoutMode=$layout; 00227 else 00228 $this->Error('Incorrect layout display mode: '.$layout); 00229 } 00230 00231 function SetCompression($compress) 00232 { 00233 //Set page compression 00234 if(function_exists('gzcompress')) 00235 $this->compress=$compress; 00236 else 00237 $this->compress=false; 00238 } 00239 00240 function SetTitle($title) 00241 { 00242 //Title of document 00243 $this->title=$title; 00244 } 00245 00246 function SetSubject($subject) 00247 { 00248 //Subject of document 00249 $this->subject=$subject; 00250 } 00251 00252 function SetAuthor($author) 00253 { 00254 //Author of document 00255 $this->author=$author; 00256 } 00257 00258 function SetKeywords($keywords) 00259 { 00260 //Keywords of document 00261 $this->keywords=$keywords; 00262 } 00263 00264 function SetCreator($creator) 00265 { 00266 //Creator of document 00267 $this->creator=$creator; 00268 } 00269 00270 function AliasNbPages($alias='{nb}') 00271 { 00272 //Define an alias for total number of pages 00273 $this->AliasNbPages=$alias; 00274 } 00275 00276 function Error($msg) 00277 { 00278 //Fatal error 00279 die('<B>FPDF error: </B>'.$msg); 00280 } 00281 00282 function Open() 00283 { 00284 //Begin document 00285 if($this->state==0) 00286 $this->_begindoc(); 00287 } 00288 00289 function Close() 00290 { 00291 //Terminate document 00292 if($this->state==3) 00293 return; 00294 if($this->page==0) 00295 $this->AddPage(); 00296 //Page footer 00297 $this->InFooter=true; 00298 $this->Footer(); 00299 $this->InFooter=false; 00300 //Close page 00301 $this->_endpage(); 00302 //Close document 00303 $this->_enddoc(); 00304 } 00305 00306 function AddPage($orientation='') 00307 { 00308 //Start a new page 00309 if($this->state==0) 00310 $this->Open(); 00311 $family=$this->FontFamily; 00312 $style=$this->FontStyle.($this->underline ? 'U' : ''); 00313 $size=$this->FontSizePt; 00314 $lw=$this->LineWidth; 00315 $dc=$this->DrawColor; 00316 $fc=$this->FillColor; 00317 $tc=$this->TextColor; 00318 $cf=$this->ColorFlag; 00319 if($this->page>0) 00320 { 00321 //Page footer 00322 $this->InFooter=true; 00323 $this->Footer(); 00324 $this->InFooter=false; 00325 //Close page 00326 $this->_endpage(); 00327 } 00328 //Start new page 00329 $this->_beginpage($orientation); 00330 //Set line cap style to square 00331 $this->_out('2 J'); 00332 //Set line width 00333 $this->LineWidth=$lw; 00334 $this->_out(sprintf('%.2f w',$lw*$this->k)); 00335 //Set font 00336 if($family) 00337 $this->SetFont($family,$style,$size); 00338 //Set colors 00339 $this->DrawColor=$dc; 00340 if($dc!='0 G') 00341 $this->_out($dc); 00342 $this->FillColor=$fc; 00343 if($fc!='0 g') 00344 $this->_out($fc); 00345 $this->TextColor=$tc; 00346 $this->ColorFlag=$cf; 00347 //Page header 00348 $this->Header(); 00349 //Restore line width 00350 if($this->LineWidth!=$lw) 00351 { 00352 $this->LineWidth=$lw; 00353 $this->_out(sprintf('%.2f w',$lw*$this->k)); 00354 } 00355 //Restore font 00356 if($family) 00357 $this->SetFont($family,$style,$size); 00358 //Restore colors 00359 if($this->DrawColor!=$dc) 00360 { 00361 $this->DrawColor=$dc; 00362 $this->_out($dc); 00363 } 00364 if($this->FillColor!=$fc) 00365 { 00366 $this->FillColor=$fc; 00367 $this->_out($fc); 00368 } 00369 $this->TextColor=$tc; 00370 $this->ColorFlag=$cf; 00371 } 00372 00373 function Header() 00374 { 00375 //To be implemented in your own inherited class 00376 } 00377 00378 function Footer() 00379 { 00380 //To be implemented in your own inherited class 00381 } 00382 00383 function PageNo() 00384 { 00385 //Get current page number 00386 return $this->page; 00387 } 00388 00389 function SetDrawColor($r,$g=-1,$b=-1) 00390 { 00391 //Set color for all stroking operations 00392 if(($r==0 and $g==0 and $b==0) or $g==-1) 00393 $this->DrawColor=sprintf('%.3f G',$r/255); 00394 else 00395 $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); 00396 if($this->page>0) 00397 $this->_out($this->DrawColor); 00398 } 00399 00400 function SetFillColor($r,$g=-1,$b=-1) 00401 { 00402 //Set color for all filling operations 00403 if(($r==0 and $g==0 and $b==0) or $g==-1) 00404 $this->FillColor=sprintf('%.3f g',$r/255); 00405 else 00406 $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); 00407 $this->ColorFlag=($this->FillColor!=$this->TextColor); 00408 if($this->page>0) 00409 $this->_out($this->FillColor); 00410 } 00411 00412 function SetTextColor($r,$g=-1,$b=-1) 00413 { 00414 //Set color for text 00415 if(($r==0 and $g==0 and $b==0) or $g==-1) 00416 $this->TextColor=sprintf('%.3f g',$r/255); 00417 else 00418 $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); 00419 $this->ColorFlag=($this->FillColor!=$this->TextColor); 00420 } 00421 00422 function GetStringWidth($s) 00423 { 00424 //Get width of a string in the current font 00425 $s=(string)$s; 00426 $cw=&$this->CurrentFont['cw']; 00427 $w=0; 00428 $l=strlen($s); 00429 for($i=0;$i<$l;$i++) 00430 $w+=$cw[$s{$i}]; 00431 return $w*$this->FontSize/1000; 00432 } 00433 00434 function SetLineWidth($width) 00435 { 00436 //Set line width 00437 $this->LineWidth=$width; 00438 if($this->page>0) 00439 $this->_out(sprintf('%.2f w',$width*$this->k)); 00440 } 00441 00442 function Line($x1,$y1,$x2,$y2) 00443 { 00444 //Draw a line 00445 $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)); 00446 } 00447 00448 function Rect($x,$y,$w,$h,$style='') 00449 { 00450 //Draw a rectangle 00451 if($style=='F') 00452 $op='f'; 00453 elseif($style=='FD' or $style=='DF') 00454 $op='B'; 00455 else 00456 $op='S'; 00457 $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op)); 00458 } 00459 00460 function AddFont($family,$style='',$file='') 00461 { 00462 //Add a TrueType or Type1 font 00463 $family=strtolower($family); 00464 if($family=='arial') 00465 $family='helvetica'; 00466 $style=strtoupper($style); 00467 if($style=='IB') 00468 $style='BI'; 00469 if(isset($this->fonts[$family.$style])) 00470 $this->Error('Font already added: '.$family.' '.$style); 00471 if($file=='') 00472 $file=str_replace(' ','',$family).strtolower($style).'.php'; 00473 if(defined('FPDF_FONTPATH')) 00474 $file=FPDF_FONTPATH.$file; 00475 include($file); 00476 if(!isset($name)) 00477 $this->Error('Could not include font definition file'); 00478 $i=count($this->fonts)+1; 00479 $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); 00480 if($diff) 00481 { 00482 //Search existing encodings 00483 $d=0; 00484 $nb=count($this->diffs); 00485 for($i=1;$i<=$nb;$i++) 00486 if($this->diffs[$i]==$diff) 00487 { 00488 $d=$i; 00489 break; 00490 } 00491 if($d==0) 00492 { 00493 $d=$nb+1; 00494 $this->diffs[$d]=$diff; 00495 } 00496 $this->fonts[$family.$style]['diff']=$d; 00497 } 00498 if($file) 00499 { 00500 if($type=='TrueType') 00501 $this->FontFiles[$file]=array('length1'=>$originalsize); 00502 else 00503 $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); 00504 } 00505 } 00506 00507 function SetFont($family,$style='',$size=0) 00508 { 00509 //Select a font; size given in points 00510 global $fpdf_charwidths; 00511 00512 $family=strtolower($family); 00513 if($family=='') 00514 $family=$this->FontFamily; 00515 if($family=='arial') 00516 $family='helvetica'; 00517 elseif($family=='symbol' or $family=='zapfdingbats') 00518 $style=''; 00519 $style=strtoupper($style); 00520 if(is_int(strpos($style,'U'))) 00521 { 00522 $this->underline=true; 00523 $style=str_replace('U','',$style); 00524 } 00525 else 00526 $this->underline=false; 00527 if($style=='IB') 00528 $style='BI'; 00529 if($size==0) 00530 $size=$this->FontSizePt; 00531 //Test if font is already selected 00532 if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) 00533 return; 00534 //Test if used for the first time 00535 $fontkey=$family.$style; 00536 if(!isset($this->fonts[$fontkey])) 00537 { 00538 //Check if one of the standard fonts 00539 if(isset($this->CoreFonts[$fontkey])) 00540 { 00541 if(!isset($fpdf_charwidths[$fontkey])) 00542 { 00543 //Load metric file 00544 $file=$family; 00545 if($family=='times' or $family=='helvetica') 00546 $file.=strtolower($style); 00547 $file.='.php'; 00548 if(defined('FPDF_FONTPATH')) 00549 $file=FPDF_FONTPATH.$file; 00550 include($file); 00551 if(!isset($fpdf_charwidths[$fontkey])) 00552 $this->Error('Could not include font metric file'); 00553 } 00554 $i=count($this->fonts)+1; 00555 $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]); 00556 } 00557 else 00558 $this->Error('Undefined font: '.$family.' '.$style); 00559 } 00560 //Select it 00561 $this->FontFamily=$family; 00562 $this->FontStyle=$style; 00563 $this->FontSizePt=$size; 00564 $this->FontSize=$size/$this->k; 00565 $this->CurrentFont=&$this->fonts[$fontkey]; 00566 if($this->page>0) 00567 $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 00568 } 00569 00570 function SetFontSize($size) 00571 { 00572 //Set font size in points 00573 if($this->FontSizePt==$size) 00574 return; 00575 $this->FontSizePt=$size; 00576 $this->FontSize=$size/$this->k; 00577 if($this->page>0) 00578 $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt)); 00579 } 00580 00581 function AddLink() 00582 { 00583 //Create a new internal link 00584 $n=count($this->links)+1; 00585 $this->links[$n]=array(0,0); 00586 return $n; 00587 } 00588 00589 function SetLink($link,$y=0,$page=-1) 00590 { 00591 //Set destination of internal link 00592 if($y==-1) 00593 $y=$this->y; 00594 if($page==-1) 00595 $page=$this->page; 00596 $this->links[$link]=array($page,$y); 00597 } 00598 00599 function Link($x,$y,$w,$h,$link) 00600 { 00601 //Put a link on the page 00602 $this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link); 00603 } 00604 00605 function Text($x,$y,$txt) 00606 { 00607 //Output a string 00608 $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); 00609 if($this->underline and $txt!='') 00610 $s.=' '.$this->_dounderline($x,$y,$txt); 00611 if($this->ColorFlag) 00612 $s='q '.$this->TextColor.' '.$s.' Q'; 00613 $this->_out($s); 00614 } 00615 00616 function AcceptPageBreak() 00617 { 00618 //Accept automatic page break or not 00619 return $this->AutoPageBreak; 00620 } 00621 00622 function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') 00623 { 00624 //Output a cell 00625 $k=$this->k; 00626 if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) 00627 { 00628 //Automatic page break 00629 $x=$this->x; 00630 $ws=$this->ws; 00631 if($ws>0) 00632 { 00633 $this->ws=0; 00634 $this->_out('0 Tw'); 00635 } 00636 $this->AddPage($this->CurOrientation); 00637 $this->x=$x; 00638 if($ws>0) 00639 { 00640 $this->ws=$ws; 00641 $this->_out(sprintf('%.3f Tw',$ws*$k)); 00642 } 00643 } 00644 if($w==0) 00645 $w=$this->w-$this->rMargin-$this->x; 00646 $s=''; 00647 if($fill==1 or $border==1) 00648 { 00649 if($fill==1) 00650 $op=($border==1) ? 'B' : 'f'; 00651 else 00652 $op='S'; 00653 $s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op); 00654 } 00655 if(is_string($border)) 00656 { 00657 $x=$this->x; 00658 $y=$this->y; 00659 if(is_int(strpos($border,'L'))) 00660 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); 00661 if(is_int(strpos($border,'T'))) 00662 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); 00663 if(is_int(strpos($border,'R'))) 00664 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 00665 if(is_int(strpos($border,'B'))) 00666 $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); 00667 } 00668 if($txt!='') 00669 { 00670 if($align=='R') 00671 $dx=$w-$this->cMargin-$this->GetStringWidth($txt); 00672 elseif($align=='C') 00673 $dx=($w-$this->GetStringWidth($txt))/2; 00674 else 00675 $dx=$this->cMargin; 00676 if($this->ColorFlag) 00677 $s.='q '.$this->TextColor.' '; 00678 $txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt))); 00679 $s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2); 00680 if($this->underline) 00681 $s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt); 00682 if($this->ColorFlag) 00683 $s.=' Q'; 00684 if($link) 00685 $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link); 00686 } 00687 if($s) 00688 $this->_out($s); 00689 $this->lasth=$h; 00690 if($ln>0) 00691 { 00692 //Go to next line 00693 $this->y+=$h; 00694 if($ln==1) 00695 $this->x=$this->lMargin; 00696 } 00697 else 00698 $this->x+=$w; 00699 } 00700 00701 function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) 00702 { 00703 //Output text with automatic or explicit line breaks 00704 $cw=&$this->CurrentFont['cw']; 00705 if($w==0) 00706 $w=$this->w-$this->rMargin-$this->x; 00707 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 00708 $s=str_replace("\r",'',$txt); 00709 $nb=strlen($s); 00710 if($nb>0 and $s[$nb-1]=="\n") 00711 $nb--; 00712 $b=0; 00713 if($border) 00714 { 00715 if($border==1) 00716 { 00717 $border='LTRB'; 00718 $b='LRT'; 00719 $b2='LR'; 00720 } 00721 else 00722 { 00723 $b2=''; 00724 if(is_int(strpos($border,'L'))) 00725 $b2.='L'; 00726 if(is_int(strpos($border,'R'))) 00727 $b2.='R'; 00728 $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; 00729 } 00730 } 00731 $sep=-1; 00732 $i=0; 00733 $j=0; 00734 $l=0; 00735 $ns=0; 00736 $nl=1; 00737 while($i<$nb) 00738 { 00739 //Get next character 00740 $c=$s{$i}; 00741 if($c=="\n") 00742 { 00743 //Explicit line break 00744 if($this->ws>0) 00745 { 00746 $this->ws=0; 00747 $this->_out('0 Tw'); 00748 } 00749 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 00750 $i++; 00751 $sep=-1; 00752 $j=$i; 00753 $l=0; 00754 $ns=0; 00755 $nl++; 00756 if($border and $nl==2) 00757 $b=$b2; 00758 continue; 00759 } 00760 if($c==' ') 00761 { 00762 $sep=$i; 00763 $ls=$l; 00764 $ns++; 00765 } 00766 $l+=isset($cw[ord($c)])?$cw[ord($c)]:0; 00767 if($l>$wmax) 00768 { 00769 //Automatic line break 00770 if($sep==-1) 00771 { 00772 if($i==$j) 00773 $i++; 00774 if($this->ws>0) 00775 { 00776 $this->ws=0; 00777 $this->_out('0 Tw'); 00778 } 00779 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 00780 } 00781 else 00782 { 00783 if($align=='J') 00784 { 00785 $this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 00786 $this->_out(sprintf('%.3f Tw',$this->ws*$this->k)); 00787 } 00788 $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 00789 $i=$sep+1; 00790 } 00791 $sep=-1; 00792 $j=$i; 00793 $l=0; 00794 $ns=0; 00795 $nl++; 00796 if($border and $nl==2) 00797 $b=$b2; 00798 } 00799 else 00800 $i++; 00801 } 00802 //Last chunk 00803 if($this->ws>0) 00804 { 00805 $this->ws=0; 00806 $this->_out('0 Tw'); 00807 } 00808 if($border and is_int(strpos($border,'B'))) 00809 $b.='B'; 00810 $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 00811 $this->x=$this->lMargin; 00812 } 00813 00814 function Write($h,$txt,$link='') 00815 { 00816 //Output text in flowing mode 00817 $cw=&$this->CurrentFont['cw']; 00818 $w=$this->w-$this->rMargin-$this->x; 00819 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 00820 $s=str_replace("\r",'',$txt); 00821 $nb=strlen($s); 00822 $sep=-1; 00823 $i=0; 00824 $j=0; 00825 $l=0; 00826 $nl=1; 00827 while($i<$nb) 00828 { 00829 //Get next character 00830 $c=$s{$i}; 00831 if($c=="\n") 00832 { 00833 //Explicit line break 00834 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 00835 $i++; 00836 $sep=-1; 00837 $j=$i; 00838 $l=0; 00839 if($nl==1) 00840 { 00841 $this->x=$this->lMargin; 00842 $w=$this->w-$this->rMargin-$this->x; 00843 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 00844 } 00845 $nl++; 00846 continue; 00847 } 00848 if($c==' ') 00849 $sep=$i; 00850 $l+=$cw[$c]; 00851 if($l>$wmax) 00852 { 00853 //Automatic line break 00854 if($sep==-1) 00855 { 00856 if($this->x>$this->lMargin) 00857 { 00858 //Move to next line 00859 $this->x=$this->lMargin; 00860 $this->y+=$h; 00861 $w=$this->w-$this->rMargin-$this->x; 00862 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 00863 $i++; 00864 $nl++; 00865 continue; 00866 } 00867 if($i==$j) 00868 $i++; 00869 $this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link); 00870 } 00871 else 00872 { 00873 $this->Cell($w,$h,substr($s,$j,$sep-$j),0,2,'',0,$link); 00874 $i=$sep+1; 00875 } 00876 $sep=-1; 00877 $j=$i; 00878 $l=0; 00879 if($nl==1) 00880 { 00881 $this->x=$this->lMargin; 00882 $w=$this->w-$this->rMargin-$this->x; 00883 $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; 00884 } 00885 $nl++; 00886 } 00887 else 00888 $i++; 00889 } 00890 //Last chunk 00891 if($i!=$j) 00892 $this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link); 00893 } 00894 00895 function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') 00896 { 00897 //Put an image on the page 00898 if(!isset($this->images[$file])) 00899 { 00900 //First use of image, get info 00901 if($type=='') 00902 { 00903 $pos=strrpos($file,'.'); 00904 if(!$pos) 00905 $this->Error('Image file has no extension and no type was specified: '.$file); 00906 $type=substr($file,$pos+1); 00907 } 00908 $type=strtolower($type); 00909 $mqr=get_magic_quotes_runtime(); 00910 set_magic_quotes_runtime(0); 00911 if($type=='jpg' or $type=='jpeg') 00912 $info=$this->_parsejpg($file); 00913 elseif($type=='png') 00914 $info=$this->_parsepng($file); 00915 else 00916 { 00917 //Allow for additional formats 00918 $mtd='_parse'.$type; 00919 if(!method_exists($this,$mtd)) 00920 $this->Error('Unsupported image type: '.$type); 00921 $info=$this->$mtd($file); 00922 } 00923 set_magic_quotes_runtime($mqr); 00924 $info['i']=count($this->images)+1; 00925 $this->images[$file]=$info; 00926 } 00927 else 00928 $info=$this->images[$file]; 00929 //Automatic width and height calculation if needed 00930 if($w==0 and $h==0) 00931 { 00932 //Put image at 72 dpi 00933 $w=$info['w']/$this->k; 00934 $h=$info['h']/$this->k; 00935 } 00936 if($w==0) 00937 $w=$h*$info['w']/$info['h']; 00938 if($h==0) 00939 $h=$w*$info['h']/$info['w']; 00940 $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'])); 00941 if($link) 00942 $this->Link($x,$y,$w,$h,$link); 00943 } 00944 00945 function Ln($h='') 00946 { 00947 //Line feed; default value is last cell height 00948 $this->x=$this->lMargin; 00949 if(is_string($h)) 00950 $this->y+=$this->lasth; 00951 else 00952 $this->y+=$h; 00953 } 00954 00955 function GetX() 00956 { 00957 //Get x position 00958 return $this->x; 00959 } 00960 00961 function SetX($x) 00962 { 00963 //Set x position 00964 if($x>=0) 00965 $this->x=$x; 00966 else 00967 $this->x=$this->w+$x; 00968 } 00969 00970 function GetY() 00971 { 00972 //Get y position 00973 return $this->y; 00974 } 00975 00976 function SetY($y) 00977 { 00978 //Set y position and reset x 00979 $this->x=$this->lMargin; 00980 if($y>=0) 00981 $this->y=$y; 00982 else 00983 $this->y=$this->h+$y; 00984 } 00985 00986 function SetXY($x,$y) 00987 { 00988 //Set x and y positions 00989 $this->SetY($y); 00990 $this->SetX($x); 00991 } 00992 00993 function Output($name='',$dest='') 00994 { 00995 //Output PDF to some destination 00996 // lem9 00997 //global $HTTP_SERVER_VARS; 00998 00999 //Finish document if necessary 01000 if($this->state<3) 01001 $this->Close(); 01002 //Normalize parameters 01003 if(is_bool($dest)) 01004 $dest=$dest ? 'D' : 'F'; 01005 $dest=strtoupper($dest); 01006 if($dest=='') 01007 { 01008 if($name=='') 01009 { 01010 $name='doc.pdf'; 01011 $dest='I'; 01012 } 01013 else 01014 $dest='F'; 01015 } 01016 switch($dest) 01017 { 01018 case 'I': 01019 //Send to standard output 01020 // lem9 01021 //if(isset($HTTP_SERVER_VARS['SERVER_NAME'])) 01022 if(isset($_SERVER['SERVER_NAME'])) 01023 { 01024 //We send to a browser 01025 Header('Content-Type: application/pdf'); 01026 if(headers_sent()) 01027 $this->Error('Some data has already been output to browser, can\'t send PDF file'); 01028 Header('Content-Length: '.strlen($this->buffer)); 01029 Header('Content-disposition: inline; filename='.$name); 01030 } 01031 echo $this->buffer; 01032 break; 01033 case 'D': 01034 //Download file 01035 // lem9 01036 //if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE')) 01037 if(isset($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) 01038 Header('Content-Type: application/force-download'); 01039 else 01040 Header('Content-Type: application/octet-stream'); 01041 if(headers_sent()) 01042 $this->Error('Some data has already been output to browser, can\'t send PDF file'); 01043 Header('Content-Length: '.strlen($this->buffer)); 01044 Header('Content-disposition: attachment; filename='.$name); 01045 echo $this->buffer; 01046 break; 01047 case 'F': 01048 //Save to local file 01049 $f=fopen($name,'wb'); 01050 if(!$f) 01051 $this->Error('Unable to create output file: '.$name); 01052 fwrite($f,$this->buffer,strlen($this->buffer)); 01053 fclose($f); 01054 break; 01055 case 'S': 01056 //Return as a string 01057 return $this->buffer; 01058 default: 01059 $this->Error('Incorrect output destination: '.$dest); 01060 } 01061 return ''; 01062 } 01063 01064 /******************************************************************************* 01065 * * 01066 * Protected methods * 01067 * * 01068 *******************************************************************************/ 01069 function _dochecks() 01070 { 01071 //Check for locale-related bug 01072 if(1.1==1) 01073 $this->Error('Don\'t alter the locale before including class file'); 01074 //Check for decimal separator 01075 if(sprintf('%.1f',1.0)!='1.0') 01076 setlocale(LC_NUMERIC,'C'); 01077 } 01078 01079 function _begindoc() 01080 { 01081 //Start document 01082 $this->state=1; 01083 $this->_out('%PDF-1.3'); 01084 } 01085 01086 function _strreplace($what, $to, $where) { 01087 return str_replace($what, $to, $where); 01088 } 01089 01090 function _putpages() 01091 { 01092 $nb=$this->page; 01093 if(!empty($this->AliasNbPages)) 01094 { 01095 //Replace number of pages 01096 for($n=1;$n<=$nb;$n++) 01097 $this->pages[$n]=$this->_strreplace($this->AliasNbPages,$nb,$this->pages[$n]); 01098 } 01099 if($this->DefOrientation=='P') 01100 { 01101 $wPt=$this->fwPt; 01102 $hPt=$this->fhPt; 01103 } 01104 else 01105 { 01106 $wPt=$this->fhPt; 01107 $hPt=$this->fwPt; 01108 } 01109 $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 01110 for($n=1;$n<=$nb;$n++) 01111 { 01112 //Page 01113 $this->_newobj(); 01114 $this->_out('<</Type /Page'); 01115 $this->_out('/Parent 1 0 R'); 01116 if(isset($this->OrientationChanges[$n])) 01117 $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$hPt,$wPt)); 01118 $this->_out('/Resources 2 0 R'); 01119 if(isset($this->PageLinks[$n])) 01120 { 01121 //Links 01122 $annots='/Annots ['; 01123 foreach($this->PageLinks[$n] as $pl) 01124 { 01125 $rect=sprintf('%.2f %.2f %.2f %.2f',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); 01126 $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; 01127 if(is_string($pl[4])) 01128 $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; 01129 else 01130 { 01131 $l=$this->links[$pl[4]]; 01132 $h=isset($this->OrientationChanges[$l[0]]) ? $wPt : $hPt; 01133 $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>',1+2*$l[0],$h-$l[1]*$this->k); 01134 } 01135 } 01136 $this->_out($annots.']'); 01137 } 01138 $this->_out('/Contents '.($this->n+1).' 0 R>>'); 01139 $this->_out('endobj'); 01140 //Page content 01141 $p=($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n]; 01142 $this->_newobj(); 01143 $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); 01144 $this->_putstream($p); 01145 $this->_out('endobj'); 01146 } 01147 //Pages root 01148 $this->offsets[1]=strlen($this->buffer); 01149 $this->_out('1 0 obj'); 01150 $this->_out('<</Type /Pages'); 01151 $kids='/Kids ['; 01152 for($i=0;$i<$nb;$i++) 01153 $kids.=(3+2*$i).' 0 R '; 01154 $this->_out($kids.']'); 01155 $this->_out('/Count '.$nb); 01156 $this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]',$wPt,$hPt)); 01157 $this->_out('>>'); 01158 $this->_out('endobj'); 01159 } 01160 01161 function _putfonts() 01162 { 01163 $nf=$this->n; 01164 foreach($this->diffs as $diff) 01165 { 01166 //Encodings 01167 $this->_newobj(); 01168 $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>'); 01169 $this->_out('endobj'); 01170 } 01171 $mqr=get_magic_quotes_runtime(); 01172 set_magic_quotes_runtime(0); 01173 foreach($this->FontFiles as $file=>$info) 01174 { 01175 //Font file embedding 01176 $this->_newobj(); 01177 $this->FontFiles[$file]['n']=$this->n; 01178 if(defined('FPDF_FONTPATH')) 01179 $file=FPDF_FONTPATH.$file; 01180 $size=filesize($file); 01181 if(!$size) 01182 $this->Error('Font file not found'); 01183 $this->_out('<</Length '.$size); 01184 if(substr($file,-2)=='.z') 01185 $this->_out('/Filter /FlateDecode'); 01186 $this->_out('/Length1 '.$info['length1']); 01187 if(isset($info['length2'])) 01188 $this->_out('/Length2 '.$info['length2'].' /Length3 0'); 01189 $this->_out('>>'); 01190 $f=fopen($file,'rb'); 01191 $this->_putstream(fread($f,$size)); 01192 fclose($f); 01193 $this->_out('endobj'); 01194 } 01195 set_magic_quotes_runtime($mqr); 01196 foreach($this->fonts as $k=>$font) 01197 { 01198 //Font objects 01199 $this->fonts[$k]['n']=$this->n+1; 01200 $type=$font['type']; 01201 $name=$font['name']; 01202 if($type=='core') 01203 { 01204 //Standard font 01205 $this->_newobj(); 01206 $this->_out('<</Type /Font'); 01207 $this->_out('/BaseFont /'.$name); 01208 $this->_out('/Subtype /Type1'); 01209 if($name!='Symbol' and $name!='ZapfDingbats') 01210 $this->_out('/Encoding /WinAnsiEncoding'); 01211 $this->_out('>>'); 01212 $this->_out('endobj'); 01213 } 01214 elseif($type=='Type1' or $type=='TrueType') 01215 { 01216 //Additional Type1 or TrueType font 01217 $this->_newobj(); 01218 $this->_out('<</Type /Font'); 01219 $this->_out('/BaseFont /'.$name); 01220 $this->_out('/Subtype /'.$type); 01221 $this->_out('/FirstChar 32 /LastChar 255'); 01222 $this->_out('/Widths '.($this->n+1).' 0 R'); 01223 $this->_out('/FontDescriptor '.($this->n+2).' 0 R'); 01224 if($font['enc']) 01225 { 01226 if(isset($font['diff'])) 01227 $this->_out('/Encoding '.($nf+$font['diff']).' 0 R'); 01228 else 01229 $this->_out('/Encoding /WinAnsiEncoding'); 01230 } 01231 $this->_out('>>'); 01232 $this->_out('endobj'); 01233 //Widths 01234 $this->_newobj(); 01235 $cw=&$font['cw']; 01236 $s='['; 01237 for($i=32;$i<=255;$i++) 01238 $s.=$cw[chr($i)].' '; 01239 $this->_out($s.']'); 01240 $this->_out('endobj'); 01241 //Descriptor 01242 $this->_newobj(); 01243 $s='<</Type /FontDescriptor /FontName /'.$name; 01244 foreach($font['desc'] as $k=>$v) 01245 $s.=' /'.$k.' '.$v; 01246 $file=$font['file']; 01247 if($file) 01248 $s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R'; 01249 $this->_out($s.'>>'); 01250 $this->_out('endobj'); 01251 } 01252 else 01253 { 01254 //Allow for additional types 01255 $mtd='_put'.strtolower($type); 01256 if(!method_exists($this,$mtd)) 01257 $this->Error('Unsupported font type: '.$type); 01258 $this->$mtd($font); 01259 } 01260 } 01261 } 01262 01263 function _putimages() 01264 { 01265 $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; 01266 reset($this->images); 01267 while(list($file,$info)=each($this->images)) 01268 { 01269 $this->_newobj(); 01270 $this->images[$file]['n']=$this->n; 01271 $this->_out('<</Type /XObject'); 01272 $this->_out('/Subtype /Image'); 01273 $this->_out('/Width '.$info['w']); 01274 $this->_out('/Height '.$info['h']); 01275 if($info['cs']=='Indexed') 01276 $this->_out('/ColorSpace [/Indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); 01277 else 01278 { 01279 $this->_out('/ColorSpace /'.$info['cs']); 01280 if($info['cs']=='DeviceCMYK') 01281 $this->_out('/Decode [1 0 1 0 1 0 1 0]'); 01282 } 01283 $this->_out('/BitsPerComponent '.$info['bpc']); 01284 $this->_out('/Filter /'.$info['f']); 01285 if(isset($info['parms'])) 01286 $this->_out($info['parms']); 01287 if(isset($info['trns']) and is_array($info['trns'])) 01288 { 01289 $trns=''; 01290 for($i=0;$i<count($info['trns']);$i++) 01291 $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; 01292 $this->_out('/Mask ['.$trns.']'); 01293 } 01294 $this->_out('/Length '.strlen($info['data']).'>>'); 01295 $this->_putstream($info['data']); 01296 unset($this->images[$file]['data']); 01297 $this->_out('endobj'); 01298 //Palette 01299 if($info['cs']=='Indexed') 01300 { 01301 $this->_newobj(); 01302 $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; 01303 $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); 01304 $this->_putstream($pal); 01305 $this->_out('endobj'); 01306 } 01307 } 01308 } 01309 01310 function _putresources() 01311 { 01312 $this->_putfonts(); 01313 $this->_putimages(); 01314 //Resource dictionary 01315 $this->offsets[2]=strlen($this->buffer); 01316 $this->_out('2 0 obj'); 01317 $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); 01318 $this->_out('/Font <<'); 01319 foreach($this->fonts as $font) 01320 $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); 01321 $this->_out('>>'); 01322 if(count($this->images)) 01323 { 01324 $this->_out('/XObject <<'); 01325 foreach($this->images as $image) 01326 $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); 01327 $this->_out('>>'); 01328 } 01329 $this->_out('>>'); 01330 $this->_out('endobj'); 01331 } 01332 01333 function _putinfo() 01334 { 01335 $this->_out('/Producer '.$this->_textstring('FPDF '.FPDF_VERSION)); 01336 if(!empty($this->title)) 01337 $this->_out('/Title '.$this->_textstring($this->title)); 01338 if(!empty($this->subject)) 01339 $this->_out('/Subject '.$this->_textstring($this->subject)); 01340 if(!empty($this->author)) 01341 $this->_out('/Author '.$this->_textstring($this->author)); 01342 if(!empty($this->keywords)) 01343 $this->_out('/Keywords '.$this->_textstring($this->keywords)); 01344 if(!empty($this->creator)) 01345 $this->_out('/Creator '.$this->_textstring($this->creator)); 01346 $this->_out('/CreationDate '.$this->_textstring('D:'.date('YmdHis'))); 01347 } 01348 01349 function _putcatalog() 01350 { 01351 $this->_out('/Type /Catalog'); 01352 $this->_out('/Pages 1 0 R'); 01353 if($this->ZoomMode=='fullpage') 01354 $this->_out('/OpenAction [3 0 R /Fit]'); 01355 elseif($this->ZoomMode=='fullwidth') 01356 $this->_out('/OpenAction [3 0 R /FitH null]'); 01357 elseif($this->ZoomMode=='real') 01358 $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); 01359 elseif(!is_string($this->ZoomMode)) 01360 $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); 01361 if($this->LayoutMode=='single') 01362 $this->_out('/PageLayout /SinglePage'); 01363 elseif($this->LayoutMode=='continuous') 01364 $this->_out('/PageLayout /OneColumn'); 01365 elseif($this->LayoutMode=='two') 01366 $this->_out('/PageLayout /TwoColumnLeft'); 01367 } 01368 01369 function _puttrailer() 01370 { 01371 $this->_out('/Size '.($this->n+1)); 01372 $this->_out('/Root '.$this->n.' 0 R'); 01373 $this->_out('/Info '.($this->n-1).' 0 R'); 01374 } 01375 01376 function _enddoc() 01377 { 01378 $this->_putpages(); 01379 $this->_putresources(); 01380 //Info 01381 $this->_newobj(); 01382 $this->_out('<<'); 01383 $this->_putinfo(); 01384 $this->_out('>>'); 01385 $this->_out('endobj'); 01386 //Catalog 01387 $this->_newobj(); 01388 $this->_out('<<'); 01389 $this->_putcatalog(); 01390 $this->_out('>>'); 01391 $this->_out('endobj'); 01392 //Cross-ref 01393 $o=strlen($this->buffer); 01394 $this->_out('xref'); 01395 $this->_out('0 '.($this->n+1)); 01396 $this->_out('0000000000 65535 f '); 01397 for($i=1;$i<=$this->n;$i++) 01398 $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); 01399 //Trailer 01400 $this->_out('trailer'); 01401 $this->_out('<<'); 01402 $this->_puttrailer(); 01403 $this->_out('>>'); 01404 $this->_out('startxref'); 01405 $this->_out($o); 01406 $this->_out('%%EOF'); 01407 $this->state=3; 01408 } 01409 01410 function _beginpage($orientation) 01411 { 01412 $this->page++; 01413 $this->pages[$this->page]=''; 01414 $this->state=2; 01415 $this->x=$this->lMargin; 01416 $this->y=$this->tMargin; 01417 $this->FontFamily=''; 01418 //Page orientation 01419 if(!$orientation) 01420 $orientation=$this->DefOrientation; 01421 else 01422 { 01423 $orientation=strtoupper($orientation{0}); 01424 if($orientation!=$this->DefOrientation) 01425 $this->OrientationChanges[$this->page]=true; 01426 } 01427 if($orientation!=$this->CurOrientation) 01428 { 01429 //Change orientation 01430 if($orientation=='P') 01431 { 01432 $this->wPt=$this->fwPt; 01433 $this->hPt=$this->fhPt; 01434 $this->w=$this->fw; 01435 $this->h=$this->fh; 01436 } 01437 else 01438 { 01439 $this->wPt=$this->fhPt; 01440 $this->hPt=$this->fwPt; 01441 $this->w=$this->fh; 01442 $this->h=$this->fw; 01443 } 01444 $this->PageBreakTrigger=$this->h-$this->bMargin; 01445 $this->CurOrientation=$orientation; 01446 } 01447 } 01448 01449 function _endpage() 01450 { 01451 //End of page contents 01452 $this->state=1; 01453 } 01454 01455 function _newobj() 01456 { 01457 //Begin a new object 01458 $this->n++; 01459 $this->offsets[$this->n]=strlen($this->buffer); 01460 $this->_out($this->n.' 0 obj'); 01461 } 01462 01463 function _dounderline($x,$y,$txt) 01464 { 01465 //Underline text 01466 $up=$this->CurrentFont['up']; 01467 $ut=$this->CurrentFont['ut']; 01468 $w=$this->GetStringWidth($txt)+$this->ws*substr_count($txt,' '); 01469 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); 01470 } 01471 01472 function _parsejpg($file) 01473 { 01474 //Extract info from a JPEG file 01475 $a=GetImageSize($file); 01476 if(!$a) 01477 $this->Error('Missing or incorrect image file: '.$file); 01478 if($a[2]!=2) 01479 $this->Error('Not a JPEG file: '.$file); 01480 if(!isset($a['channels']) or $a['channels']==3) 01481 $colspace='DeviceRGB'; 01482 elseif($a['channels']==4) 01483 $colspace='DeviceCMYK'; 01484 else 01485 $colspace='DeviceGray'; 01486 $bpc=isset($a['bits']) ? $a['bits'] : 8; 01487 //Read whole file 01488 $f=fopen($file,'rb'); 01489 $data=''; 01490 while(!feof($f)) 01491 $data.=fread($f,4096); 01492 fclose($f); 01493 return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); 01494 } 01495 01496 function _parsepng($file) 01497 { 01498 //Extract info from a PNG file 01499 $f=fopen($file,'rb'); 01500 if(!$f) 01501 $this->Error('Can\'t open image file: '.$file); 01502 //Check signature 01503 if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) 01504 $this->Error('Not a PNG file: '.$file); 01505 //Read header chunk 01506 fread($f,4); 01507 if(fread($f,4)!='IHDR') 01508 $this->Error('Incorrect PNG file: '.$file); 01509 $w=$this->_freadint($f); 01510 $h=$this->_freadint($f); 01511 $bpc=ord(fread($f,1)); 01512 if($bpc>8) 01513 $this->Error('16-bit depth not supported: '.$file); 01514 $ct=ord(fread($f,1)); 01515 if($ct==0) 01516 $colspace='DeviceGray'; 01517 elseif($ct==2) 01518 $colspace='DeviceRGB'; 01519 elseif($ct==3) 01520 $colspace='Indexed'; 01521 else 01522 $this->Error('Alpha channel not supported: '.$file); 01523 if(ord(fread($f,1))!=0) 01524 $this->Error('Unknown compression method: '.$file); 01525 if(ord(fread($f,1))!=0) 01526 $this->Error('Unknown filter method: '.$file); 01527 if(ord(fread($f,1))!=0) 01528 $this->Error('Interlacing not supported: '.$file); 01529 fread($f,4); 01530 $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; 01531 //Scan chunks looking for palette, transparency and image data 01532 $pal=''; 01533 $trns=''; 01534 $data=''; 01535 do 01536 { 01537 $n=$this->_freadint($f); 01538 $type=fread($f,4); 01539 if($type=='PLTE') 01540 { 01541 //Read palette 01542 $pal=fread($f,$n); 01543 fread($f,4); 01544 } 01545 elseif($type=='tRNS') 01546 { 01547 //Read transparency info 01548 $t=fread($f,$n); 01549 if($ct==0) 01550 $trns=array(ord(substr($t,1,1))); 01551 elseif($ct==2) 01552 $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); 01553 else 01554 { 01555 $pos=strpos($t,chr(0)); 01556 if(is_int($pos)) 01557 $trns=array($pos); 01558 } 01559 fread($f,4); 01560 } 01561 elseif($type=='IDAT') 01562 { 01563 //Read image data block 01564 $data.=fread($f,$n); 01565 fread($f,4); 01566 } 01567 elseif($type=='IEND') 01568 break; 01569 else 01570 fread($f,$n+4); 01571 } 01572 while($n); 01573 if($colspace=='Indexed' and empty($pal)) 01574 $this->Error('Missing palette in '.$file); 01575 fclose($f); 01576 return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); 01577 } 01578 01579 function _freadint($f) 01580 { 01581 //Read a 4-byte integer from file 01582 $i=ord(fread($f,1))<<24; 01583 $i+=ord(fread($f,1))<<16; 01584 $i+=ord(fread($f,1))<<8; 01585 $i+=ord(fread($f,1)); 01586 return $i; 01587 } 01588 01589 function _textstring($s) 01590 { 01591 //Format a text string 01592 return '('.$this->_escape($s).')'; 01593 } 01594 01595 function _escape($s) 01596 { 01597 //Add \ before \, ( and ) 01598 return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); 01599 } 01600 01601 function _putstream($s) 01602 { 01603 $this->_out('stream'); 01604 $this->_out($s); 01605 $this->_out('endstream'); 01606 } 01607 01608 function _out($s) 01609 { 01610 //Add a line to the document 01611 if($this->state==2) 01612 $this->pages[$this->page].=$s."\n"; 01613 else 01614 $this->buffer.=$s."\n"; 01615 } 01616 //End of class 01617 } 01618 01619 //Handle special IE contype request 01620 // lem9 01621 //if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') 01622 if(isset($_SERVER['HTTP_USER_AGENT']) and $_SERVER['HTTP_USER_AGENT']=='contype') 01623 { 01624 Header('Content-Type: application/pdf'); 01625 exit; 01626 } 01627 01628 } 01629 ?>