From 14cea94915e8f7d18a1b71a6fa2b02f9159b28d6 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 12 Jun 2005 16:13:26 +0000 Subject: [PATCH] updated to 1.53 --- lam/lib/fpdf.php | 702 +++++++++++++++++++++++------------------------ 1 file changed, 337 insertions(+), 365 deletions(-) diff --git a/lam/lib/fpdf.php b/lam/lib/fpdf.php index 01391ae9..5fbf585f 100644 --- a/lam/lib/fpdf.php +++ b/lam/lib/fpdf.php @@ -1,298 +1,244 @@ _dochecks(); - //Initialization of properties - $this->page=0; - $this->n=2; - $this->buffer=''; - $this->pages=array(); - $this->OrientationChanges=array(); - $this->state=0; - $this->fonts=array(); - $this->FontFiles=array(); - $this->diffs=array(); - $this->images=array(); - $this->links=array(); - $this->InFooter=false; - $this->lasth=0; - $this->FontFamily=''; - $this->FontStyle=''; - $this->FontSizePt=12; - $this->underline=false; - $this->DrawColor='0 G'; - $this->FillColor='0 g'; - $this->TextColor='0 g'; - $this->ColorFlag=false; - $this->ws=0; - //Standard fonts - $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', - 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', - 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', - 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); - //Scale factor - if($unit=='pt') - $this->k=1; - elseif($unit=='mm') - $this->k=72/25.4; - elseif($unit=='cm') - $this->k=72/2.54; - elseif($unit=='in') - $this->k=72; +function FPDF($orientation='P',$unit='mm',$format='A4') +{ + //Some checks + $this->_dochecks(); + //Initialization of properties + $this->page=0; + $this->n=2; + $this->buffer=''; + $this->pages=array(); + $this->OrientationChanges=array(); + $this->state=0; + $this->fonts=array(); + $this->FontFiles=array(); + $this->diffs=array(); + $this->images=array(); + $this->links=array(); + $this->InFooter=false; + $this->lasth=0; + $this->FontFamily=''; + $this->FontStyle=''; + $this->FontSizePt=12; + $this->underline=false; + $this->DrawColor='0 G'; + $this->FillColor='0 g'; + $this->TextColor='0 g'; + $this->ColorFlag=false; + $this->ws=0; + //Standard fonts + $this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique', + 'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique', + 'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic', + 'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats'); + //Scale factor + if($unit=='pt') + $this->k=1; + elseif($unit=='mm') + $this->k=72/25.4; + elseif($unit=='cm') + $this->k=72/2.54; + elseif($unit=='in') + $this->k=72; + else + $this->Error('Incorrect unit: '.$unit); + //Page format + if(is_string($format)) + { + $format=strtolower($format); + if($format=='a3') + $format=array(841.89,1190.55); + elseif($format=='a4') + $format=array(595.28,841.89); + elseif($format=='a5') + $format=array(420.94,595.28); + elseif($format=='letter') + $format=array(612,792); + elseif($format=='legal') + $format=array(612,1008); else - $this->Error('Incorrect unit: '.$unit); - //Page format - if(is_string($format)) - { - $format=strtolower($format); - if($format=='a3') - $format=array(841.89,1190.55); - elseif($format=='a4') - $format=array(595.28,841.89); - elseif($format=='a5') - $format=array(420.94,595.28); - elseif($format=='letter') - $format=array(612,792); - elseif($format=='legal') - $format=array(612,1008); - else - $this->Error('Unknown page format: '.$format); - $this->fwPt=$format[0]; - $this->fhPt=$format[1]; - } - else - { - $this->fwPt=$format[0]*$this->k; - $this->fhPt=$format[1]*$this->k; - } - $this->fw=$this->fwPt/$this->k; - $this->fh=$this->fhPt/$this->k; - //Page orientation - $orientation=strtolower($orientation); - if($orientation=='p' or $orientation=='portrait') - { - $this->DefOrientation='P'; - $this->wPt=$this->fwPt; - $this->hPt=$this->fhPt; - } - elseif($orientation=='l' or $orientation=='landscape') - { - $this->DefOrientation='L'; - $this->wPt=$this->fhPt; - $this->hPt=$this->fwPt; - } - else - $this->Error('Incorrect orientation: '.$orientation); - $this->CurOrientation=$this->DefOrientation; - $this->w=$this->wPt/$this->k; - $this->h=$this->hPt/$this->k; - //Page margins (1 cm) - $margin=28.35/$this->k; - $this->SetMargins($margin,$margin); - //Interior cell margin (1 mm) - $this->cMargin=$margin/10; - //Line width (0.2 mm) - $this->LineWidth=.567/$this->k; - //Automatic page break - $this->SetAutoPageBreak(true,2*$margin); - //Full width display mode - $this->SetDisplayMode('fullwidth'); - //Compression - $this->SetCompression(true); + $this->Error('Unknown page format: '.$format); + $this->fwPt=$format[0]; + $this->fhPt=$format[1]; } - - /** - * - * - * @param int - * @param int - * @param int - */ - function SetMargins($left,$top,$right=-1) + else { - //Set left, top and right margins - $this->lMargin=$left; - $this->tMargin=$top; - if($right==-1) - $right=$left; - $this->rMargin=$right; + $this->fwPt=$format[0]*$this->k; + $this->fhPt=$format[1]*$this->k; } - - /** - * - * - * @param int - */ - function SetLeftMargin($margin) + $this->fw=$this->fwPt/$this->k; + $this->fh=$this->fhPt/$this->k; + //Page orientation + $orientation=strtolower($orientation); + if($orientation=='p' || $orientation=='portrait') { - //Set left margin - $this->lMargin=$margin; - if($this->page>0 and $this->x<$margin) - $this->x=$margin; + $this->DefOrientation='P'; + $this->wPt=$this->fwPt; + $this->hPt=$this->fhPt; } - - /** - * - * - * @param int - */ - function SetTopMargin($margin) + elseif($orientation=='l' || $orientation=='landscape') { - //Set top margin - $this->tMargin=$margin; - } - - /** - * - * - * @param int - */ - function SetRightMargin($margin) - { - //Set right margin - $this->rMargin=$margin; - } - - /** - * - * - * @param boolean - * @param int - */ - function SetAutoPageBreak($auto,$margin=0) - { - //Set auto page break mode and triggering margin - $this->AutoPageBreak=$auto; - $this->bMargin=$margin; - $this->PageBreakTrigger=$this->h-$margin; - } - - /** - * - * - * @param string - * @param string - */ - function SetDisplayMode($zoom,$layout='continuous') - { - //Set display mode in viewer - if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom)) - $this->ZoomMode=$zoom; - else - $this->Error('Incorrect zoom display mode: '.$zoom); - if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default') - $this->LayoutMode=$layout; - else - $this->Error('Incorrect layout display mode: '.$layout); - } - - /** - * - * - * @param string - */ - function SetCompression($compress) - { - //Set page compression - if(function_exists('gzcompress')) - $this->compress=$compress; - else - $this->compress=false; + $this->DefOrientation='L'; + $this->wPt=$this->fhPt; + $this->hPt=$this->fwPt; } + else + $this->Error('Incorrect orientation: '.$orientation); + $this->CurOrientation=$this->DefOrientation; + $this->w=$this->wPt/$this->k; + $this->h=$this->hPt/$this->k; + //Page margins (1 cm) + $margin=28.35/$this->k; + $this->SetMargins($margin,$margin); + //Interior cell margin (1 mm) + $this->cMargin=$margin/10; + //Line width (0.2 mm) + $this->LineWidth=.567/$this->k; + //Automatic page break + $this->SetAutoPageBreak(true,2*$margin); + //Full width display mode + $this->SetDisplayMode('fullwidth'); + //Enable compression + $this->SetCompression(true); + //Set default PDF version number + $this->PDFVersion='1.3'; +} + +function SetMargins($left,$top,$right=-1) +{ + //Set left, top and right margins + $this->lMargin=$left; + $this->tMargin=$top; + if($right==-1) + $right=$left; + $this->rMargin=$right; +} + +function SetLeftMargin($margin) +{ + //Set left margin + $this->lMargin=$margin; + if($this->page>0 && $this->x<$margin) + $this->x=$margin; +} + +function SetTopMargin($margin) +{ + //Set top margin + $this->tMargin=$margin; +} + +function SetRightMargin($margin) +{ + //Set right margin + $this->rMargin=$margin; +} + +function SetAutoPageBreak($auto,$margin=0) +{ + //Set auto page break mode and triggering margin + $this->AutoPageBreak=$auto; + $this->bMargin=$margin; + $this->PageBreakTrigger=$this->h-$margin; +} + +function SetDisplayMode($zoom,$layout='continuous') +{ + //Set display mode in viewer + if($zoom=='fullpage' || $zoom=='fullwidth' || $zoom=='real' || $zoom=='default' || !is_string($zoom)) + $this->ZoomMode=$zoom; + else + $this->Error('Incorrect zoom display mode: '.$zoom); + if($layout=='single' || $layout=='continuous' || $layout=='two' || $layout=='default') + $this->LayoutMode=$layout; + else + $this->Error('Incorrect layout display mode: '.$layout); +} + +function SetCompression($compress) +{ + //Set page compression + if(function_exists('gzcompress')) + $this->compress=$compress; + else + $this->compress=false; +} function SetTitle($title) { @@ -339,8 +285,7 @@ function Error($msg) function Open() { //Begin document - if($this->state==0) - $this->_begindoc(); + $this->state=1; } function Close() @@ -446,7 +391,7 @@ function PageNo() function SetDrawColor($r,$g=-1,$b=-1) { //Set color for all stroking operations - if(($r==0 and $g==0 and $b==0) or $g==-1) + if(($r==0 && $g==0 && $b==0) || $g==-1) $this->DrawColor=sprintf('%.3f G',$r/255); else $this->DrawColor=sprintf('%.3f %.3f %.3f RG',$r/255,$g/255,$b/255); @@ -457,7 +402,7 @@ function SetDrawColor($r,$g=-1,$b=-1) function SetFillColor($r,$g=-1,$b=-1) { //Set color for all filling operations - if(($r==0 and $g==0 and $b==0) or $g==-1) + if(($r==0 && $g==0 && $b==0) || $g==-1) $this->FillColor=sprintf('%.3f g',$r/255); else $this->FillColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); @@ -469,7 +414,7 @@ function SetFillColor($r,$g=-1,$b=-1) function SetTextColor($r,$g=-1,$b=-1) { //Set color for text - if(($r==0 and $g==0 and $b==0) or $g==-1) + if(($r==0 && $g==0 && $b==0) || $g==-1) $this->TextColor=sprintf('%.3f g',$r/255); else $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); @@ -507,7 +452,7 @@ function Rect($x,$y,$w,$h,$style='') //Draw a rectangle if($style=='F') $op='f'; - elseif($style=='FD' or $style=='DF') + elseif($style=='FD' || $style=='DF') $op='B'; else $op='S'; @@ -518,39 +463,40 @@ function AddFont($family,$style='',$file='') { //Add a TrueType or Type1 font $family=strtolower($family); + if($file=='') + $file=str_replace(' ','',$family).strtolower($style).'.php'; if($family=='arial') $family='helvetica'; $style=strtoupper($style); if($style=='IB') $style='BI'; - if(isset($this->fonts[$family.$style])) + $fontkey=$family.$style; + if(isset($this->fonts[$fontkey])) $this->Error('Font already added: '.$family.' '.$style); - if($file=='') - $file=str_replace(' ','',$family).strtolower($style).'.php'; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - include($file); + include($this->_getfontpath().$file); if(!isset($name)) $this->Error('Could not include font definition file'); $i=count($this->fonts)+1; - $this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); + $this->fonts[$fontkey]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file); if($diff) { //Search existing encodings $d=0; $nb=count($this->diffs); for($i=1;$i<=$nb;$i++) + { if($this->diffs[$i]==$diff) { $d=$i; break; } + } if($d==0) { $d=$nb+1; $this->diffs[$d]=$diff; } - $this->fonts[$family.$style]['diff']=$d; + $this->fonts[$fontkey]['diff']=$d; } if($file) { @@ -571,10 +517,10 @@ function SetFont($family,$style='',$size=0) $family=$this->FontFamily; if($family=='arial') $family='helvetica'; - elseif($family=='symbol' or $family=='zapfdingbats') + elseif($family=='symbol' || $family=='zapfdingbats') $style=''; $style=strtoupper($style); - if(is_int(strpos($style,'U'))) + if(strpos($style,'U')!==false) { $this->underline=true; $style=str_replace('U','',$style); @@ -586,7 +532,7 @@ function SetFont($family,$style='',$size=0) if($size==0) $size=$this->FontSizePt; //Test if font is already selected - if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) + if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size) return; //Test if used for the first time $fontkey=$family.$style; @@ -599,12 +545,9 @@ function SetFont($family,$style='',$size=0) { //Load metric file $file=$family; - if($family=='times' or $family=='helvetica') + if($family=='times' || $family=='helvetica') $file.=strtolower($style); - $file.='.php'; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - include($file); + include($this->_getfontpath().$file.'.php'); if(!isset($fpdf_charwidths[$fontkey])) $this->Error('Could not include font metric file'); } @@ -663,7 +606,7 @@ function Text($x,$y,$txt) { //Output a string $s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt)); - if($this->underline and $txt!='') + if($this->underline && $txt!='') $s.=' '.$this->_dounderline($x,$y,$txt); if($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q'; @@ -680,7 +623,7 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') { //Output a cell $k=$this->k; - if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak()) + if($this->y+$h>$this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) { //Automatic page break $x=$this->x; @@ -701,7 +644,7 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') if($w==0) $w=$this->w-$this->rMargin-$this->x; $s=''; - if($fill==1 or $border==1) + if($fill==1 || $border==1) { if($fill==1) $op=($border==1) ? 'B' : 'f'; @@ -713,16 +656,16 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='') { $x=$this->x; $y=$this->y; - if(is_int(strpos($border,'L'))) + if(strpos($border,'L')!==false) $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'T'))) + if(strpos($border,'T')!==false) $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k); - if(is_int(strpos($border,'R'))) + if(strpos($border,'R')!==false) $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k); - if(is_int(strpos($border,'B'))) + if(strpos($border,'B')!==false) $s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k); } - if($txt!='') + if($txt!=='') { if($align=='R') $dx=$w-$this->cMargin-$this->GetStringWidth($txt); @@ -764,7 +707,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; $s=str_replace("\r",'',$txt); $nb=strlen($s); - if($nb>0 and $s[$nb-1]=="\n") + if($nb>0 && $s[$nb-1]=="\n") $nb--; $b=0; if($border) @@ -778,11 +721,11 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) else { $b2=''; - if(is_int(strpos($border,'L'))) + if(strpos($border,'L')!==false) $b2.='L'; - if(is_int(strpos($border,'R'))) + if(strpos($border,'R')!==false) $b2.='R'; - $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; + $b=(strpos($border,'T')!==false) ? $b2.'T' : $b2; } } $sep=-1; @@ -810,7 +753,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) $l=0; $ns=0; $nl++; - if($border and $nl==2) + if($border && $nl==2) $b=$b2; continue; } @@ -850,7 +793,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) $l=0; $ns=0; $nl++; - if($border and $nl==2) + if($border && $nl==2) $b=$b2; } else @@ -862,7 +805,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0) $this->ws=0; $this->_out('0 Tw'); } - if($border and is_int(strpos($border,'B'))) + if($border && strpos($border,'B')!==false) $b.='B'; $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); $this->x=$this->lMargin; @@ -965,7 +908,7 @@ function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') $type=strtolower($type); $mqr=get_magic_quotes_runtime(); set_magic_quotes_runtime(0); - if($type=='jpg' or $type=='jpeg') + if($type=='jpg' || $type=='jpeg') $info=$this->_parsejpg($file); elseif($type=='png') $info=$this->_parsepng($file); @@ -984,7 +927,7 @@ function Image($file,$x,$y,$w=0,$h=0,$type='',$link='') else $info=$this->images[$file]; //Automatic width and height calculation if needed - if($w==0 and $h==0) + if($w==0 && $h==0) { //Put image at 72 dpi $w=$info['w']/$this->k; @@ -1050,8 +993,6 @@ function SetXY($x,$y) function Output($name='',$dest='') { //Output PDF to some destination - global $HTTP_SERVER_VARS; - //Finish document if necessary if($this->state<3) $this->Close(); @@ -1073,27 +1014,31 @@ function Output($name='',$dest='') { case 'I': //Send to standard output - if(isset($HTTP_SERVER_VARS['SERVER_NAME'])) + if(ob_get_contents()) + $this->Error('Some data has already been output, can\'t send PDF file'); + if(php_sapi_name()!='cli') { //We send to a browser - Header('Content-Type: application/pdf'); + header('Content-Type: application/pdf'); if(headers_sent()) $this->Error('Some data has already been output to browser, can\'t send PDF file'); - Header('Content-Length: '.strlen($this->buffer)); - Header('Content-disposition: inline; filename='.$name); + header('Content-Length: '.strlen($this->buffer)); + header('Content-disposition: inline; filename="'.$name.'"'); } echo $this->buffer; break; case 'D': //Download file - if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE')) - Header('Content-Type: application/force-download'); + if(ob_get_contents()) + $this->Error('Some data has already been output, can\'t send PDF file'); + if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')) + header('Content-Type: application/force-download'); else - Header('Content-Type: application/octet-stream'); + header('Content-Type: application/octet-stream'); if(headers_sent()) $this->Error('Some data has already been output to browser, can\'t send PDF file'); - Header('Content-Length: '.strlen($this->buffer)); - Header('Content-disposition: attachment; filename='.$name); + header('Content-Length: '.strlen($this->buffer)); + header('Content-disposition: attachment; filename="'.$name.'"'); echo $this->buffer; break; case 'F': @@ -1128,11 +1073,11 @@ function _dochecks() setlocale(LC_NUMERIC,'C'); } -function _begindoc() +function _getfontpath() { - //Start document - $this->state=1; - $this->_out('%PDF-1.3'); + if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font')) + define('FPDF_FONTPATH',dirname(__FILE__).'/font/'); + return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : ''; } function _putpages() @@ -1223,21 +1168,36 @@ function _putfonts() //Font file embedding $this->_newobj(); $this->FontFiles[$file]['n']=$this->n; - if(defined('FPDF_FONTPATH')) - $file=FPDF_FONTPATH.$file; - $size=filesize($file); - if(!$size) + $font=''; + $f=fopen($this->_getfontpath().$file,'rb',1); + if(!$f) $this->Error('Font file not found'); - $this->_out('<_out('<_out('/Filter /FlateDecode'); $this->_out('/Length1 '.$info['length1']); if(isset($info['length2'])) $this->_out('/Length2 '.$info['length2'].' /Length3 0'); $this->_out('>>'); - $f=fopen($file,'rb'); - $this->_putstream(fread($f,$size)); - fclose($f); + $this->_putstream($font); $this->_out('endobj'); } set_magic_quotes_runtime($mqr); @@ -1254,12 +1214,12 @@ function _putfonts() $this->_out('<_out('/BaseFont /'.$name); $this->_out('/Subtype /Type1'); - if($name!='Symbol' and $name!='ZapfDingbats') + if($name!='Symbol' && $name!='ZapfDingbats') $this->_out('/Encoding /WinAnsiEncoding'); $this->_out('>>'); $this->_out('endobj'); } - elseif($type=='Type1' or $type=='TrueType') + elseif($type=='Type1' || $type=='TrueType') { //Additional Type1 or TrueType font $this->_newobj(); @@ -1329,10 +1289,11 @@ function _putimages() $this->_out('/Decode [1 0 1 0 1 0 1 0]'); } $this->_out('/BitsPerComponent '.$info['bpc']); - $this->_out('/Filter /'.$info['f']); + if(isset($info['f'])) + $this->_out('/Filter /'.$info['f']); if(isset($info['parms'])) $this->_out($info['parms']); - if(isset($info['trns']) and is_array($info['trns'])) + if(isset($info['trns']) && is_array($info['trns'])) { $trns=''; for($i=0;$iimages as $image) + $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); +} + +function _putresourcedict() +{ + $this->_out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]'); + $this->_out('/Font <<'); + foreach($this->fonts as $font) + $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); + $this->_out('>>'); + $this->_out('/XObject <<'); + $this->_putxobjectdict(); + $this->_out('>>'); +} + function _putresources() { $this->_putfonts(); @@ -1362,18 +1341,8 @@ function _putresources() //Resource dictionary $this->offsets[2]=strlen($this->buffer); $this->_out('2 0 obj'); - $this->_out('<_out('/Font <<'); - foreach($this->fonts as $font) - $this->_out('/F'.$font['i'].' '.$font['n'].' 0 R'); - $this->_out('>>'); - if(count($this->images)) - { - $this->_out('/XObject <<'); - foreach($this->images as $image) - $this->_out('/I'.$image['i'].' '.$image['n'].' 0 R'); - $this->_out('>>'); - } + $this->_out('<<'); + $this->_putresourcedict(); $this->_out('>>'); $this->_out('endobj'); } @@ -1414,6 +1383,11 @@ function _putcatalog() $this->_out('/PageLayout /TwoColumnLeft'); } +function _putheader() +{ + $this->_out('%PDF-'.$this->PDFVersion); +} + function _puttrailer() { $this->_out('/Size '.($this->n+1)); @@ -1423,6 +1397,7 @@ function _puttrailer() function _enddoc() { + $this->_putheader(); $this->_putpages(); $this->_putresources(); //Info @@ -1525,7 +1500,7 @@ function _parsejpg($file) $this->Error('Missing or incorrect image file: '.$file); if($a[2]!=2) $this->Error('Not a JPEG file: '.$file); - if(!isset($a['channels']) or $a['channels']==3) + if(!isset($a['channels']) || $a['channels']==3) $colspace='DeviceRGB'; elseif($a['channels']==4) $colspace='DeviceCMYK'; @@ -1601,7 +1576,7 @@ function _parsepng($file) else { $pos=strpos($t,chr(0)); - if(is_int($pos)) + if($pos!==false) $trns=array($pos); } fread($f,4); @@ -1618,7 +1593,7 @@ function _parsepng($file) fread($f,$n+4); } while($n); - if($colspace=='Indexed' and empty($pal)) + if($colspace=='Indexed' && empty($pal)) $this->Error('Missing palette in '.$file); fclose($f); return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); @@ -1627,11 +1602,8 @@ function _parsepng($file) function _freadint($f) { //Read a 4-byte integer from file - $i=ord(fread($f,1))<<24; - $i+=ord(fread($f,1))<<16; - $i+=ord(fread($f,1))<<8; - $i+=ord(fread($f,1)); - return $i; + $a=unpack('Ni',fread($f,4)); + return $a['i']; } function _textstring($s) @@ -1665,9 +1637,9 @@ function _out($s) } //Handle special IE contype request -if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') +if(isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']=='contype') { - Header('Content-Type: application/pdf'); + header('Content-Type: application/pdf'); exit; }