por esta razon quise compartir esto con el foro , ademas por la razon de que este foro me ha sacado de apuros muchas veces
![Afirmando](http://static.forosdelweb.com/fdwtheme/images/smilies/afirmar.gif)
si tienes sugerencias y consejos para mejorar el reporte estare muy agradecido
ha utiliza la clase fpdf.php , ademas el archivo ex.php recive datos de de otra clase por medio de session
ojala les sirva para sus proyectos
![Adios](http://static.forosdelweb.com/fdwtheme/images/smilies/adios.gif)
ex.php
Código PHP:
<?php session_start();
if(isset($_POST['EXCEL']) && "EXCEL"==$_POST['EXCEL'])
{
define('FPDF_FONTPATH','font/');
require('mysql_table.php');
class PDF extends PDF_MySQL_Table
{
function Header()
{
$fecha = time();
//Title
$this->SetFont('Arial','B',8);
$this->Cell(0,6,'Reporte Archivos en Proceso ',0,1,'C');
$this->Cell(0,6,'*Departamento de Desarrollo',0,1,'L');
$this->Cell(0,6,'*Dasorrallado por :Felipe Ballesteros Olmos',0,1,'L');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
//Connect to database
mysql_connect('base o servidor','user','pass');
mysql_select_db('SCEnterprise');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//First table: put all columns automatically
$publicacion= $_SESSION["publica"];
$edicion= $_SESSION["edita"];
$seccion1= $_SESSION["secciona"];
$sql="SELECT id AS ID ,creator AS Autor, pagerange AS N_paguina, name AS Nombre_articulo, DATE_FORMAT(created,'%H:%i:%s')AS Inicio, section AS Seccion, modifier AS Editor, DATE_FORMAT(modified,'%H:%i:%s')AS Termino,state AS Estado FROM smart_objects
where
publication =".$publicacion."
AND issue=".$edicion;
if (is_numeric($seccion1) == TRUE )
{
$sql=$sql." AND section=".$seccion1;
}
$sql=$sql." GROUP BY section,id,name,created";
$pdf->Table($sql);
//-------------------------------------------------------------------------
//Second table: specify 3 columns
$pdf->AddPage();
$pdf->AddCol('id','15','CD');
$pdf->AddCol('section',16,'Seccion');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>1);
$pdf->Table('select a.id,a.section from smart_publsections a limit 0,21',$prop);
$pdf->AddCol('id','15','CD');
$pdf->AddCol('state','20','Estado');
$prop2=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>1);
$pdf->Table2('select b.id ,b.state from smart_states b',$prop2);
$modo="D";
$nombre=("algo".time().".pdf");
$pdf->Output($nombre,$modo);
//--------------------------------------------
}
?>
mysql_table.php
Código PHP:
<?php
require('fpdf.php');
class PDF_MySQL_Table extends FPDF
{
var $ProcessingTable=false;
var $aCols=array();
var $TableX;
var $HeaderColor;
var $RowColors;
var $ColorIndex;
function Header()
{
//Print the table header if necessary
if($this->ProcessingTable)
$this->TableHeader();
}
function TableHeader()
{
$this->SetFont('Arial','B',6);
$this->SetX($this->TableX);
$fill=!empty($this->HeaderColor);
if($fill)
$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
$this->Ln();
}
function Row($data)
{
$this->SetX($this->TableX);
$ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]);
if($fill)
$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
$this->Ln();
$this->ColorIndex=1-$ci;
}
function CalcWidths($width,$align)
{
//Compute the widths of the columns
$TableWidth=0;
foreach($this->aCols as $i=>$col)
{
$w=$col['w'];
if($w==-1)
$w=$width/count($this->aCols);
elseif(substr($w,-1)=='%')
$w=$w/70*$width;
$this->aCols[$i]['w']=$w;
$TableWidth+=$w;
}
//Compute the abscissa of the table
if($align=='C')
$this->TableX=max(($this->w-$TableWidth)/2,0);
elseif($align=='R')
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
else
$this->TableX=$this->lMargin;
}
function AddCol($field=-1,$width=-1,$caption='',$align='L')
{
//Add a column to the table
if($field==-1)
$field=count($this->aCols);
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
}
function Table($query,$prop=array())
{
//Issue query
$res=mysql_query($query) or die('Error: '.mysql_error()."<BR>Query: $query");
//Add all columns if none was specified
if(count($this->aCols)==0)
{
$nb=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Retrieve column names when not specified
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
//Handle properties
if(!isset($prop['width']))
$prop['width']=0;
if($prop['width']==0)
$prop['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop['align']))
$prop['align']='L';
if(!isset($prop2['aling']))
$prop2['aling']='C';
if(!isset($prop['padding']))
$prop['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop['padding'];
if(!isset($prop['HeaderColor']))
$prop['HeaderColor']=array();
$this->HeaderColor=$prop['HeaderColor'];
if(!isset($prop['color1']))
$prop['color1']=array();
if(!isset($prop['color2']))
$prop['color2']=array();
$this->RowColors=array($prop['color1'],$prop['color2']);
//Compute column widths
$this->CalcWidths($prop['width'],$prop['align']);
//Print header
$this->TableHeader();
//Print rows
$this->SetFont('Arial','',5);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
function Table2($query2,$prop2=array())
{
//Issue query
$res2=mysql_query($query2) or die('Error: '.mysql_error()."<BR>Query: $query");
//Add all columns if none was specified
if(count($this->aCols)==0)
{
$nb2=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Retrieve column names when not specified
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
//Handle properties
if(!isset($prop2['width']))
$prop2['width']=0;
if($prop2['width']==0)
$prop2['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop2['align']))
$prop2['align']='L';
if(!isset($prop2['aling']))
$prop2['aling']='C';
if(!isset($prop2['padding']))
$prop2['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop2['padding'];
if(!isset($prop2['HeaderColor']))
$prop2['HeaderColor']=array();
$this->HeaderColor=$prop2['HeaderColor'];
if(!isset($prop2['color1']))
$prop2['color1']=array();
if(!isset($prop2['color2']))
$prop2['color2']=array();
$this->RowColors=array($prop2['color1'],$prop2['color2']);
//Compute column widths
$this->CalcWidths($prop2['width'],$prop2['align']);
//Print header
$this->TableHeader();
//Print rows
$this->SetFont('Arial','',5);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res2))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
}
?>