mirror of
https://github.com/rmontanana/inventario2.git
synced 2025-08-16 07:56:00 +00:00
-Actualizado FPdf.php a versión 1.7
-Incluido FPDF_Merge para hacer inventario total (todavía no funciona bien) -Añadido .DS_Store y tmp/* a .gitignore
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1,3 @@
|
||||
nbproject
|
||||
tmp/*
|
||||
.DS_Store
|
||||
|
@@ -133,19 +133,23 @@ class InformeInventario {
|
||||
if (!$resultado) {
|
||||
return $this->bdd->mensajeError($comando);
|
||||
}
|
||||
$salidaTotal = '';
|
||||
//Utiliza un nuevo manejador de base de datos para poder hacer una consulta en los informes
|
||||
$bdatos = new Sql(SERVIDOR, USUARIO, CLAVE, BASEDATOS);
|
||||
$mezcla = new FPDF_Merge();
|
||||
$i = 0;
|
||||
while ($fila = $this->bdd->procesaResultado()) {
|
||||
//$fila=$this->bdd->procesaResultado();
|
||||
$plantilla = file_get_contents($fichero) or die('Fallo en la apertura de la plantilla ' . $fichero);
|
||||
$plantilla = str_replace("{id}", $fila['id'], $plantilla);
|
||||
$plantilla = str_replace("{Descripcion}", utf8_encode($fila['Descripcion']), $plantilla);
|
||||
file_put_contents($salida, $plantilla) or die('Fallo en la escritura de la plantilla ' . $salida);
|
||||
$informe = new InformePDF($this->bdd, $salida, true);
|
||||
$salidaTotal.=$informe->getContenido();
|
||||
$informe = new InformePDF($bdatos, $salida, true);
|
||||
$nombre = "tmp/sal" . $i++ . ".pdf";
|
||||
$informe->guardaArchivo($nombre);
|
||||
$mezcla->add($nombre);
|
||||
}
|
||||
file_put_contents("tmp/prueba.pdf", $salidaTotal);
|
||||
$informe->enviaCabecera();
|
||||
echo $salidaTotal;
|
||||
$nombre = "tmp/total.pdf";
|
||||
$mezcla->output($nombre);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
$type = 'Core';
|
||||
$name = 'Courier';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
for($i=0;$i<=255;$i++)
|
||||
$fpdf_charwidths['courier'][chr($i)]=600;
|
||||
$fpdf_charwidths['courierB']=$fpdf_charwidths['courier'];
|
||||
$fpdf_charwidths['courierI']=$fpdf_charwidths['courier'];
|
||||
$fpdf_charwidths['courierBI']=$fpdf_charwidths['courier'];
|
||||
$cw[chr($i)] = 600;
|
||||
?>
|
||||
|
8
font/courierb.php
Normal file
8
font/courierb.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$type = 'Core';
|
||||
$name = 'Courier-Bold';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
for($i=0;$i<=255;$i++)
|
||||
$cw[chr($i)] = 600;
|
||||
?>
|
8
font/courierbi.php
Normal file
8
font/courierbi.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$type = 'Core';
|
||||
$name = 'Courier-BoldOblique';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
for($i=0;$i<=255;$i++)
|
||||
$cw[chr($i)] = 600;
|
||||
?>
|
8
font/courieri.php
Normal file
8
font/courieri.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$type = 'Core';
|
||||
$name = 'Courier-Oblique';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
for($i=0;$i<=255;$i++)
|
||||
$cw[chr($i)] = 600;
|
||||
?>
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['helvetica']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Helvetica';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
|
||||
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
|
||||
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['helveticaB']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Helvetica-Bold';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
|
||||
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584,
|
||||
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['helveticaBI']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Helvetica-BoldOblique';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
|
||||
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584,
|
||||
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['helveticaI']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Helvetica-Oblique';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
|
||||
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
|
||||
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
|
||||
|
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
/*******************************************************************************
|
||||
* Utility to generate font definition files *
|
||||
* Version: 1.13 *
|
||||
* Date: 2004-12-31 *
|
||||
* *
|
||||
* Version: 1.14 *
|
||||
* Date: 2008-08-03 *
|
||||
* Author: Olivier PLATHEY *
|
||||
*******************************************************************************/
|
||||
|
||||
function ReadMap($enc)
|
||||
@@ -11,11 +13,11 @@ function ReadMap($enc)
|
||||
$file=dirname(__FILE__).'/'.strtolower($enc).'.map';
|
||||
$a=file($file);
|
||||
if(empty($a))
|
||||
die('<B>Error:</B> encoding not found: '.$enc);
|
||||
die('<b>Error:</b> encoding not found: '.$enc);
|
||||
$cc2gn=array();
|
||||
foreach($a as $l)
|
||||
{
|
||||
if($l{0}=='!')
|
||||
if($l[0]=='!')
|
||||
{
|
||||
$e=preg_split('/[ \\t]+/',rtrim($l));
|
||||
$cc=hexdec(substr($e[0],1));
|
||||
@@ -31,7 +33,7 @@ function ReadMap($enc)
|
||||
return $cc2gn;
|
||||
}
|
||||
|
||||
function ReadAFM($file,&$map)
|
||||
function ReadAFM($file, &$map)
|
||||
{
|
||||
//Read a font metric file
|
||||
$a=file($file);
|
||||
@@ -114,14 +116,14 @@ function ReadAFM($file,&$map)
|
||||
{
|
||||
if(!isset($widths['.notdef']))
|
||||
$widths['.notdef']=600;
|
||||
if(!isset($widths['Delta']) and isset($widths['increment']))
|
||||
if(!isset($widths['Delta']) && isset($widths['increment']))
|
||||
$widths['Delta']=$widths['increment'];
|
||||
//Order widths according to map
|
||||
for($i=0;$i<=255;$i++)
|
||||
{
|
||||
if(!isset($widths[$map[$i]]))
|
||||
{
|
||||
echo '<B>Warning:</B> character '.$map[$i].' is missing<BR>';
|
||||
echo '<b>Warning:</b> character '.$map[$i].' is missing<br>';
|
||||
$widths[$i]=$widths['.notdef'];
|
||||
}
|
||||
else
|
||||
@@ -132,7 +134,7 @@ function ReadAFM($file,&$map)
|
||||
return $fm;
|
||||
}
|
||||
|
||||
function MakeFontDescriptor($fm,$symbolic)
|
||||
function MakeFontDescriptor($fm, $symbolic)
|
||||
{
|
||||
//Ascent
|
||||
$asc=(isset($fm['Ascender']) ? $fm['Ascender'] : 1000);
|
||||
@@ -150,20 +152,20 @@ function MakeFontDescriptor($fm,$symbolic)
|
||||
$fd.=",'CapHeight'=>".$ch;
|
||||
//Flags
|
||||
$flags=0;
|
||||
if(isset($fm['IsFixedPitch']) and $fm['IsFixedPitch'])
|
||||
if(isset($fm['IsFixedPitch']) && $fm['IsFixedPitch'])
|
||||
$flags+=1<<0;
|
||||
if($symbolic)
|
||||
$flags+=1<<2;
|
||||
if(!$symbolic)
|
||||
$flags+=1<<5;
|
||||
if(isset($fm['ItalicAngle']) and $fm['ItalicAngle']!=0)
|
||||
if(isset($fm['ItalicAngle']) && $fm['ItalicAngle']!=0)
|
||||
$flags+=1<<6;
|
||||
$fd.=",'Flags'=>".$flags;
|
||||
//FontBBox
|
||||
if(isset($fm['FontBBox']))
|
||||
$fbb=$fm['FontBBox'];
|
||||
else
|
||||
$fbb=array(0,$des-100,1000,$asc+100);
|
||||
$fbb=array(0,$desc-100,1000,$asc+100);
|
||||
$fd.=",'FontBBox'=>'[".$fbb[0].' '.$fbb[1].' '.$fbb[2].' '.$fbb[3]."]'";
|
||||
//ItalicAngle
|
||||
$ia=(isset($fm['ItalicAngle']) ? $fm['ItalicAngle'] : 0);
|
||||
@@ -171,7 +173,7 @@ function MakeFontDescriptor($fm,$symbolic)
|
||||
//StemV
|
||||
if(isset($fm['StdVW']))
|
||||
$stemv=$fm['StdVW'];
|
||||
elseif(isset($fm['Weight']) and eregi('(bold|black)',$fm['Weight']))
|
||||
elseif(isset($fm['Weight']) && preg_match('/bold|black/i',$fm['Weight']))
|
||||
$stemv=120;
|
||||
else
|
||||
$stemv=70;
|
||||
@@ -194,7 +196,7 @@ function MakeWidthArray($fm)
|
||||
$s.="'\\''";
|
||||
elseif(chr($i)=="\\")
|
||||
$s.="'\\\\'";
|
||||
elseif($i>=32 and $i<=126)
|
||||
elseif($i>=32 && $i<=126)
|
||||
$s.="'".chr($i)."'";
|
||||
else
|
||||
$s.="chr($i)";
|
||||
@@ -227,7 +229,7 @@ function MakeFontEncoding($map)
|
||||
return rtrim($s);
|
||||
}
|
||||
|
||||
function SaveToFile($file,$s,$mode='t')
|
||||
function SaveToFile($file, $s, $mode)
|
||||
{
|
||||
$f=fopen($file,'w'.$mode);
|
||||
if(!$f)
|
||||
@@ -253,7 +255,7 @@ function CheckTTF($file)
|
||||
//Check if font license allows embedding
|
||||
$f=fopen($file,'rb');
|
||||
if(!$f)
|
||||
die('<B>Error:</B> Can\'t open '.$file);
|
||||
die('<b>Error:</b> Can\'t open '.$file);
|
||||
//Extract number of tables
|
||||
fseek($f,4,SEEK_CUR);
|
||||
$nb=ReadShort($f);
|
||||
@@ -284,21 +286,22 @@ function CheckTTF($file)
|
||||
$pp=($fsType & 0x04)!=0;
|
||||
$e=($fsType & 0x08)!=0;
|
||||
fclose($f);
|
||||
if($rl and !$pp and !$e)
|
||||
echo '<B>Warning:</B> font license does not allow embedding';
|
||||
if($rl && !$pp && !$e)
|
||||
echo '<b>Warning:</b> font license does not allow embedding';
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* $fontfile : chemin du fichier TTF (ou cha<68>ne vide si pas d'incorporation) *
|
||||
* $afmfile : chemin du fichier AFM *
|
||||
* $enc : encodage (ou cha<68>ne vide si la police est symbolique) *
|
||||
* $patch : patch optionnel pour l'encodage *
|
||||
* $type : type de la police si $fontfile est vide *
|
||||
* fontfile: path to TTF file (or empty string if not to be embedded) *
|
||||
* afmfile: path to AFM file *
|
||||
* enc: font encoding (or empty string for symbolic fonts) *
|
||||
* patch: optional patch for encoding *
|
||||
* type: font type if fontfile is empty *
|
||||
*******************************************************************************/
|
||||
function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueType')
|
||||
function MakeFont($fontfile, $afmfile, $enc='cp1252', $patch=array(), $type='TrueType')
|
||||
{
|
||||
//Generate a font definition file
|
||||
set_magic_quotes_runtime(0);
|
||||
if(get_magic_quotes_runtime())
|
||||
@set_magic_quotes_runtime(0);
|
||||
ini_set('auto_detect_line_endings','1');
|
||||
if($enc)
|
||||
{
|
||||
@@ -309,7 +312,7 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
else
|
||||
$map=array();
|
||||
if(!file_exists($afmfile))
|
||||
die('<B>Error:</B> AFM file not found: '.$afmfile);
|
||||
die('<b>Error:</b> AFM file not found: '.$afmfile);
|
||||
$fm=ReadAFM($afmfile,$map);
|
||||
if($enc)
|
||||
$diff=MakeFontEncoding($map);
|
||||
@@ -325,12 +328,12 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
elseif($ext=='pfb')
|
||||
$type='Type1';
|
||||
else
|
||||
die('<B>Error:</B> unrecognized font file extension: '.$ext);
|
||||
die('<b>Error:</b> unrecognized font file extension: '.$ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($type!='TrueType' and $type!='Type1')
|
||||
die('<B>Error:</B> incorrect font type: '.$type);
|
||||
if($type!='TrueType' && $type!='Type1')
|
||||
die('<b>Error:</b> incorrect font type: '.$type);
|
||||
}
|
||||
//Start generation
|
||||
$s='<?php'."\n";
|
||||
@@ -352,18 +355,18 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
{
|
||||
//Embedded font
|
||||
if(!file_exists($fontfile))
|
||||
die('<B>Error:</B> font file not found: '.$fontfile);
|
||||
die('<b>Error:</b> font file not found: '.$fontfile);
|
||||
if($type=='TrueType')
|
||||
CheckTTF($fontfile);
|
||||
$f=fopen($fontfile,'rb');
|
||||
if(!$f)
|
||||
die('<B>Error:</B> Can\'t open '.$fontfile);
|
||||
die('<b>Error:</b> Can\'t open '.$fontfile);
|
||||
$file=fread($f,filesize($fontfile));
|
||||
fclose($f);
|
||||
if($type=='Type1')
|
||||
{
|
||||
//Find first two sections and discard third one
|
||||
$header=(ord($file{0})==128);
|
||||
$header=(ord($file[0])==128);
|
||||
if($header)
|
||||
{
|
||||
//Strip first binary header
|
||||
@@ -371,16 +374,16 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
}
|
||||
$pos=strpos($file,'eexec');
|
||||
if(!$pos)
|
||||
die('<B>Error:</B> font file does not seem to be valid Type1');
|
||||
die('<b>Error:</b> font file does not seem to be valid Type1');
|
||||
$size1=$pos+6;
|
||||
if($header and ord($file{$size1})==128)
|
||||
if($header && ord($file[$size1])==128)
|
||||
{
|
||||
//Strip second binary header
|
||||
$file=substr($file,0,$size1).substr($file,$size1+6);
|
||||
}
|
||||
$pos=strpos($file,'00000000');
|
||||
if(!$pos)
|
||||
die('<B>Error:</B> font file does not seem to be valid Type1');
|
||||
die('<b>Error:</b> font file does not seem to be valid Type1');
|
||||
$size2=$pos-$size1;
|
||||
$file=substr($file,0,$size1+$size2);
|
||||
}
|
||||
@@ -389,12 +392,12 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
$cmp=$basename.'.z';
|
||||
SaveToFile($cmp,gzcompress($file),'b');
|
||||
$s.='$file=\''.$cmp."';\n";
|
||||
echo 'Font file compressed ('.$cmp.')<BR>';
|
||||
echo 'Font file compressed ('.$cmp.')<br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$s.='$file=\''.basename($fontfile)."';\n";
|
||||
echo '<B>Notice:</B> font file could not be compressed (zlib extension not available)<BR>';
|
||||
echo '<b>Notice:</b> font file could not be compressed (zlib extension not available)<br>';
|
||||
}
|
||||
if($type=='Type1')
|
||||
{
|
||||
@@ -410,7 +413,7 @@ function MakeFont($fontfile,$afmfile,$enc='cp1252',$patch=array(),$type='TrueTyp
|
||||
$s.='$file='."'';\n";
|
||||
}
|
||||
$s.="?>\n";
|
||||
SaveToFile($basename.'.php',$s);
|
||||
echo 'Font definition file generated ('.$basename.'.php'.')<BR>';
|
||||
SaveToFile($basename.'.php',$s,'t');
|
||||
echo 'Font definition file generated ('.$basename.'.php'.')<br>';
|
||||
}
|
||||
?>
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['symbol']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Symbol';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
|
||||
chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>713,'#'=>500,'$'=>549,'%'=>833,'&'=>778,'\''=>439,'('=>333,')'=>333,'*'=>500,'+'=>549,
|
||||
','=>250,'-'=>549,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>549,'='=>549,'>'=>549,'?'=>444,'@'=>549,'A'=>722,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['times']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Times-Roman';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
|
||||
chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>408,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>180,'('=>333,')'=>333,'*'=>500,'+'=>564,
|
||||
','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>278,';'=>278,'<'=>564,'='=>564,'>'=>564,'?'=>444,'@'=>921,'A'=>722,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['timesB']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Times-Bold';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
|
||||
chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>555,'#'=>500,'$'=>500,'%'=>1000,'&'=>833,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570,
|
||||
','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>930,'A'=>722,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['timesBI']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Times-BoldItalic';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
|
||||
chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>389,'"'=>555,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>278,'('=>333,')'=>333,'*'=>500,'+'=>570,
|
||||
','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>570,'='=>570,'>'=>570,'?'=>500,'@'=>832,'A'=>667,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['timesI']=array(
|
||||
$type = 'Core';
|
||||
$name = 'Times-Italic';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>250,chr(1)=>250,chr(2)=>250,chr(3)=>250,chr(4)=>250,chr(5)=>250,chr(6)=>250,chr(7)=>250,chr(8)=>250,chr(9)=>250,chr(10)=>250,chr(11)=>250,chr(12)=>250,chr(13)=>250,chr(14)=>250,chr(15)=>250,chr(16)=>250,chr(17)=>250,chr(18)=>250,chr(19)=>250,chr(20)=>250,chr(21)=>250,
|
||||
chr(22)=>250,chr(23)=>250,chr(24)=>250,chr(25)=>250,chr(26)=>250,chr(27)=>250,chr(28)=>250,chr(29)=>250,chr(30)=>250,chr(31)=>250,' '=>250,'!'=>333,'"'=>420,'#'=>500,'$'=>500,'%'=>833,'&'=>778,'\''=>214,'('=>333,')'=>333,'*'=>500,'+'=>675,
|
||||
','=>250,'-'=>333,'.'=>250,'/'=>278,'0'=>500,'1'=>500,'2'=>500,'3'=>500,'4'=>500,'5'=>500,'6'=>500,'7'=>500,'8'=>500,'9'=>500,':'=>333,';'=>333,'<'=>675,'='=>675,'>'=>675,'?'=>500,'@'=>920,'A'=>611,
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
$fpdf_charwidths['zapfdingbats']=array(
|
||||
$type = 'Core';
|
||||
$name = 'ZapfDingbats';
|
||||
$up = -100;
|
||||
$ut = 50;
|
||||
$cw = array(
|
||||
chr(0)=>0,chr(1)=>0,chr(2)=>0,chr(3)=>0,chr(4)=>0,chr(5)=>0,chr(6)=>0,chr(7)=>0,chr(8)=>0,chr(9)=>0,chr(10)=>0,chr(11)=>0,chr(12)=>0,chr(13)=>0,chr(14)=>0,chr(15)=>0,chr(16)=>0,chr(17)=>0,chr(18)=>0,chr(19)=>0,chr(20)=>0,chr(21)=>0,
|
||||
chr(22)=>0,chr(23)=>0,chr(24)=>0,chr(25)=>0,chr(26)=>0,chr(27)=>0,chr(28)=>0,chr(29)=>0,chr(30)=>0,chr(31)=>0,' '=>278,'!'=>974,'"'=>961,'#'=>974,'$'=>980,'%'=>719,'&'=>789,'\''=>790,'('=>791,')'=>690,'*'=>960,'+'=>939,
|
||||
','=>549,'-'=>855,'.'=>911,'/'=>933,'0'=>911,'1'=>945,'2'=>974,'3'=>755,'4'=>846,'5'=>762,'6'=>761,'7'=>571,'8'=>677,'9'=>763,':'=>760,';'=>759,'<'=>754,'='=>494,'>'=>552,'?'=>537,'@'=>577,'A'=>692,
|
||||
|
21
fpdf.css
Executable file
21
fpdf.css
Executable file
@@ -0,0 +1,21 @@
|
||||
body {font-family:"Times New Roman",serif}
|
||||
h1 {font:bold 135% Arial,sans-serif; color:#4000A0; margin-bottom:0.9em}
|
||||
h2 {font:bold 95% Arial,sans-serif; color:#900000; margin-top:1.5em; margin-bottom:1em}
|
||||
dl.param dt {text-decoration:underline}
|
||||
dl.param dd {margin-top:1em; margin-bottom:1em}
|
||||
dl.param ul {margin-top:1em; margin-bottom:1em}
|
||||
tt, code, kbd {font-family:"Courier New",Courier,monospace; font-size:82%}
|
||||
div.source {margin-top:1.4em; margin-bottom:1.3em}
|
||||
div.source pre {display:table; border:1px solid #24246A; width:100%; margin:0em; font-family:inherit; font-size:100%}
|
||||
div.source code {display:block; border:1px solid #C5C5EC; background-color:#F0F5FF; padding:6px; color:#000000}
|
||||
div.doc-source {margin-top:1.4em; margin-bottom:1.3em}
|
||||
div.doc-source pre {display:table; width:100%; margin:0em; font-family:inherit; font-size:100%}
|
||||
div.doc-source code {display:block; background-color:#E0E0E0; padding:4px}
|
||||
.kw {color:#000080; font-weight:bold}
|
||||
.str {color:#CC0000}
|
||||
.cmt {color:#008000}
|
||||
p.demo {text-align:center; margin-top:-0.9em}
|
||||
a.demo {text-decoration:none; font-weight:bold; color:#0000CC}
|
||||
a.demo:link {text-decoration:none; font-weight:bold; color:#0000CC}
|
||||
a.demo:hover {text-decoration:none; font-weight:bold; color:#0000FF}
|
||||
a.demo:active {text-decoration:none; font-weight:bold; color:#0000FF}
|
795
fpdf_merge.php
Normal file
795
fpdf_merge.php
Normal file
@@ -0,0 +1,795 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* FPDF_Merge
|
||||
* Tool to merge PDFs created by fpdf 1.6
|
||||
*
|
||||
* @version 1.0
|
||||
* @date 2011-02-18
|
||||
* @author DEMONTE Jean-Baptiste <jbdemonte@gmail.com>
|
||||
* @copyright (C) Digitick <www.digitick.net> 2011
|
||||
* @license GNU Lesser General Public License v3.0
|
||||
*
|
||||
* Why this tool ?
|
||||
*
|
||||
* All the library tested (fpdi, ...) produce too heavy pdf
|
||||
* because, these are not optimized.
|
||||
* This library parses the pages, get the objects included (font, images)
|
||||
* generate a hash to store only once these objects or reuse previous stored ones.
|
||||
*
|
||||
*
|
||||
* Notes
|
||||
*
|
||||
* - links are not supported in this version
|
||||
* - all pages are included (because this was what we needed) but update it
|
||||
* to create an add(array pages) should be easy
|
||||
*
|
||||
*
|
||||
* I tried to optimize a lot this tool using X-Debug, let me know if you do best :)
|
||||
* If you get trouble or want to comment, feel free to send me an email.
|
||||
*
|
||||
* Use
|
||||
*
|
||||
* $merge = new FPDF_Merge();
|
||||
* $merge->add('/tmp/pdf-1.pdf');
|
||||
* $merge->add('/tmp/pdf-2.pdf');
|
||||
* $merge->output('/tmp/pdf-merge.pdf'); // or $merge->output(); to open it directly in the browser
|
||||
*
|
||||
* */
|
||||
class FPDF_Merge {
|
||||
|
||||
const TYPE_NULL = 0,
|
||||
TYPE_TOKEN = 1,
|
||||
TYPE_REFERENCE = 2,
|
||||
TYPE_REFERENCE_F = 3,
|
||||
TYPE_NUMERIC = 4,
|
||||
TYPE_HEX = 5,
|
||||
TYPE_BOOL = 6,
|
||||
TYPE_STRING = 7,
|
||||
TYPE_ARRAY = 8,
|
||||
TYPE_DICTIONARY = 9,
|
||||
TYPE_STREAM = 10;
|
||||
|
||||
private $buffer, $compress, $fonts, $objects, $pages, $ref, $n, $xref;
|
||||
|
||||
/* * ************************************************
|
||||
/* CONSTRUCTOR
|
||||
/************************************************* */
|
||||
|
||||
public function __construct() {
|
||||
$this->buffer = '';
|
||||
$this->fonts = array();
|
||||
$this->objects = array();
|
||||
$this->pages = array();
|
||||
$this->ref = array();
|
||||
$this->xref = array();
|
||||
$this->n = 0;
|
||||
$this->compress = function_exists('gzcompress');
|
||||
}
|
||||
|
||||
/* * ************************************************
|
||||
/* PRIVATE
|
||||
/************************************************* */
|
||||
|
||||
private function error($msg) {
|
||||
throw new Exception($msg);
|
||||
die;
|
||||
}
|
||||
|
||||
//================================================
|
||||
// FONCTIONS D'IMPORT
|
||||
//================================================
|
||||
|
||||
private function parse($buffer, &$len, &$off) {
|
||||
if ($len === $off) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!preg_match('`\s*(.)`', $buffer, $m, PREG_OFFSET_CAPTURE, $off))
|
||||
return null;
|
||||
$off = $m[1][1];
|
||||
|
||||
switch ($buffer[$off]) {
|
||||
case '<':
|
||||
if ($buffer[$off + 1] === '<') {
|
||||
// dictionnary
|
||||
$v = array();
|
||||
$off+=2;
|
||||
while (1) {
|
||||
$key = $this->parse($buffer, $len, $off);
|
||||
if ($key === null)
|
||||
break;
|
||||
if ($key[0] !== self::TYPE_TOKEN)
|
||||
break;
|
||||
$value = $this->parse($buffer, $len, $off);
|
||||
$v[$key[1]] = $value;
|
||||
}
|
||||
$off+=2;
|
||||
return array(self::TYPE_DICTIONARY, $v);
|
||||
} else {
|
||||
// hex
|
||||
$p = strpos($buffer, '>', $off);
|
||||
if ($p !== false) {
|
||||
$v = substr($buffer, $off + 1, $p - $off - 1);
|
||||
$off = $p + 1;
|
||||
return array(self::TYPE_HEX, $v);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '(':
|
||||
// string
|
||||
$p = $off;
|
||||
while (1) {
|
||||
$p++;
|
||||
if ($p === $len)
|
||||
break;
|
||||
if (($buffer[$p] === ')') && ($buffer[$p - 1] !== '\\'))
|
||||
break;
|
||||
}
|
||||
if ($p < $len) {
|
||||
$v = substr($buffer, $off + 1, $p - $off - 1);
|
||||
$off = $p + 1;
|
||||
return array(self::TYPE_STRING, $v);
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
$v = array();
|
||||
$off++; // jump the [
|
||||
while (1) {
|
||||
$value = $this->parse($buffer, $len, $off);
|
||||
if ($value === null)
|
||||
break;
|
||||
$v[] = $value;
|
||||
}
|
||||
$off++; // jump the ]
|
||||
return array(self::TYPE_ARRAY, $v);
|
||||
break;
|
||||
case '>': // dictionnary : end
|
||||
case ']': // array : end
|
||||
return null;
|
||||
break;
|
||||
case '%': // comments : jump
|
||||
$p = strpos($buffer, "\n", $off);
|
||||
if ($p !== false) {
|
||||
$off = $p + 1;
|
||||
return $this->parse($buffer, $len, $off);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if (preg_match('`^\s*([0-9]+) 0 R`', substr($buffer, $off, 32), $m)) {
|
||||
$off += strlen($m[0]);
|
||||
return array(self::TYPE_REFERENCE, $m[1]);
|
||||
} else {
|
||||
$p = strcspn($buffer, " %[]<>()\r\n\t/", $off + 1);
|
||||
$v = substr($buffer, $off, $p + 1);
|
||||
$off += $p + 1;
|
||||
if (is_numeric($v)) {
|
||||
$type = self::TYPE_NUMERIC;
|
||||
} else if (($v === 'true') || ($v === 'false')) {
|
||||
$type = self::TYPE_BOOL;
|
||||
} else if ($v === 'null') {
|
||||
$type = self::TYPE_NULL;
|
||||
} else {
|
||||
$type = self::TYPE_TOKEN;
|
||||
}
|
||||
return array($type, $v);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getObject($f, $xref, $index, $includeSubObject = false) {
|
||||
|
||||
$type = self::TYPE_TOKEN;
|
||||
|
||||
if (!isset($xref[$index])) {
|
||||
$this->error('reference d\'object inconnue');
|
||||
}
|
||||
|
||||
fseek($f, $xref[$index]);
|
||||
|
||||
$data = '';
|
||||
$len = 0;
|
||||
$offset = 0;
|
||||
$expLen = 1024;
|
||||
do {
|
||||
$prev = $len;
|
||||
$data .= fread($f, $expLen);
|
||||
$len = strlen($data);
|
||||
$p = strpos($data, "endobj", $offset);
|
||||
if ($p !== false) {
|
||||
if ($data[$p - 1] !== "\n") {
|
||||
$offset = $p + 6;
|
||||
$p = false;
|
||||
} else {
|
||||
if ($len < $p + 8) {
|
||||
$data .= fread($f, 1);
|
||||
$len = strlen($data);
|
||||
}
|
||||
if ($data[$p + 6] !== "\n") {
|
||||
$offset = $p + 6; // not the endobj markup, maybe a string content
|
||||
$p = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$expLen *= 2;
|
||||
} while (($p === false) && ($prev !== $len));
|
||||
|
||||
if ($p === false) {
|
||||
$this->error('object [' . $index . '] non trouve');
|
||||
}
|
||||
|
||||
$p--;
|
||||
$data = substr($data, 0, $p);
|
||||
|
||||
if (!preg_match('`^([0-9]+ 0 obj)`', $data, $m, PREG_OFFSET_CAPTURE)) {
|
||||
$this->error('object [' . $index . '] invalide');
|
||||
}
|
||||
|
||||
$p = $m[0][1] + strlen($m[1][0]) + 1;
|
||||
$data = substr($data, $p);
|
||||
|
||||
if (substr($data, 0, 2) === '<<') {
|
||||
$type = self::TYPE_DICTIONARY;
|
||||
$off = 0;
|
||||
$len = strlen($data);
|
||||
$dictionary = $this->parse($data, $len, $off);
|
||||
$off++;
|
||||
$data = substr($data, $off);
|
||||
if ($data === false) {
|
||||
$data = '';
|
||||
} else if (substr($data, 0, 7) === "stream\n") {
|
||||
$data = substr($data, 7, strlen($data) - 17);
|
||||
$type = self::TYPE_STREAM;
|
||||
}
|
||||
if ($includeSubObject) {
|
||||
$dictionary = $this->_resolveValues($f, $xref, $dictionary);
|
||||
}
|
||||
} else {
|
||||
$dictionary = null;
|
||||
}
|
||||
return array($type, $dictionary, $data);
|
||||
}
|
||||
|
||||
private function _resolveValues($f, $xref, $item) {
|
||||
switch ($item[0]) {
|
||||
case self::TYPE_REFERENCE:
|
||||
$object = $this->getObject($f, $xref, $item[1], true);
|
||||
if ($object[0] === self::TYPE_TOKEN) {
|
||||
return array(self::TYPE_TOKEN, $object[2]);
|
||||
}
|
||||
$ref = $this->storeObject($object);
|
||||
return array(self::TYPE_REFERENCE_F, $this->_getObjectType($object), $ref);
|
||||
break;
|
||||
case self::TYPE_ARRAY:
|
||||
case self::TYPE_DICTIONARY:
|
||||
$r = array();
|
||||
foreach ($item[1] as $key => $val) {
|
||||
if (($val[0] == self::TYPE_REFERENCE) ||
|
||||
($val[0] == self::TYPE_ARRAY) ||
|
||||
($val[0] == self::TYPE_DICTIONARY)) {
|
||||
$r[$key] = $this->_resolveValues($f, $xref, $val);
|
||||
} else {
|
||||
$r[$key] = $val;
|
||||
}
|
||||
}
|
||||
return array($item[0], $r);
|
||||
break;
|
||||
default:
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
private function getResources($f, $xref, $page) {
|
||||
if ($page[0] !== self::TYPE_DICTIONARY) {
|
||||
$this->error('getResources necessite un dictionaire');
|
||||
}
|
||||
if (isset($page[1]['/Resources'])) {
|
||||
if ($page[1]['/Resources'][0] === self::TYPE_REFERENCE) {
|
||||
return $this->getObject($f, $xref, $page[1]['/Resources'][1]);
|
||||
} else {
|
||||
return array($page[1]['/Resources'][1]);
|
||||
}
|
||||
} else if (isset($page[1]['/Parent'])) {
|
||||
return $this->getResources($f, $xref, $page[1]['/Parent']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getContent($f, $xref, $page) {
|
||||
if ($page[0] !== self::TYPE_DICTIONARY) {
|
||||
$this->error('getContent necessite un dictionaire');
|
||||
}
|
||||
$stream = '';
|
||||
if (isset($page[1]['/Contents'])) {
|
||||
$stream = $this->_getContent($f, $xref, $page[1]['/Contents']);
|
||||
}
|
||||
return $stream;
|
||||
}
|
||||
|
||||
private function _getContent($f, $xref, $content) {
|
||||
$stream = '';
|
||||
if ($content[0] === self::TYPE_REFERENCE) {
|
||||
$stream .= $this->getStream($f, $xref, $this->getObject($f, $xref, $content[1]));
|
||||
} else if ($content[0] === self::TYPE_ARRAY) {
|
||||
foreach ($content[1] as $sub) {
|
||||
$stream .= $this->_getContent($f, $xref, $sub);
|
||||
}
|
||||
} else {
|
||||
$stream .= $this->getStream($f, $xref, $item);
|
||||
}
|
||||
return $stream;
|
||||
}
|
||||
|
||||
private function getCompression($f, $xref, $item) {
|
||||
if ($item[0] === self::TYPE_TOKEN) {
|
||||
return array($item[1]);
|
||||
} else if ($item[0] === self::TYPE_ARRAY) {
|
||||
$r = array();
|
||||
foreach ($item[1] as $sub) {
|
||||
$r = array_merge($r, $this->getCompression($f, $xref, $sub));
|
||||
}
|
||||
return $r;
|
||||
} else if ($item[0] === self::TYPE_REFERENCE) {
|
||||
return $this->getCompression($f, $xref, $this->getObject($f, $xref, $item[1]));
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
private function getStream($f, $xref, $item) {
|
||||
$methods = isset($item[1][1]['/Filter']) ? $this->getCompression($f, $xref, $item[1][1]['/Filter']) : array();
|
||||
|
||||
$raw = $item[2];
|
||||
foreach ($methods as $method) {
|
||||
switch ($method) {
|
||||
case '/FlateDecode':
|
||||
if (function_exists('gzuncompress')) {
|
||||
$raw = !empty($raw) ? @gzuncompress($raw) : '';
|
||||
} else {
|
||||
$this->error('gzuncompress necessaire pour decompresser ce stream');
|
||||
}
|
||||
if ($raw === false) {
|
||||
$this->error('erreur de decompression du stream');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->error($method . ' necessaire pour decompresser ce stream');
|
||||
}
|
||||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
private function storeObject($item, $type = false) {
|
||||
$md5 = md5(serialize($item));
|
||||
if ($type === '/Font') {
|
||||
$array = & $this->fonts;
|
||||
$prefix = '/F';
|
||||
} else {
|
||||
$array = & $this->objects;
|
||||
$prefix = '/Obj';
|
||||
}
|
||||
if (!isset($array[$md5])) {
|
||||
$index = count($array) + 1;
|
||||
$array[$md5] = array(
|
||||
'name' => $prefix . $index,
|
||||
'item' => $item,
|
||||
'type' => $type,
|
||||
'index' => $index
|
||||
);
|
||||
} else if ($type) {
|
||||
$array[$md5]['type'] = $type;
|
||||
}
|
||||
return $array[$md5][$type ? 'name' : 'index'];
|
||||
}
|
||||
|
||||
//================================================
|
||||
// FONCTIONS D'IMPRESSION
|
||||
//================================================
|
||||
|
||||
private function _out($raw) {
|
||||
$this->buffer .= $raw . "\n";
|
||||
}
|
||||
|
||||
private function _strval($value) {
|
||||
$value+=0;
|
||||
if ($value) {
|
||||
return strval($value);
|
||||
}
|
||||
return '0';
|
||||
}
|
||||
|
||||
private function _toStream($item) {
|
||||
switch ($item[0]) {
|
||||
case self::TYPE_NULL : return 'null';
|
||||
case self::TYPE_TOKEN : return $item[1];
|
||||
case self::TYPE_REFERENCE : return $this->_strval($item[1]) . ' 0 R';
|
||||
case self::TYPE_REFERENCE_F :
|
||||
if (!isset($this->ref[$item[1]][$item[2]])) {
|
||||
$this->error('reference vers un object non sauve');
|
||||
}
|
||||
return $this->_strval($this->ref[$item[1]][$item[2]]) . ' 0 R';
|
||||
|
||||
case self::TYPE_NUMERIC : return $this->_strval($item[1]);
|
||||
case self::TYPE_HEX : return '<' . strval($item[1]) . '>';
|
||||
case self::TYPE_BOOL : return $item[1] ? 'true' : 'false';
|
||||
case self::TYPE_STRING : return '(' . str_replace(array('\\', '(', ')'), array('\\\\', '\\(', '\\)'), strval($item[1])) . ')';
|
||||
case self::TYPE_ARRAY :
|
||||
$r = array();
|
||||
foreach ($item[1] as $val) {
|
||||
$r[] = $this->_toStream($val);
|
||||
}
|
||||
return '[' . implode(' ', $r) . ']';
|
||||
case self::TYPE_DICTIONARY :
|
||||
$r = array();
|
||||
foreach ($item[1] as $key => $val) {
|
||||
$val = $this->_toStream($val);
|
||||
$r[] = $key . ' ' . $val;
|
||||
}
|
||||
return '<<' . implode("\n", $r) . '>>';
|
||||
break;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
private function _newobj($n = null) {
|
||||
if (($n === null) || ($n === true)) {
|
||||
$this->n++;
|
||||
$id = $this->n;
|
||||
} else {
|
||||
$id = $n;
|
||||
}
|
||||
if ($n !== true) {
|
||||
$this->xref[$id] = strlen($this->buffer);
|
||||
$this->_out($id . ' 0 obj');
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function _addObj($dico = null, $buf = null) {
|
||||
$ref = $this->_newobj();
|
||||
$buf = empty($buf) && ($buf !== 0) && ($buf !== '0') ? null : $buf;
|
||||
if (is_array($dico)) {
|
||||
if ($buf !== null) {
|
||||
if ($this->compress && !isset($dico['/Filter'])) {
|
||||
$buf = gzcompress($buf);
|
||||
$dico['/Filter'] = array(self::TYPE_TOKEN, '/FlateDecode');
|
||||
}
|
||||
$dico['/Length'] = array(self::TYPE_NUMERIC, strlen($buf));
|
||||
}
|
||||
$this->_out($this->_toStream(array(self::TYPE_DICTIONARY, $dico)));
|
||||
}
|
||||
if ($buf !== null) {
|
||||
$this->_out('stream');
|
||||
$this->_out($buf);
|
||||
$this->_out('endstream');
|
||||
}
|
||||
$this->_out('endobj');
|
||||
return $ref;
|
||||
}
|
||||
|
||||
private function _getObjectType($object) {
|
||||
return isset($object['type']) && !empty($object['type']) ? $object['type'] : 'default';
|
||||
}
|
||||
|
||||
private function _putObject($object) {
|
||||
$type = $this->_getObjectType($object);
|
||||
if (!isset($this->ref[$type])) {
|
||||
$this->ref[$type] = array();
|
||||
}
|
||||
$this->ref[$type][$object['index']] = $this->_addObj($object['item'][1][1], $object['item'][2]);
|
||||
}
|
||||
|
||||
private function _putObjects() {
|
||||
foreach ($this->objects as $object) {
|
||||
if ($object['type'])
|
||||
continue;
|
||||
$this->_putObject($object);
|
||||
}
|
||||
foreach ($this->objects as $object) {
|
||||
if (!$object['type'])
|
||||
continue;
|
||||
$this->_putObject($object);
|
||||
}
|
||||
foreach ($this->fonts as $object) {
|
||||
$this->_putObject($object);
|
||||
}
|
||||
}
|
||||
|
||||
private function _putResources() {
|
||||
$dico = array(
|
||||
'/ProcSet' => array(
|
||||
self::TYPE_ARRAY,
|
||||
array(
|
||||
array(self::TYPE_TOKEN, '/PDF'),
|
||||
array(self::TYPE_TOKEN, '/Text'),
|
||||
array(self::TYPE_TOKEN, '/ImageB'),
|
||||
array(self::TYPE_TOKEN, '/ImageC'),
|
||||
array(self::TYPE_TOKEN, '/ImageI')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$xObjects = array();
|
||||
foreach ($this->objects as $index => $object) {
|
||||
if ($object['type'] === false) {
|
||||
continue;
|
||||
}
|
||||
$value = array(
|
||||
self::TYPE_TOKEN,
|
||||
$this->_toStream(array(self::TYPE_REFERENCE, $this->ref[$object['type']][$object['index']]))
|
||||
);
|
||||
if ($object['type'] === '/XObject') {
|
||||
$xObjects[$object['name']] = $value;
|
||||
}
|
||||
}
|
||||
if (!empty($xObjects)) {
|
||||
$dico['/XObject'] = array(self::TYPE_DICTIONARY, $xObjects);
|
||||
}
|
||||
|
||||
$fonts = array();
|
||||
foreach ($this->fonts as $index => $object) {
|
||||
$value = array(
|
||||
self::TYPE_TOKEN,
|
||||
$this->_toStream(array(self::TYPE_REFERENCE, $this->ref['/Font'][$object['index']]))
|
||||
);
|
||||
$fonts[$object['name']] = $value;
|
||||
}
|
||||
if (!empty($fonts)) {
|
||||
$dico['/Font'] = array(self::TYPE_DICTIONARY, $fonts);
|
||||
}
|
||||
return $this->_addObj($dico);
|
||||
}
|
||||
|
||||
/* * ************************************************
|
||||
/* PUBLIC
|
||||
/************************************************* */
|
||||
|
||||
public function add($filename) {
|
||||
$f = @fopen($filename, 'rb');
|
||||
if (!$f) {
|
||||
$this->error('impossible d\'ouvrir le fichier');
|
||||
}
|
||||
fseek($f, 0, SEEK_END);
|
||||
$fileLength = ftell($f);
|
||||
|
||||
// Localisation de xref
|
||||
//-------------------------------------------------
|
||||
|
||||
fseek($f, -128, SEEK_END);
|
||||
$data = fread($f, 128);
|
||||
if ($data === false) {
|
||||
return $this->error('erreur de lecture dans le fichier');
|
||||
}
|
||||
$p = strripos($data, 'startxref');
|
||||
if ($p === false) {
|
||||
return $this->error('startxref absent');
|
||||
}
|
||||
$startxref = substr($data, $p + 10, strlen($data) - $p - 17);
|
||||
$posStartxref = $fileLength - 128 + $p;
|
||||
|
||||
// extraction de xref + trailer
|
||||
//-------------------------------------------------
|
||||
|
||||
fseek($f, $startxref);
|
||||
$data = fread($f, $posStartxref - $startxref);
|
||||
|
||||
// extraction du trailer
|
||||
//-------------------------------------------------
|
||||
$p = stripos($data, 'trailer');
|
||||
if ($p === false) {
|
||||
return $this->error('trailer absent');
|
||||
}
|
||||
$dataTrailer = substr($data, $p + 8);
|
||||
$len = strlen($dataTrailer);
|
||||
$off = 0;
|
||||
$trailer = $this->parse($dataTrailer, $len, $off);
|
||||
|
||||
// extraction du xref
|
||||
//-------------------------------------------------
|
||||
|
||||
$data = explode("\n", trim(substr($data, 0, $p)));
|
||||
array_shift($data); // "xref"
|
||||
|
||||
$cnt = 0;
|
||||
$xref = array();
|
||||
|
||||
foreach ($data as $line) {
|
||||
if (!$cnt) {
|
||||
if (preg_match('`^([0-9]+) ([0-9]+)$`', $line, $m)) {
|
||||
$index = intval($m[1]) - 1;
|
||||
$cnt = intval($m[2]);
|
||||
} else {
|
||||
$this->error('erreur dans xref');
|
||||
}
|
||||
} else {
|
||||
$index++;
|
||||
$cnt--;
|
||||
if (preg_match('`^([0-9]{10}) [0-9]{5} ([n|f])`', $line, $m)) {
|
||||
if ($m[2] === 'f') {
|
||||
continue;
|
||||
}
|
||||
$xref[$index] = $m[1];
|
||||
} else {
|
||||
$this->error('erreur dans xref : ' . $line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lecture des pages
|
||||
//-------------------------------------------------
|
||||
|
||||
$root = $this->getObject($f, $xref, $trailer[1]['/Root'][1]);
|
||||
$root = $root[1][1];
|
||||
|
||||
$pages = $this->getObject($f, $xref, $root['/Pages'][1]);
|
||||
$pages = $pages[1][1];
|
||||
|
||||
foreach ($pages['/Kids'][1] as $kid) {
|
||||
$kid = $this->getObject($f, $xref, $kid[1]);
|
||||
$kid = $kid[1];
|
||||
|
||||
$resources = $this->getResources($f, $xref, $kid);
|
||||
$resources = $resources[1][1];
|
||||
|
||||
$content = $this->getContent($f, $xref, $kid);
|
||||
|
||||
// traitement des fonts
|
||||
//-------------------------------------------------
|
||||
$newFonts = array();
|
||||
if (isset($resources['/Font']) && !empty($resources['/Font'])) {
|
||||
if (preg_match_all("`(/F[0-9]+)\s+-?[0-9\.]+\s+Tf`", $content, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
$newContent = '';
|
||||
$offset = 0;
|
||||
$cnt = count($matches[0]);
|
||||
for ($i = 0; $i < $cnt; $i++) {
|
||||
$position = $matches[0][$i][1];
|
||||
$name = $matches[1][$i][0];
|
||||
if (!isset($newFonts[$name])) {
|
||||
$object = $this->getObject($f, $xref, $resources['/Font'][1][$name][1], true);
|
||||
$newFonts[$name] = $this->storeObject($object, '/Font');
|
||||
}
|
||||
if ($newFonts[$name] !== $name) {
|
||||
$newContent .= substr($content, $offset, $position - $offset);
|
||||
$newContent .= $newFonts[$name];
|
||||
$offset = $position + strlen($name);
|
||||
}
|
||||
}
|
||||
$content = $newContent . substr($content, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
// traitement des XObjets
|
||||
//-------------------------------------------------
|
||||
$newXObjects = array();
|
||||
if (isset($resources['/XObject']) && !empty($resources['/XObject'])) {
|
||||
if (preg_match_all("`(/[^%\[\]<>\(\)\r\n\t/]+) Do`", $content, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
$newContent = '';
|
||||
$offset = 0;
|
||||
foreach ($matches[1] as $m) {
|
||||
$name = $m[0];
|
||||
$position = $m[1];
|
||||
if (!isset($newXObjects[$name])) {
|
||||
$object = $this->getObject($f, $xref, $resources['/XObject'][1][$name][1], true);
|
||||
$newXObjects[$name] = $this->storeObject($object, '/XObject');
|
||||
}
|
||||
if ($newXObjects[$name] !== $name) {
|
||||
$newContent .= substr($content, $offset, $position - $offset);
|
||||
$newContent .= $newXObjects[$name];
|
||||
$offset = $position + strlen($name);
|
||||
}
|
||||
}
|
||||
$content = $newContent . substr($content, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
$mediaBox = isset($kid[1]['/MediaBox']) ? $kid[1]['/MediaBox'] : (isset($pages['/MediaBox']) ? $pages['/MediaBox'] : null);
|
||||
|
||||
if ($mediaBox[0] !== self::TYPE_ARRAY) {
|
||||
$this->error('MediaBox non definie');
|
||||
}
|
||||
|
||||
|
||||
$this->pages[] = array(
|
||||
'content' => $content,
|
||||
'/XObject' => array_values($newXObjects),
|
||||
'/Font' => array_values($newFonts),
|
||||
'/MediaBox' => $mediaBox
|
||||
);
|
||||
}
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
public function output($filename = null) {
|
||||
$this->_out('%PDF-1.6');
|
||||
|
||||
$this->_putObjects();
|
||||
|
||||
$rsRef = $this->_putResources();
|
||||
|
||||
$ptRef = $this->_newobj(true);
|
||||
|
||||
$kids = array();
|
||||
|
||||
// Ajout des pages
|
||||
$n = count($this->pages);
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$ctRef = $this->_addObj(array(), $this->pages[$i]['content']);
|
||||
$dico = array(
|
||||
'/Type' => array(self::TYPE_TOKEN, '/Page'),
|
||||
'/Parent' => array(self::TYPE_REFERENCE, $ptRef),
|
||||
'/MediaBox' => $this->pages[$i]['/MediaBox'],
|
||||
'/Resources' => array(self::TYPE_REFERENCE, $rsRef),
|
||||
'/Contents' => array(self::TYPE_REFERENCE, $ctRef),
|
||||
);
|
||||
$kids[] = array(self::TYPE_REFERENCE, $this->_addObj($dico));
|
||||
}
|
||||
|
||||
// Ajout du page tree
|
||||
$ptDico = array(
|
||||
self::TYPE_DICTIONARY,
|
||||
array(
|
||||
'/Type' => array(self::TYPE_TOKEN, '/Pages'),
|
||||
'/Kids' => array(self::TYPE_ARRAY, $kids),
|
||||
'/Count' => array(self::TYPE_NUMERIC, count($kids))
|
||||
)
|
||||
);
|
||||
|
||||
$this->_newobj($ptRef);
|
||||
$this->_out($this->_toStream($ptDico));
|
||||
$this->_out('endobj');
|
||||
|
||||
// Ajout du catalogue
|
||||
$ctDico = array(
|
||||
self::TYPE_DICTIONARY,
|
||||
array(
|
||||
'/Type' => array(self::TYPE_TOKEN, '/Calalog'),
|
||||
'/Pages' => array(self::TYPE_REFERENCE, $ptRef)
|
||||
)
|
||||
);
|
||||
$ctRef = $this->_newobj();
|
||||
$this->_out($this->_toStream($ctDico));
|
||||
$this->_out('endobj');
|
||||
|
||||
// Ajout du xref
|
||||
$xrefOffset = strlen($this->buffer);
|
||||
$count = count($this->xref);
|
||||
$this->_out('xref');
|
||||
$this->_out('0 ' . ($count + 1));
|
||||
$this->_out('0000000000 65535 f ');
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->_out(sprintf('%010d 00000 n ', $this->xref[$i + 1]));
|
||||
}
|
||||
|
||||
// Ajout du trailer
|
||||
$dico = array(
|
||||
'/Size' => array(self::TYPE_NUMERIC, 1 + count($this->xref)),
|
||||
'/Root' => array(self::TYPE_REFERENCE, $ctRef)
|
||||
);
|
||||
$this->_out('trailer');
|
||||
$this->_out($this->_toStream(array(self::TYPE_DICTIONARY, $dico)));
|
||||
|
||||
|
||||
// Ajout du startxref
|
||||
$this->_out('startxref');
|
||||
$this->_out($xrefOffset);
|
||||
$this->_out('%%EOF');
|
||||
|
||||
if ($filename === null) {
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Length: ' . strlen($this->buffer));
|
||||
header('Cache-Control: private, max-age=0, must-revalidate');
|
||||
header('Pragma: public');
|
||||
ini_set('zlib.output_compression', '0');
|
||||
|
||||
echo $this->buffer;
|
||||
die;
|
||||
} else {
|
||||
file_put_contents($filename, $this->buffer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
13
pdf.php
13
pdf.php
@@ -1,13 +0,0 @@
|
||||
<?
|
||||
require('Fpdf.php');
|
||||
|
||||
$pdf=new Fpdf();
|
||||
$pdf->Open();
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial','B',16);
|
||||
$pdf->Cell(40,10,utf8_decode('¡Hola, Mundo!'),1,1);
|
||||
$pdf->Cell(60,10,utf8_decode('Conserjería'),1,1);
|
||||
$pdf->Cell(80,10,'Conserjería',1,1);
|
||||
$pdf->Close();
|
||||
$pdf->Output();
|
||||
?>
|
0
timerbar.js
Normal file → Executable file
0
timerbar.js
Normal file → Executable file
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<Informe>
|
||||
<Titulo Texto="Agitador magnético" />
|
||||
<Datos>
|
||||
<Consulta>
|
||||
select A.id as id,U.Descripcion as ubicacion,E.fechaCompra as fechaCompra,
|
||||
E.numSerie as numserie,E.Cantidad as cantidad
|
||||
from Elementos E, Articulos A, Ubicaciones U where A.id=E.id_Articulo and U.id=E.id_Ubicacion
|
||||
and A.id='700' order by U.Descripcion,numserie;
|
||||
</Consulta>
|
||||
</Datos>
|
||||
<Pagina Orientacion="P" Formato="A4">
|
||||
<Cabecera>M. E. C. - Dotación Inicial</Cabecera>
|
||||
<Cuerpo>
|
||||
<Col Nombre="ubicacion" Ancho="80" Ajuste="L" Titulo="Ubicación"/>
|
||||
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
|
||||
<Col Nombre="fechaCompra" Ancho="40" Ajuste="L" Titulo="Fecha C." />
|
||||
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
|
||||
</Cuerpo>
|
||||
</Pagina>
|
||||
</Informe>
|
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<Informe>
|
||||
<Titulo Texto="Aula de Plástica" />
|
||||
<Datos>
|
||||
<Consulta>
|
||||
select A.id as id,A.Marca as marca,A.Modelo as modelo,E.fechaCompra as fechaCompra,
|
||||
E.numSerie as numserie,A.Descripcion as descripcion,E.Cantidad as cantidad
|
||||
from Elementos E, Articulos A, Ubicaciones U where A.id=E.id_Articulo and U.id=E.id_Ubicacion
|
||||
and U.id='144' order by A.descripcion;
|
||||
</Consulta>
|
||||
</Datos>
|
||||
<Pagina Orientacion="L" Formato="A4">
|
||||
<Cabecera>Inventario de Ubicación</Cabecera>
|
||||
<Cuerpo>
|
||||
<Col Nombre="descripcion" Ancho="70" Ajuste="L" Titulo="Artículo"/>
|
||||
<Col Nombre="marca" Ancho="50" Ajuste="L" Titulo="Marca"/>
|
||||
<Col Nombre="modelo" Ancho="50" Ajuste="L" Titulo="Modelo"/>
|
||||
<Col Nombre="numserie" Ancho="40" Ajuste="L" Titulo="N Serie"/>
|
||||
<Col Nombre="fechaCompra" Ancho="35" Ajuste="L" Titulo="Fecha C." />
|
||||
<Col Nombre="cantidad" Ancho="20" Ajuste="D" Titulo="Cantidad" Total="S"/>
|
||||
</Cuerpo>
|
||||
</Pagina>
|
||||
</Informe>
|
Reference in New Issue
Block a user