updated to new version with changed license
This commit is contained in:
parent
305634fa1b
commit
e653105d86
|
@ -1,14 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/****************************************************************************
|
/*******************************************************************************
|
||||||
* Software: FPDF *
|
* Software: FPDF *
|
||||||
* Version: 1.51 *
|
* Version: 1.52 *
|
||||||
* Date: 2002/08/03 *
|
* Date: 2003-12-30 *
|
||||||
* Author: Olivier PLATHEY *
|
* Author: Olivier PLATHEY *
|
||||||
* License: Freeware *
|
* License: Freeware *
|
||||||
* *
|
* *
|
||||||
* You may use and modify this software as you wish. *
|
* You may use, modify and redistribute this software as you wish. *
|
||||||
****************************************************************************/
|
*******************************************************************************/
|
||||||
define('FPDF_VERSION','1.51');
|
|
||||||
|
if(!class_exists('FPDF'))
|
||||||
|
{
|
||||||
|
define('FPDF_VERSION','1.52');
|
||||||
|
|
||||||
class FPDF
|
class FPDF
|
||||||
{
|
{
|
||||||
|
@ -23,17 +26,17 @@ var $compress; //compression flag
|
||||||
var $DefOrientation; //default orientation
|
var $DefOrientation; //default orientation
|
||||||
var $CurOrientation; //current orientation
|
var $CurOrientation; //current orientation
|
||||||
var $OrientationChanges; //array indicating orientation changes
|
var $OrientationChanges; //array indicating orientation changes
|
||||||
|
var $k; //scale factor (number of points in user unit)
|
||||||
var $fwPt,$fhPt; //dimensions of page format in points
|
var $fwPt,$fhPt; //dimensions of page format in points
|
||||||
var $fw,$fh; //dimensions of page format in user unit
|
var $fw,$fh; //dimensions of page format in user unit
|
||||||
var $wPt,$hPt; //current dimensions of page in points
|
var $wPt,$hPt; //current dimensions of page in points
|
||||||
var $k; //scale factor (number of points in user unit)
|
|
||||||
var $w,$h; //current dimensions of page in user unit
|
var $w,$h; //current dimensions of page in user unit
|
||||||
var $lMargin; //left margin
|
var $lMargin; //left margin
|
||||||
var $tMargin; //top margin
|
var $tMargin; //top margin
|
||||||
var $rMargin; //right margin
|
var $rMargin; //right margin
|
||||||
var $bMargin; //page break margin
|
var $bMargin; //page break margin
|
||||||
var $cMargin; //cell margin
|
var $cMargin; //cell margin
|
||||||
var $x,$y; //current position in user unit for cell positionning
|
var $x,$y; //current position in user unit for cell positioning
|
||||||
var $lasth; //height of last cell printed
|
var $lasth; //height of last cell printed
|
||||||
var $LineWidth; //line width in user unit
|
var $LineWidth; //line width in user unit
|
||||||
var $CoreFonts; //array of standard font names
|
var $CoreFonts; //array of standard font names
|
||||||
|
@ -66,16 +69,15 @@ var $keywords; //keywords
|
||||||
var $creator; //creator
|
var $creator; //creator
|
||||||
var $AliasNbPages; //alias for total number of pages
|
var $AliasNbPages; //alias for total number of pages
|
||||||
|
|
||||||
/****************************************************************************
|
/*******************************************************************************
|
||||||
* *
|
* *
|
||||||
* Public methods *
|
* Public methods *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
*******************************************************************************/
|
||||||
function FPDF($orientation='P',$unit='mm',$format='A4')
|
function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
{
|
{
|
||||||
//Check for PHP locale-related bug
|
//Some checks
|
||||||
if(1.1==1)
|
$this->_dochecks();
|
||||||
$this->Error('Don\'t alter the locale before including class file');
|
|
||||||
//Initialization of properties
|
//Initialization of properties
|
||||||
$this->page=0;
|
$this->page=0;
|
||||||
$this->n=2;
|
$this->n=2;
|
||||||
|
@ -89,6 +91,7 @@ function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
$this->images=array();
|
$this->images=array();
|
||||||
$this->links=array();
|
$this->links=array();
|
||||||
$this->InFooter=false;
|
$this->InFooter=false;
|
||||||
|
$this->lasth=0;
|
||||||
$this->FontFamily='';
|
$this->FontFamily='';
|
||||||
$this->FontStyle='';
|
$this->FontStyle='';
|
||||||
$this->FontSizePt=12;
|
$this->FontSizePt=12;
|
||||||
|
@ -99,20 +102,10 @@ function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
$this->ColorFlag=false;
|
$this->ColorFlag=false;
|
||||||
$this->ws=0;
|
$this->ws=0;
|
||||||
//Standard fonts
|
//Standard fonts
|
||||||
$this->CoreFonts['courier']='Courier';
|
$this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique',
|
||||||
$this->CoreFonts['courierB']='Courier-Bold';
|
'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique',
|
||||||
$this->CoreFonts['courierI']='Courier-Oblique';
|
'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic',
|
||||||
$this->CoreFonts['courierBI']='Courier-BoldOblique';
|
'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats');
|
||||||
$this->CoreFonts['helvetica']='Helvetica';
|
|
||||||
$this->CoreFonts['helveticaB']='Helvetica-Bold';
|
|
||||||
$this->CoreFonts['helveticaI']='Helvetica-Oblique';
|
|
||||||
$this->CoreFonts['helveticaBI']='Helvetica-BoldOblique';
|
|
||||||
$this->CoreFonts['times']='Times-Roman';
|
|
||||||
$this->CoreFonts['timesB']='Times-Bold';
|
|
||||||
$this->CoreFonts['timesI']='Times-Italic';
|
|
||||||
$this->CoreFonts['timesBI']='Times-BoldItalic';
|
|
||||||
$this->CoreFonts['symbol']='Symbol';
|
|
||||||
$this->CoreFonts['zapfdingbats']='ZapfDingbats';
|
|
||||||
//Scale factor
|
//Scale factor
|
||||||
if($unit=='pt')
|
if($unit=='pt')
|
||||||
$this->k=1;
|
$this->k=1;
|
||||||
|
@ -227,13 +220,11 @@ function SetDisplayMode($zoom,$layout='continuous')
|
||||||
//Set display mode in viewer
|
//Set display mode in viewer
|
||||||
if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
|
if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
|
||||||
$this->ZoomMode=$zoom;
|
$this->ZoomMode=$zoom;
|
||||||
elseif($zoom=='zoom')
|
|
||||||
$this->ZoomMode=$layout;
|
|
||||||
else
|
else
|
||||||
$this->Error('Incorrect zoom display mode: '.$zoom);
|
$this->Error('Incorrect zoom display mode: '.$zoom);
|
||||||
if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')
|
if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')
|
||||||
$this->LayoutMode=$layout;
|
$this->LayoutMode=$layout;
|
||||||
elseif($zoom!='zoom')
|
else
|
||||||
$this->Error('Incorrect layout display mode: '.$layout);
|
$this->Error('Incorrect layout display mode: '.$layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,12 +282,15 @@ function Error($msg)
|
||||||
function Open()
|
function Open()
|
||||||
{
|
{
|
||||||
//Begin document
|
//Begin document
|
||||||
$this->_begindoc();
|
if($this->state==0)
|
||||||
|
$this->_begindoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Close()
|
function Close()
|
||||||
{
|
{
|
||||||
//Terminate document
|
//Terminate document
|
||||||
|
if($this->state==3)
|
||||||
|
return;
|
||||||
if($this->page==0)
|
if($this->page==0)
|
||||||
$this->AddPage();
|
$this->AddPage();
|
||||||
//Page footer
|
//Page footer
|
||||||
|
@ -312,6 +306,8 @@ function Close()
|
||||||
function AddPage($orientation='')
|
function AddPage($orientation='')
|
||||||
{
|
{
|
||||||
//Start a new page
|
//Start a new page
|
||||||
|
if($this->state==0)
|
||||||
|
$this->Open();
|
||||||
$family=$this->FontFamily;
|
$family=$this->FontFamily;
|
||||||
$style=$this->FontStyle.($this->underline ? 'U' : '');
|
$style=$this->FontStyle.($this->underline ? 'U' : '');
|
||||||
$size=$this->FontSizePt;
|
$size=$this->FontSizePt;
|
||||||
|
@ -609,8 +605,7 @@ function Link($x,$y,$w,$h,$link)
|
||||||
function Text($x,$y,$txt)
|
function Text($x,$y,$txt)
|
||||||
{
|
{
|
||||||
//Output a string
|
//Output a string
|
||||||
$txt=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
||||||
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$txt);
|
|
||||||
if($this->underline and $txt!='')
|
if($this->underline and $txt!='')
|
||||||
$s.=' '.$this->_dounderline($x,$y,$txt);
|
$s.=' '.$this->_dounderline($x,$y,$txt);
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
|
@ -630,6 +625,7 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')
|
||||||
$k=$this->k;
|
$k=$this->k;
|
||||||
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak())
|
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak())
|
||||||
{
|
{
|
||||||
|
//Automatic page break
|
||||||
$x=$this->x;
|
$x=$this->x;
|
||||||
$ws=$this->ws;
|
$ws=$this->ws;
|
||||||
if($ws>0)
|
if($ws>0)
|
||||||
|
@ -677,10 +673,10 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')
|
||||||
$dx=($w-$this->GetStringWidth($txt))/2;
|
$dx=($w-$this->GetStringWidth($txt))/2;
|
||||||
else
|
else
|
||||||
$dx=$this->cMargin;
|
$dx=$this->cMargin;
|
||||||
$txt=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
$s.='q '.$this->TextColor.' ';
|
$s.='q '.$this->TextColor.' ';
|
||||||
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt);
|
$txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
||||||
|
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
|
||||||
if($this->underline)
|
if($this->underline)
|
||||||
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
|
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
|
@ -741,7 +737,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)
|
||||||
while($i<$nb)
|
while($i<$nb)
|
||||||
{
|
{
|
||||||
//Get next character
|
//Get next character
|
||||||
$c=$s[$i];
|
$c=$s{$i};
|
||||||
if($c=="\n")
|
if($c=="\n")
|
||||||
{
|
{
|
||||||
//Explicit line break
|
//Explicit line break
|
||||||
|
@ -811,7 +807,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)
|
||||||
}
|
}
|
||||||
if($border and is_int(strpos($border,'B')))
|
if($border and is_int(strpos($border,'B')))
|
||||||
$b.='B';
|
$b.='B';
|
||||||
$this->Cell($w,$h,substr($s,$j,$i),$b,2,$align,$fill);
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
|
||||||
$this->x=$this->lMargin;
|
$this->x=$this->lMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,10 +846,7 @@ function Write($h,$txt,$link='')
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($c==' ')
|
if($c==' ')
|
||||||
{
|
|
||||||
$sep=$i;
|
$sep=$i;
|
||||||
$ls=$l;
|
|
||||||
}
|
|
||||||
$l+=$cw[$c];
|
$l+=$cw[$c];
|
||||||
if($l>$wmax)
|
if($l>$wmax)
|
||||||
{
|
{
|
||||||
|
@ -896,10 +889,10 @@ function Write($h,$txt,$link='')
|
||||||
}
|
}
|
||||||
//Last chunk
|
//Last chunk
|
||||||
if($i!=$j)
|
if($i!=$j)
|
||||||
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i),0,0,'',0,$link);
|
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Image($file,$x,$y,$w,$h=0,$type='',$link='')
|
function Image($file,$x,$y,$w=0,$h=0,$type='',$link='')
|
||||||
{
|
{
|
||||||
//Put an image on the page
|
//Put an image on the page
|
||||||
if(!isset($this->images[$file]))
|
if(!isset($this->images[$file]))
|
||||||
|
@ -920,14 +913,26 @@ function Image($file,$x,$y,$w,$h=0,$type='',$link='')
|
||||||
elseif($type=='png')
|
elseif($type=='png')
|
||||||
$info=$this->_parsepng($file);
|
$info=$this->_parsepng($file);
|
||||||
else
|
else
|
||||||
$this->Error('Unsupported image file type: '.$type);
|
{
|
||||||
|
//Allow for additional formats
|
||||||
|
$mtd='_parse'.$type;
|
||||||
|
if(!method_exists($this,$mtd))
|
||||||
|
$this->Error('Unsupported image type: '.$type);
|
||||||
|
$info=$this->$mtd($file);
|
||||||
|
}
|
||||||
set_magic_quotes_runtime($mqr);
|
set_magic_quotes_runtime($mqr);
|
||||||
$info['i']=count($this->images)+1;
|
$info['i']=count($this->images)+1;
|
||||||
$this->images[$file]=$info;
|
$this->images[$file]=$info;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$info=$this->images[$file];
|
$info=$this->images[$file];
|
||||||
//Automatic width or height calculation
|
//Automatic width and height calculation if needed
|
||||||
|
if($w==0 and $h==0)
|
||||||
|
{
|
||||||
|
//Put image at 72 dpi
|
||||||
|
$w=$info['w']/$this->k;
|
||||||
|
$h=$info['h']/$this->k;
|
||||||
|
}
|
||||||
if($w==0)
|
if($w==0)
|
||||||
$w=$h*$info['w']/$info['h'];
|
$w=$h*$info['w']/$info['h'];
|
||||||
if($h==0)
|
if($h==0)
|
||||||
|
@ -985,55 +990,87 @@ function SetXY($x,$y)
|
||||||
$this->SetX($x);
|
$this->SetX($x);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Output($file='',$download=false)
|
function Output($name='',$dest='')
|
||||||
{
|
{
|
||||||
//Output PDF to file or browser
|
//Output PDF to some destination
|
||||||
global $HTTP_ENV_VARS;
|
global $HTTP_SERVER_VARS;
|
||||||
|
|
||||||
|
//Finish document if necessary
|
||||||
if($this->state<3)
|
if($this->state<3)
|
||||||
$this->Close();
|
$this->Close();
|
||||||
if($file=='')
|
//Normalize parameters
|
||||||
|
if(is_bool($dest))
|
||||||
|
$dest=$dest ? 'D' : 'F';
|
||||||
|
$dest=strtoupper($dest);
|
||||||
|
if($dest=='')
|
||||||
{
|
{
|
||||||
//Send to browser
|
if($name=='')
|
||||||
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=doc.pdf');
|
|
||||||
echo $this->buffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($download)
|
|
||||||
{
|
{
|
||||||
|
$name='doc.pdf';
|
||||||
|
$dest='I';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$dest='F';
|
||||||
|
}
|
||||||
|
switch($dest)
|
||||||
|
{
|
||||||
|
case 'I':
|
||||||
|
//Send to standard output
|
||||||
|
if(isset($HTTP_SERVER_VARS['SERVER_NAME']))
|
||||||
|
{
|
||||||
|
//We send to a browser
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
echo $this->buffer;
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
//Download file
|
//Download file
|
||||||
if(isset($HTTP_ENV_VARS['HTTP_USER_AGENT']) and strpos($HTTP_ENV_VARS['HTTP_USER_AGENT'],'MSIE 5.5'))
|
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE'))
|
||||||
Header('Content-Type: application/dummy');
|
Header('Content-Type: application/force-download');
|
||||||
else
|
else
|
||||||
Header('Content-Type: application/octet-stream');
|
Header('Content-Type: application/octet-stream');
|
||||||
if(headers_sent())
|
if(headers_sent())
|
||||||
$this->Error('Some data has already been output to browser, can\'t send PDF file');
|
$this->Error('Some data has already been output to browser, can\'t send PDF file');
|
||||||
Header('Content-Length: '.strlen($this->buffer));
|
Header('Content-Length: '.strlen($this->buffer));
|
||||||
Header('Content-disposition: attachment; filename='.$file);
|
Header('Content-disposition: attachment; filename='.$name);
|
||||||
echo $this->buffer;
|
echo $this->buffer;
|
||||||
}
|
break;
|
||||||
else
|
case 'F':
|
||||||
{
|
//Save to local file
|
||||||
//Save file locally
|
$f=fopen($name,'wb');
|
||||||
$f=fopen($file,'wb');
|
|
||||||
if(!$f)
|
if(!$f)
|
||||||
$this->Error('Unable to create output file: '.$file);
|
$this->Error('Unable to create output file: '.$name);
|
||||||
fwrite($f,$this->buffer,strlen($this->buffer));
|
fwrite($f,$this->buffer,strlen($this->buffer));
|
||||||
fclose($f);
|
fclose($f);
|
||||||
}
|
break;
|
||||||
|
case 'S':
|
||||||
|
//Return as a string
|
||||||
|
return $this->buffer;
|
||||||
|
default:
|
||||||
|
$this->Error('Incorrect output destination: '.$dest);
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* *
|
||||||
|
* Protected methods *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
function _dochecks()
|
||||||
|
{
|
||||||
|
//Check for locale-related bug
|
||||||
|
if(1.1==1)
|
||||||
|
$this->Error('Don\'t alter the locale before including class file');
|
||||||
|
//Check for decimal separator
|
||||||
|
if(sprintf('%.1f',1.0)!='1.0')
|
||||||
|
setlocale(LC_NUMERIC,'C');
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* *
|
|
||||||
* Private methods *
|
|
||||||
* *
|
|
||||||
****************************************************************************/
|
|
||||||
function _begindoc()
|
function _begindoc()
|
||||||
{
|
{
|
||||||
//Start document
|
//Start document
|
||||||
|
@ -1150,24 +1187,29 @@ function _putfonts()
|
||||||
foreach($this->fonts as $k=>$font)
|
foreach($this->fonts as $k=>$font)
|
||||||
{
|
{
|
||||||
//Font objects
|
//Font objects
|
||||||
$this->_newobj();
|
$this->fonts[$k]['n']=$this->n+1;
|
||||||
$this->fonts[$k]['n']=$this->n;
|
$type=$font['type'];
|
||||||
$name=$font['name'];
|
$name=$font['name'];
|
||||||
$this->_out('<</Type /Font');
|
if($type=='core')
|
||||||
$this->_out('/BaseFont /'.$name);
|
|
||||||
if($font['type']=='core')
|
|
||||||
{
|
{
|
||||||
//Standard font
|
//Standard font
|
||||||
|
$this->_newobj();
|
||||||
|
$this->_out('<</Type /Font');
|
||||||
|
$this->_out('/BaseFont /'.$name);
|
||||||
$this->_out('/Subtype /Type1');
|
$this->_out('/Subtype /Type1');
|
||||||
if($name!='Symbol' and $name!='ZapfDingbats')
|
if($name!='Symbol' and $name!='ZapfDingbats')
|
||||||
$this->_out('/Encoding /WinAnsiEncoding');
|
$this->_out('/Encoding /WinAnsiEncoding');
|
||||||
|
$this->_out('>>');
|
||||||
|
$this->_out('endobj');
|
||||||
}
|
}
|
||||||
else
|
elseif($type=='Type1' or $type=='TrueType')
|
||||||
{
|
{
|
||||||
//Additional font
|
//Additional Type1 or TrueType font
|
||||||
$this->_out('/Subtype /'.$font['type']);
|
$this->_newobj();
|
||||||
$this->_out('/FirstChar 32');
|
$this->_out('<</Type /Font');
|
||||||
$this->_out('/LastChar 255');
|
$this->_out('/BaseFont /'.$name);
|
||||||
|
$this->_out('/Subtype /'.$type);
|
||||||
|
$this->_out('/FirstChar 32 /LastChar 255');
|
||||||
$this->_out('/Widths '.($this->n+1).' 0 R');
|
$this->_out('/Widths '.($this->n+1).' 0 R');
|
||||||
$this->_out('/FontDescriptor '.($this->n+2).' 0 R');
|
$this->_out('/FontDescriptor '.($this->n+2).' 0 R');
|
||||||
if($font['enc'])
|
if($font['enc'])
|
||||||
|
@ -1177,11 +1219,8 @@ function _putfonts()
|
||||||
else
|
else
|
||||||
$this->_out('/Encoding /WinAnsiEncoding');
|
$this->_out('/Encoding /WinAnsiEncoding');
|
||||||
}
|
}
|
||||||
}
|
$this->_out('>>');
|
||||||
$this->_out('>>');
|
$this->_out('endobj');
|
||||||
$this->_out('endobj');
|
|
||||||
if($font['type']!='core')
|
|
||||||
{
|
|
||||||
//Widths
|
//Widths
|
||||||
$this->_newobj();
|
$this->_newobj();
|
||||||
$cw=&$font['cw'];
|
$cw=&$font['cw'];
|
||||||
|
@ -1197,17 +1236,26 @@ function _putfonts()
|
||||||
$s.=' /'.$k.' '.$v;
|
$s.=' /'.$k.' '.$v;
|
||||||
$file=$font['file'];
|
$file=$font['file'];
|
||||||
if($file)
|
if($file)
|
||||||
$s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
|
$s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
|
||||||
$this->_out($s.'>>');
|
$this->_out($s.'>>');
|
||||||
$this->_out('endobj');
|
$this->_out('endobj');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Allow for additional types
|
||||||
|
$mtd='_put'.strtolower($type);
|
||||||
|
if(!method_exists($this,$mtd))
|
||||||
|
$this->Error('Unsupported font type: '.$type);
|
||||||
|
$this->$mtd($font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _putimages()
|
function _putimages()
|
||||||
{
|
{
|
||||||
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
||||||
foreach($this->images as $file=>$info)
|
reset($this->images);
|
||||||
|
while(list($file,$info)=each($this->images))
|
||||||
{
|
{
|
||||||
$this->_newobj();
|
$this->_newobj();
|
||||||
$this->images[$file]['n']=$this->n;
|
$this->images[$file]['n']=$this->n;
|
||||||
|
@ -1236,6 +1284,7 @@ function _putimages()
|
||||||
}
|
}
|
||||||
$this->_out('/Length '.strlen($info['data']).'>>');
|
$this->_out('/Length '.strlen($info['data']).'>>');
|
||||||
$this->_putstream($info['data']);
|
$this->_putstream($info['data']);
|
||||||
|
unset($this->images[$file]['data']);
|
||||||
$this->_out('endobj');
|
$this->_out('endobj');
|
||||||
//Palette
|
//Palette
|
||||||
if($info['cs']=='Indexed')
|
if($info['cs']=='Indexed')
|
||||||
|
@ -1356,7 +1405,6 @@ function _beginpage($orientation)
|
||||||
$this->state=2;
|
$this->state=2;
|
||||||
$this->x=$this->lMargin;
|
$this->x=$this->lMargin;
|
||||||
$this->y=$this->tMargin;
|
$this->y=$this->tMargin;
|
||||||
$this->lasth=0;
|
|
||||||
$this->FontFamily='';
|
$this->FontFamily='';
|
||||||
//Page orientation
|
//Page orientation
|
||||||
if(!$orientation)
|
if(!$orientation)
|
||||||
|
@ -1429,7 +1477,9 @@ function _parsejpg($file)
|
||||||
$bpc=isset($a['bits']) ? $a['bits'] : 8;
|
$bpc=isset($a['bits']) ? $a['bits'] : 8;
|
||||||
//Read whole file
|
//Read whole file
|
||||||
$f=fopen($file,'rb');
|
$f=fopen($file,'rb');
|
||||||
$data=fread($f,filesize($file));
|
$data='';
|
||||||
|
while(!feof($f))
|
||||||
|
$data.=fread($f,4096);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
|
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
|
||||||
}
|
}
|
||||||
|
@ -1557,11 +1607,12 @@ function _out($s)
|
||||||
//End of class
|
//End of class
|
||||||
}
|
}
|
||||||
|
|
||||||
//Handle silly IE contype request
|
//Handle special IE contype request
|
||||||
if(isset($HTTP_ENV_VARS['HTTP_USER_AGENT']) and $HTTP_ENV_VARS['HTTP_USER_AGENT']=='contype')
|
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype')
|
||||||
{
|
{
|
||||||
Header('Content-Type: application/pdf');
|
Header('Content-Type: application/pdf');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
255
lam/lib/fpdf.php
255
lam/lib/fpdf.php
|
@ -1,14 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
/****************************************************************************
|
/*******************************************************************************
|
||||||
* Software: FPDF *
|
* Software: FPDF *
|
||||||
* Version: 1.51 *
|
* Version: 1.52 *
|
||||||
* Date: 2002/08/03 *
|
* Date: 2003-12-30 *
|
||||||
* Author: Olivier PLATHEY *
|
* Author: Olivier PLATHEY *
|
||||||
* License: Freeware *
|
* License: Freeware *
|
||||||
* *
|
* *
|
||||||
* You may use and modify this software as you wish. *
|
* You may use, modify and redistribute this software as you wish. *
|
||||||
****************************************************************************/
|
*******************************************************************************/
|
||||||
define('FPDF_VERSION','1.51');
|
|
||||||
|
if(!class_exists('FPDF'))
|
||||||
|
{
|
||||||
|
define('FPDF_VERSION','1.52');
|
||||||
|
|
||||||
class FPDF
|
class FPDF
|
||||||
{
|
{
|
||||||
|
@ -23,17 +26,17 @@ var $compress; //compression flag
|
||||||
var $DefOrientation; //default orientation
|
var $DefOrientation; //default orientation
|
||||||
var $CurOrientation; //current orientation
|
var $CurOrientation; //current orientation
|
||||||
var $OrientationChanges; //array indicating orientation changes
|
var $OrientationChanges; //array indicating orientation changes
|
||||||
|
var $k; //scale factor (number of points in user unit)
|
||||||
var $fwPt,$fhPt; //dimensions of page format in points
|
var $fwPt,$fhPt; //dimensions of page format in points
|
||||||
var $fw,$fh; //dimensions of page format in user unit
|
var $fw,$fh; //dimensions of page format in user unit
|
||||||
var $wPt,$hPt; //current dimensions of page in points
|
var $wPt,$hPt; //current dimensions of page in points
|
||||||
var $k; //scale factor (number of points in user unit)
|
|
||||||
var $w,$h; //current dimensions of page in user unit
|
var $w,$h; //current dimensions of page in user unit
|
||||||
var $lMargin; //left margin
|
var $lMargin; //left margin
|
||||||
var $tMargin; //top margin
|
var $tMargin; //top margin
|
||||||
var $rMargin; //right margin
|
var $rMargin; //right margin
|
||||||
var $bMargin; //page break margin
|
var $bMargin; //page break margin
|
||||||
var $cMargin; //cell margin
|
var $cMargin; //cell margin
|
||||||
var $x,$y; //current position in user unit for cell positionning
|
var $x,$y; //current position in user unit for cell positioning
|
||||||
var $lasth; //height of last cell printed
|
var $lasth; //height of last cell printed
|
||||||
var $LineWidth; //line width in user unit
|
var $LineWidth; //line width in user unit
|
||||||
var $CoreFonts; //array of standard font names
|
var $CoreFonts; //array of standard font names
|
||||||
|
@ -66,16 +69,15 @@ var $keywords; //keywords
|
||||||
var $creator; //creator
|
var $creator; //creator
|
||||||
var $AliasNbPages; //alias for total number of pages
|
var $AliasNbPages; //alias for total number of pages
|
||||||
|
|
||||||
/****************************************************************************
|
/*******************************************************************************
|
||||||
* *
|
* *
|
||||||
* Public methods *
|
* Public methods *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
*******************************************************************************/
|
||||||
function FPDF($orientation='P',$unit='mm',$format='A4')
|
function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
{
|
{
|
||||||
//Check for PHP locale-related bug
|
//Some checks
|
||||||
if(1.1==1)
|
$this->_dochecks();
|
||||||
$this->Error('Don\'t alter the locale before including class file');
|
|
||||||
//Initialization of properties
|
//Initialization of properties
|
||||||
$this->page=0;
|
$this->page=0;
|
||||||
$this->n=2;
|
$this->n=2;
|
||||||
|
@ -89,6 +91,7 @@ function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
$this->images=array();
|
$this->images=array();
|
||||||
$this->links=array();
|
$this->links=array();
|
||||||
$this->InFooter=false;
|
$this->InFooter=false;
|
||||||
|
$this->lasth=0;
|
||||||
$this->FontFamily='';
|
$this->FontFamily='';
|
||||||
$this->FontStyle='';
|
$this->FontStyle='';
|
||||||
$this->FontSizePt=12;
|
$this->FontSizePt=12;
|
||||||
|
@ -99,20 +102,10 @@ function FPDF($orientation='P',$unit='mm',$format='A4')
|
||||||
$this->ColorFlag=false;
|
$this->ColorFlag=false;
|
||||||
$this->ws=0;
|
$this->ws=0;
|
||||||
//Standard fonts
|
//Standard fonts
|
||||||
$this->CoreFonts['courier']='Courier';
|
$this->CoreFonts=array('courier'=>'Courier','courierB'=>'Courier-Bold','courierI'=>'Courier-Oblique','courierBI'=>'Courier-BoldOblique',
|
||||||
$this->CoreFonts['courierB']='Courier-Bold';
|
'helvetica'=>'Helvetica','helveticaB'=>'Helvetica-Bold','helveticaI'=>'Helvetica-Oblique','helveticaBI'=>'Helvetica-BoldOblique',
|
||||||
$this->CoreFonts['courierI']='Courier-Oblique';
|
'times'=>'Times-Roman','timesB'=>'Times-Bold','timesI'=>'Times-Italic','timesBI'=>'Times-BoldItalic',
|
||||||
$this->CoreFonts['courierBI']='Courier-BoldOblique';
|
'symbol'=>'Symbol','zapfdingbats'=>'ZapfDingbats');
|
||||||
$this->CoreFonts['helvetica']='Helvetica';
|
|
||||||
$this->CoreFonts['helveticaB']='Helvetica-Bold';
|
|
||||||
$this->CoreFonts['helveticaI']='Helvetica-Oblique';
|
|
||||||
$this->CoreFonts['helveticaBI']='Helvetica-BoldOblique';
|
|
||||||
$this->CoreFonts['times']='Times-Roman';
|
|
||||||
$this->CoreFonts['timesB']='Times-Bold';
|
|
||||||
$this->CoreFonts['timesI']='Times-Italic';
|
|
||||||
$this->CoreFonts['timesBI']='Times-BoldItalic';
|
|
||||||
$this->CoreFonts['symbol']='Symbol';
|
|
||||||
$this->CoreFonts['zapfdingbats']='ZapfDingbats';
|
|
||||||
//Scale factor
|
//Scale factor
|
||||||
if($unit=='pt')
|
if($unit=='pt')
|
||||||
$this->k=1;
|
$this->k=1;
|
||||||
|
@ -227,13 +220,11 @@ function SetDisplayMode($zoom,$layout='continuous')
|
||||||
//Set display mode in viewer
|
//Set display mode in viewer
|
||||||
if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
|
if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))
|
||||||
$this->ZoomMode=$zoom;
|
$this->ZoomMode=$zoom;
|
||||||
elseif($zoom=='zoom')
|
|
||||||
$this->ZoomMode=$layout;
|
|
||||||
else
|
else
|
||||||
$this->Error('Incorrect zoom display mode: '.$zoom);
|
$this->Error('Incorrect zoom display mode: '.$zoom);
|
||||||
if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')
|
if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')
|
||||||
$this->LayoutMode=$layout;
|
$this->LayoutMode=$layout;
|
||||||
elseif($zoom!='zoom')
|
else
|
||||||
$this->Error('Incorrect layout display mode: '.$layout);
|
$this->Error('Incorrect layout display mode: '.$layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,12 +282,15 @@ function Error($msg)
|
||||||
function Open()
|
function Open()
|
||||||
{
|
{
|
||||||
//Begin document
|
//Begin document
|
||||||
$this->_begindoc();
|
if($this->state==0)
|
||||||
|
$this->_begindoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
function Close()
|
function Close()
|
||||||
{
|
{
|
||||||
//Terminate document
|
//Terminate document
|
||||||
|
if($this->state==3)
|
||||||
|
return;
|
||||||
if($this->page==0)
|
if($this->page==0)
|
||||||
$this->AddPage();
|
$this->AddPage();
|
||||||
//Page footer
|
//Page footer
|
||||||
|
@ -312,6 +306,8 @@ function Close()
|
||||||
function AddPage($orientation='')
|
function AddPage($orientation='')
|
||||||
{
|
{
|
||||||
//Start a new page
|
//Start a new page
|
||||||
|
if($this->state==0)
|
||||||
|
$this->Open();
|
||||||
$family=$this->FontFamily;
|
$family=$this->FontFamily;
|
||||||
$style=$this->FontStyle.($this->underline ? 'U' : '');
|
$style=$this->FontStyle.($this->underline ? 'U' : '');
|
||||||
$size=$this->FontSizePt;
|
$size=$this->FontSizePt;
|
||||||
|
@ -609,8 +605,7 @@ function Link($x,$y,$w,$h,$link)
|
||||||
function Text($x,$y,$txt)
|
function Text($x,$y,$txt)
|
||||||
{
|
{
|
||||||
//Output a string
|
//Output a string
|
||||||
$txt=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
|
||||||
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$txt);
|
|
||||||
if($this->underline and $txt!='')
|
if($this->underline and $txt!='')
|
||||||
$s.=' '.$this->_dounderline($x,$y,$txt);
|
$s.=' '.$this->_dounderline($x,$y,$txt);
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
|
@ -630,6 +625,7 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')
|
||||||
$k=$this->k;
|
$k=$this->k;
|
||||||
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak())
|
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak())
|
||||||
{
|
{
|
||||||
|
//Automatic page break
|
||||||
$x=$this->x;
|
$x=$this->x;
|
||||||
$ws=$this->ws;
|
$ws=$this->ws;
|
||||||
if($ws>0)
|
if($ws>0)
|
||||||
|
@ -677,10 +673,10 @@ function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='')
|
||||||
$dx=($w-$this->GetStringWidth($txt))/2;
|
$dx=($w-$this->GetStringWidth($txt))/2;
|
||||||
else
|
else
|
||||||
$dx=$this->cMargin;
|
$dx=$this->cMargin;
|
||||||
$txt=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
$s.='q '.$this->TextColor.' ';
|
$s.='q '.$this->TextColor.' ';
|
||||||
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt);
|
$txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
|
||||||
|
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->FontSize))*$k,$txt2);
|
||||||
if($this->underline)
|
if($this->underline)
|
||||||
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
|
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize,$txt);
|
||||||
if($this->ColorFlag)
|
if($this->ColorFlag)
|
||||||
|
@ -741,7 +737,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)
|
||||||
while($i<$nb)
|
while($i<$nb)
|
||||||
{
|
{
|
||||||
//Get next character
|
//Get next character
|
||||||
$c=$s[$i];
|
$c=$s{$i};
|
||||||
if($c=="\n")
|
if($c=="\n")
|
||||||
{
|
{
|
||||||
//Explicit line break
|
//Explicit line break
|
||||||
|
@ -811,7 +807,7 @@ function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)
|
||||||
}
|
}
|
||||||
if($border and is_int(strpos($border,'B')))
|
if($border and is_int(strpos($border,'B')))
|
||||||
$b.='B';
|
$b.='B';
|
||||||
$this->Cell($w,$h,substr($s,$j,$i),$b,2,$align,$fill);
|
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
|
||||||
$this->x=$this->lMargin;
|
$this->x=$this->lMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -850,10 +846,7 @@ function Write($h,$txt,$link='')
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($c==' ')
|
if($c==' ')
|
||||||
{
|
|
||||||
$sep=$i;
|
$sep=$i;
|
||||||
$ls=$l;
|
|
||||||
}
|
|
||||||
$l+=$cw[$c];
|
$l+=$cw[$c];
|
||||||
if($l>$wmax)
|
if($l>$wmax)
|
||||||
{
|
{
|
||||||
|
@ -896,10 +889,10 @@ function Write($h,$txt,$link='')
|
||||||
}
|
}
|
||||||
//Last chunk
|
//Last chunk
|
||||||
if($i!=$j)
|
if($i!=$j)
|
||||||
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j,$i),0,0,'',0,$link);
|
$this->Cell($l/1000*$this->FontSize,$h,substr($s,$j),0,0,'',0,$link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Image($file,$x,$y,$w,$h=0,$type='',$link='')
|
function Image($file,$x,$y,$w=0,$h=0,$type='',$link='')
|
||||||
{
|
{
|
||||||
//Put an image on the page
|
//Put an image on the page
|
||||||
if(!isset($this->images[$file]))
|
if(!isset($this->images[$file]))
|
||||||
|
@ -920,14 +913,26 @@ function Image($file,$x,$y,$w,$h=0,$type='',$link='')
|
||||||
elseif($type=='png')
|
elseif($type=='png')
|
||||||
$info=$this->_parsepng($file);
|
$info=$this->_parsepng($file);
|
||||||
else
|
else
|
||||||
$this->Error('Unsupported image file type: '.$type);
|
{
|
||||||
|
//Allow for additional formats
|
||||||
|
$mtd='_parse'.$type;
|
||||||
|
if(!method_exists($this,$mtd))
|
||||||
|
$this->Error('Unsupported image type: '.$type);
|
||||||
|
$info=$this->$mtd($file);
|
||||||
|
}
|
||||||
set_magic_quotes_runtime($mqr);
|
set_magic_quotes_runtime($mqr);
|
||||||
$info['i']=count($this->images)+1;
|
$info['i']=count($this->images)+1;
|
||||||
$this->images[$file]=$info;
|
$this->images[$file]=$info;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$info=$this->images[$file];
|
$info=$this->images[$file];
|
||||||
//Automatic width or height calculation
|
//Automatic width and height calculation if needed
|
||||||
|
if($w==0 and $h==0)
|
||||||
|
{
|
||||||
|
//Put image at 72 dpi
|
||||||
|
$w=$info['w']/$this->k;
|
||||||
|
$h=$info['h']/$this->k;
|
||||||
|
}
|
||||||
if($w==0)
|
if($w==0)
|
||||||
$w=$h*$info['w']/$info['h'];
|
$w=$h*$info['w']/$info['h'];
|
||||||
if($h==0)
|
if($h==0)
|
||||||
|
@ -985,55 +990,87 @@ function SetXY($x,$y)
|
||||||
$this->SetX($x);
|
$this->SetX($x);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Output($file='',$download=false)
|
function Output($name='',$dest='')
|
||||||
{
|
{
|
||||||
//Output PDF to file or browser
|
//Output PDF to some destination
|
||||||
global $HTTP_ENV_VARS;
|
global $HTTP_SERVER_VARS;
|
||||||
|
|
||||||
|
//Finish document if necessary
|
||||||
if($this->state<3)
|
if($this->state<3)
|
||||||
$this->Close();
|
$this->Close();
|
||||||
if($file=='')
|
//Normalize parameters
|
||||||
|
if(is_bool($dest))
|
||||||
|
$dest=$dest ? 'D' : 'F';
|
||||||
|
$dest=strtoupper($dest);
|
||||||
|
if($dest=='')
|
||||||
{
|
{
|
||||||
//Send to browser
|
if($name=='')
|
||||||
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=doc.pdf');
|
|
||||||
echo $this->buffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if($download)
|
|
||||||
{
|
{
|
||||||
|
$name='doc.pdf';
|
||||||
|
$dest='I';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$dest='F';
|
||||||
|
}
|
||||||
|
switch($dest)
|
||||||
|
{
|
||||||
|
case 'I':
|
||||||
|
//Send to standard output
|
||||||
|
if(isset($HTTP_SERVER_VARS['SERVER_NAME']))
|
||||||
|
{
|
||||||
|
//We send to a browser
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
echo $this->buffer;
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
//Download file
|
//Download file
|
||||||
if(isset($HTTP_ENV_VARS['HTTP_USER_AGENT']) and strpos($HTTP_ENV_VARS['HTTP_USER_AGENT'],'MSIE 5.5'))
|
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'],'MSIE'))
|
||||||
Header('Content-Type: application/dummy');
|
Header('Content-Type: application/force-download');
|
||||||
else
|
else
|
||||||
Header('Content-Type: application/octet-stream');
|
Header('Content-Type: application/octet-stream');
|
||||||
if(headers_sent())
|
if(headers_sent())
|
||||||
$this->Error('Some data has already been output to browser, can\'t send PDF file');
|
$this->Error('Some data has already been output to browser, can\'t send PDF file');
|
||||||
Header('Content-Length: '.strlen($this->buffer));
|
Header('Content-Length: '.strlen($this->buffer));
|
||||||
Header('Content-disposition: attachment; filename='.$file);
|
Header('Content-disposition: attachment; filename='.$name);
|
||||||
echo $this->buffer;
|
echo $this->buffer;
|
||||||
}
|
break;
|
||||||
else
|
case 'F':
|
||||||
{
|
//Save to local file
|
||||||
//Save file locally
|
$f=fopen($name,'wb');
|
||||||
$f=fopen($file,'wb');
|
|
||||||
if(!$f)
|
if(!$f)
|
||||||
$this->Error('Unable to create output file: '.$file);
|
$this->Error('Unable to create output file: '.$name);
|
||||||
fwrite($f,$this->buffer,strlen($this->buffer));
|
fwrite($f,$this->buffer,strlen($this->buffer));
|
||||||
fclose($f);
|
fclose($f);
|
||||||
}
|
break;
|
||||||
|
case 'S':
|
||||||
|
//Return as a string
|
||||||
|
return $this->buffer;
|
||||||
|
default:
|
||||||
|
$this->Error('Incorrect output destination: '.$dest);
|
||||||
}
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* *
|
||||||
|
* Protected methods *
|
||||||
|
* *
|
||||||
|
*******************************************************************************/
|
||||||
|
function _dochecks()
|
||||||
|
{
|
||||||
|
//Check for locale-related bug
|
||||||
|
if(1.1==1)
|
||||||
|
$this->Error('Don\'t alter the locale before including class file');
|
||||||
|
//Check for decimal separator
|
||||||
|
if(sprintf('%.1f',1.0)!='1.0')
|
||||||
|
setlocale(LC_NUMERIC,'C');
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* *
|
|
||||||
* Private methods *
|
|
||||||
* *
|
|
||||||
****************************************************************************/
|
|
||||||
function _begindoc()
|
function _begindoc()
|
||||||
{
|
{
|
||||||
//Start document
|
//Start document
|
||||||
|
@ -1150,24 +1187,29 @@ function _putfonts()
|
||||||
foreach($this->fonts as $k=>$font)
|
foreach($this->fonts as $k=>$font)
|
||||||
{
|
{
|
||||||
//Font objects
|
//Font objects
|
||||||
$this->_newobj();
|
$this->fonts[$k]['n']=$this->n+1;
|
||||||
$this->fonts[$k]['n']=$this->n;
|
$type=$font['type'];
|
||||||
$name=$font['name'];
|
$name=$font['name'];
|
||||||
$this->_out('<</Type /Font');
|
if($type=='core')
|
||||||
$this->_out('/BaseFont /'.$name);
|
|
||||||
if($font['type']=='core')
|
|
||||||
{
|
{
|
||||||
//Standard font
|
//Standard font
|
||||||
|
$this->_newobj();
|
||||||
|
$this->_out('<</Type /Font');
|
||||||
|
$this->_out('/BaseFont /'.$name);
|
||||||
$this->_out('/Subtype /Type1');
|
$this->_out('/Subtype /Type1');
|
||||||
if($name!='Symbol' and $name!='ZapfDingbats')
|
if($name!='Symbol' and $name!='ZapfDingbats')
|
||||||
$this->_out('/Encoding /WinAnsiEncoding');
|
$this->_out('/Encoding /WinAnsiEncoding');
|
||||||
|
$this->_out('>>');
|
||||||
|
$this->_out('endobj');
|
||||||
}
|
}
|
||||||
else
|
elseif($type=='Type1' or $type=='TrueType')
|
||||||
{
|
{
|
||||||
//Additional font
|
//Additional Type1 or TrueType font
|
||||||
$this->_out('/Subtype /'.$font['type']);
|
$this->_newobj();
|
||||||
$this->_out('/FirstChar 32');
|
$this->_out('<</Type /Font');
|
||||||
$this->_out('/LastChar 255');
|
$this->_out('/BaseFont /'.$name);
|
||||||
|
$this->_out('/Subtype /'.$type);
|
||||||
|
$this->_out('/FirstChar 32 /LastChar 255');
|
||||||
$this->_out('/Widths '.($this->n+1).' 0 R');
|
$this->_out('/Widths '.($this->n+1).' 0 R');
|
||||||
$this->_out('/FontDescriptor '.($this->n+2).' 0 R');
|
$this->_out('/FontDescriptor '.($this->n+2).' 0 R');
|
||||||
if($font['enc'])
|
if($font['enc'])
|
||||||
|
@ -1177,11 +1219,8 @@ function _putfonts()
|
||||||
else
|
else
|
||||||
$this->_out('/Encoding /WinAnsiEncoding');
|
$this->_out('/Encoding /WinAnsiEncoding');
|
||||||
}
|
}
|
||||||
}
|
$this->_out('>>');
|
||||||
$this->_out('>>');
|
$this->_out('endobj');
|
||||||
$this->_out('endobj');
|
|
||||||
if($font['type']!='core')
|
|
||||||
{
|
|
||||||
//Widths
|
//Widths
|
||||||
$this->_newobj();
|
$this->_newobj();
|
||||||
$cw=&$font['cw'];
|
$cw=&$font['cw'];
|
||||||
|
@ -1197,17 +1236,26 @@ function _putfonts()
|
||||||
$s.=' /'.$k.' '.$v;
|
$s.=' /'.$k.' '.$v;
|
||||||
$file=$font['file'];
|
$file=$font['file'];
|
||||||
if($file)
|
if($file)
|
||||||
$s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
|
$s.=' /FontFile'.($type=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';
|
||||||
$this->_out($s.'>>');
|
$this->_out($s.'>>');
|
||||||
$this->_out('endobj');
|
$this->_out('endobj');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Allow for additional types
|
||||||
|
$mtd='_put'.strtolower($type);
|
||||||
|
if(!method_exists($this,$mtd))
|
||||||
|
$this->Error('Unsupported font type: '.$type);
|
||||||
|
$this->$mtd($font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _putimages()
|
function _putimages()
|
||||||
{
|
{
|
||||||
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
$filter=($this->compress) ? '/Filter /FlateDecode ' : '';
|
||||||
foreach($this->images as $file=>$info)
|
reset($this->images);
|
||||||
|
while(list($file,$info)=each($this->images))
|
||||||
{
|
{
|
||||||
$this->_newobj();
|
$this->_newobj();
|
||||||
$this->images[$file]['n']=$this->n;
|
$this->images[$file]['n']=$this->n;
|
||||||
|
@ -1236,6 +1284,7 @@ function _putimages()
|
||||||
}
|
}
|
||||||
$this->_out('/Length '.strlen($info['data']).'>>');
|
$this->_out('/Length '.strlen($info['data']).'>>');
|
||||||
$this->_putstream($info['data']);
|
$this->_putstream($info['data']);
|
||||||
|
unset($this->images[$file]['data']);
|
||||||
$this->_out('endobj');
|
$this->_out('endobj');
|
||||||
//Palette
|
//Palette
|
||||||
if($info['cs']=='Indexed')
|
if($info['cs']=='Indexed')
|
||||||
|
@ -1356,7 +1405,6 @@ function _beginpage($orientation)
|
||||||
$this->state=2;
|
$this->state=2;
|
||||||
$this->x=$this->lMargin;
|
$this->x=$this->lMargin;
|
||||||
$this->y=$this->tMargin;
|
$this->y=$this->tMargin;
|
||||||
$this->lasth=0;
|
|
||||||
$this->FontFamily='';
|
$this->FontFamily='';
|
||||||
//Page orientation
|
//Page orientation
|
||||||
if(!$orientation)
|
if(!$orientation)
|
||||||
|
@ -1429,7 +1477,9 @@ function _parsejpg($file)
|
||||||
$bpc=isset($a['bits']) ? $a['bits'] : 8;
|
$bpc=isset($a['bits']) ? $a['bits'] : 8;
|
||||||
//Read whole file
|
//Read whole file
|
||||||
$f=fopen($file,'rb');
|
$f=fopen($file,'rb');
|
||||||
$data=fread($f,filesize($file));
|
$data='';
|
||||||
|
while(!feof($f))
|
||||||
|
$data.=fread($f,4096);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
|
return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data);
|
||||||
}
|
}
|
||||||
|
@ -1557,11 +1607,12 @@ function _out($s)
|
||||||
//End of class
|
//End of class
|
||||||
}
|
}
|
||||||
|
|
||||||
//Handle silly IE contype request
|
//Handle special IE contype request
|
||||||
if(isset($HTTP_ENV_VARS['HTTP_USER_AGENT']) and $HTTP_ENV_VARS['HTTP_USER_AGENT']=='contype')
|
if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype')
|
||||||
{
|
{
|
||||||
Header('Content-Type: application/pdf');
|
Header('Content-Type: application/pdf');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue