hola envipe79, yo utilizo la clase ezpdf a la cual le agregue un extends backgroundPDF para generar pdf de los articulos de una web.
hice un archivo crearPDF.php donde le paso por $_GET el id del post a generar el pdf aqui el codigo
Código php:
Ver originalfunction HexToRGB($hex) {
}
}
$color['r'] = round(($color['r']/255)*100)/100; $color['g'] = round(($color['g']/255)*100)/100; $color['b'] = round(($color['b']/255)*100)/100;
return $color ;
}
function RGBToHex($r, $g, $b) {
$hex = "#";
return $hex;
}
class Creport extends backgroundPDF {
var $reportContents = array();
function Creport
($p,$o,$type = 'none', $options = array()){ $this->backgroundPDF($p,$o,$type,$options);
}
function rf($info){
// this callback records all of the table of contents entries, it also places a destination marker there
// so that it can be linked too
$tmp = $info['p'];
$lvl = $tmp[0];
$num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
$this->reportContents[] = array($lbl,$num,$lvl ); $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']); }
function dots($info){
// draw a dotted line over to the right and put on a page number
$tmp = $info['p'];
$lvl = $tmp[0];
$xpos = 520;
switch($lvl){
case '1':
$size=16;
$thick=1;
break;
case '2':
$size=12;
$thick=0.5;
break;
}
$this->saveState();
$this->setLineStyle($thick,'round','',array(0,10)); $this->line($xpos,$info['y'],$info['x']+5,$info['y']);
$this->restoreState();
$this->addText($xpos+5,$info['y'],$size,$lbl);
}
function setEstilo($info){
switch($info['p']){
case 'titulo':
$color = HexToRGB('717C7E');
$this->setColor($color['r'],$color['g'],$color['b']);
$cS = HexToRgb("e8efdb");
$this->setStrokeColor($cS['r'],$cS['g'],$cS['b']);
$this->setLineStyle(0.1);
$this->line($info['x'],($info['y']-($info['height']/2)),550,($info['y']-($info['height']/2)));
$this->ezSetY(($info['y']-($info['height']/2)));
break;
case 'texto':
$color = HexToRGB('999999');
$this->setColor($color['r'],$color['g'],$color['b']);
break;
}
}
function img($info){
if($ext=='jpg'){
$this->addJpegFromFile($info['p'],$info['x'],($info['y']-($info['height']/2)),($tam[0]/2),($tam[1]/2));
$this->ezSetY($info['y']-($info['height']*2));
}else{
$this->addPngFromFile($info['p'],$info['x'],$info['y'],($tam[0]/2),($tam[1]/2));
}
}
}
if(isset($_GET['idPost'])){ global $DbConn;
//Buscamos la informacion del post
$sql = 'SELECT * FROM post WHERE id='.$_GET['idPost'];
$Post = $DbConn->fetchAssoc($DbConn->query($sql));
//limpiamos
$Post['contenido']= $Post['contenido'];
$Post['contenido']= str_replace('<br />','',$Post['contenido']); $Post['contenido']= str_replace('<li>',' <c:img:../img/estilos/liPag.jpg></c:img>',$Post['contenido']); $Post['contenido']= str_replace('</li>','',$Post['contenido']); $Post['contenido']= str_replace('<h1>','<b>',$Post['contenido']); $Post['contenido']= str_replace('</h1>','</b>',$Post['contenido']);
//instanciamos la clase Cezpdf
$c = HexToRgb("#FFFFFF");
$pdf = new Creport
('a4','portrait','color',array('r'=>$c['r'],'g'=>$c['g'],'b'=>$c['b'])); $pdf->selectFont('../include/fonts/Helvetica.afm');
//Configuramos los margenes
$pdf -> ezSetMargins(50,70,50,50);
// Generamos las cabeceras
$all = $pdf->openObject();
$pdf->saveState();
$cS = HexToRgb("e8efdb");
$pdf->setStrokeColor($cS['r'],$cS['g'],$cS['b']);
$pdf->addJpegFromFile('../img/png/logo.jpg',($pdf->ez['pageWidth']-(($tam[0]/2)+5)),($pdf->ez['pageHeight']-($tam[1]/2)),$tam[0]/2,$tam[1]/2);
$pdf->line(20,40,578,40);
$pdf->addText(50,34,6,'http://www.xxxx.xxx.xx - Portal de Ecología'); $pdf->restoreState();
$pdf->closeObject();
$pdf->addObject($all,'all');
$pdf->ezStartPageNumbers(500,28,5,'','{PAGENUM} de {TOTALPAGENUM}',1);
//recorremos los datos
$pdf->ezText("<C:setEstilo:titulo>".$Post['titulo']."</c:setEstilo>\n",10);
$pdf->ezText("<C:setEstilo:texto>".$Post['contenido']."</c:setEstilo>\n",5.5,array('justification'=>'full'));
//prueba callback
//$pdf->ezText("<C:img:></c:img>\n",5.5,array('justification'=>'full'));
$pdf->output();
$pdf->ezStream();
}