Foros del Web » Programando para Internet » PHP »

Problema con fpdf

Estas en el tema de Problema con fpdf en el foro de PHP en Foros del Web. Hola tengo un texto guardado en una bdd, con formato de texto, el cual es el siguiente: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código CSS: Ver original <p style ...
  #1 (permalink)  
Antiguo 02/01/2011, 14:29
 
Fecha de Ingreso: julio-2010
Mensajes: 47
Antigüedad: 13 años, 8 meses
Puntos: 1
Pregunta Problema con fpdf

Hola tengo un texto guardado en una bdd, con formato de texto, el cual es el siguiente:

Código CSS:
Ver original
  1. <p style="text-align: justify;">
  2.     <span style="color: rgb(255, 0, 0);">No </span>pudo concluir &eacute;ste <strong><span style="color: rgb(51, 51, 255);">2010 </span></strong>sin que la sonda <span style="color: rgb(255, 0, 0);">STEREO-B</span> nos regalara otra imagen. Desde el <span style="color: rgb(51, 51, 255);">Observatorio de Din&aacute;mica Solar <span style="font-weight: bold;">SOHO </span></span>&eacute;ste <span style="color: rgb(255, 0, 0);">30 de Diciembre </span>(<span style="font-weight: bold;">2010</span>) se viene registrando una enorme falla en nuestro <span style="font-weight: bold; color: rgb(255, 255, 51);">Sol </span>que se conoce como <span style="font-style: italic; color: rgb(255, 0, 0);">agujero coronal</span>, &eacute;sta es un falla donde el <span style="color: rgb(51, 51, 255); font-style: italic;">campo magn&eacute;tico </span>del <span style="font-weight: bold; color: rgb(255, 255, 51);">Sol </span>se abre permitiendo a los<span style="color: rgb(255, 0, 0); font-style: italic;"> vientos solares </span>escaparse, los lentes de las sondas vienen registrando &eacute;ste fen&oacute;meno al detalle tanto que para variar se capturan nuevamente extra&ntilde;os objetos en el<span style="color: rgb(51, 51, 255);"> limbo oriental</span> del Astro Rey. Cerramos el a&ntilde;o con &eacute;stos colosales objetos cerca al <span style="font-weight: bold; color: rgb(255, 255, 51);">Sol </span>sin saber qu&eacute; son.</p>

Y quiero generar un pdf usando la clase fpdf, estoy usando el siguiente codigo:

Código PHP:
<?php

define
('FPDF_FONTPATH','font/');

require(
'fpdf.php');
//$id=$_GET['Id']

//Conexion a la bd
include("../Connections/conn.php");

//Crea un nuevo pdf
$pdf=new FPDF();

//Disable automatic page break
$pdf->SetAutoPageBreak(true);

//Añade primera página
$pdf->AddPage();

//seteo inicial de margenes y position axis pr pagina
$y_axis_initial 0;
$x_axis 10;
$y_axis 20;

//imprime los titulos de columna para la pagina (quitar comentarios para activar)
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',10);
$pdf->SetY($y_axis_initial);

//$pdf->Cell(30,6,'CODI',1,0,'L',1);


$y_axis $y_axis $row_height;

//Hago una query a mi bd
//$result=@mysql_query('SELECT * FROM articulos WHERE articulos.Id = ".$_GET['Id']."',$conexion);
mysql_select_db($database_conn$conn);
$query_Articulos "SELECT * FROM articulos WHERE articulos.Id = ".$_GET['Id']."";
$Articulos mysql_query($query_Articulos$conn) or die(mysql_error());
$row_Articulos mysql_fetch_assoc($Articulos);
$totalRows_Articulos mysql_num_rows($Articulos);
//inicializo el contador
$i 0;

//Seto el maximo de filas por pagina
$max 25;

//Seteo la altuira de la fila
$row_height 6;

while(
$row =@mysql_fetch_array($result))
{
//Si la fila actual es la ultima, creo una nueva página e imprimo el titulo (quitar comentarios para activar)
if ($i == $max)
{
$pdf->AddPage();

//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30,6,'id',1,0,'L',1);


//Go to next row
$y_axis $y_axis $row_height;

//Set $i variable to 0 (first row)
$i 0;
}

$id $row['Id'];
$articulo $row['Articulo'];


$pdf->SetY($y_axis);
$pdf->SetX($x_axis);
$linea=$id.$articulo;
$pdf->MultiCell(0,6,$linea,0,1,'L',10);
$pdf->MultiCell(30,6,$id,0,0,'L',0);
$pdf->MultiCell(90,6,$articulo,0,0,'Ln',0);
//$pdf->MultiCell(120,6,$LIBRE,0,0,'Ln',0);


//Go to next row
$y_axis $y_axis $row_height;
$i $i 1;
}

mysql_close($conn);

//Create file
$pdf->Output();
?>

El problema es que me muestra una pagina en blanco en el pdf, tambien estoy usando un buscador, por lo cual tengo que tomar la ID para mostrar el texto que he elegido, ¿alguien me puede ayudar con esto?, ¿como deberia hacer?

Gracias
  #2 (permalink)  
Antiguo 02/01/2011, 14:31
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Problema con fpdf

podrías activar el reporte de errores al inicio de tu script?
Código PHP:
error_reporting(E_ALL);
ini_set('display_errors'1); 
también sería bueno que no ocultaras los errores con @

de cualquier forma, al menos un error deberías recibir, cuando lo obtengas no dudes en indicarnos el mensaje completo...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 02/01/2011, 17:39
 
Fecha de Ingreso: julio-2010
Mensajes: 47
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Problema con fpdf

Cita:
Iniciado por pateketrueke Ver Mensaje
podrías activar el reporte de errores al inicio de tu script?
Código PHP:
error_reporting(E_ALL);
ini_set('display_errors'1); 
también sería bueno que no ocultaras los errores con @

de cualquier forma, al menos un error deberías recibir, cuando lo obtengas no dudes en indicarnos el mensaje completo...

Gracias, puse tu codigo y este es el error que devuelve:

Notice: Undefined variable: row_height in D:\AppServ\www\ovnis\c\ex.php on line 35

Warning: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\ovnis\c\ex.php:35) in D:\AppServ\www\ovnis\c\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file



que podria hacer para que funcione?
He probado de varias formas y no he logrado nada. El codigo del archivo ex.php lo he sacado de aqui: http://www.forosdelweb.com/f18/fpdf-consulta-mysql-598799/
y le he puesto algunas modificaciones.
El archivo fpdf.php lo baje de la pag oficial, no lo he modificado.

Muchas gracias, espero sus respuestas
  #4 (permalink)  
Antiguo 02/01/2011, 18:30
 
Fecha de Ingreso: julio-2010
Mensajes: 47
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Problema con fpdf

Saque otro codigo de aqui: http://www.forosdelweb.com/f18/clase-fpdf-problemillas-702823/

Es el siguiente:
Código PHP:
<?php
//pa generar pdfs
require('fpdf.php');
define('FPDF_FONTPATH','font/');
//includes
include("../Connections/conn.php");
//obtenemos id tabla
//id tabla
$idt=$_GET['Id'];

//datos del juego
$tabla mysql_query("SELECT * FROM articulos where Id='$idt'");


while (
$registro mysql_fetch_array($tabla)) {
$juego=$registro['Articulo'];
//$categoria=$registro['categoria'];
//$trucos=$registro['truco'];
//$uploader=$registro['uploader'];
}

//pdf con codigo html ;)

//no tocar
class PDF extends FPDF
{
var 
$B;
var 
$I;
var 
$U;
var 
$HREF;

function 
PDF($orientation='P',$unit='mm',$format='A4')
{
//Llama al constructor de la clase padre
$this->FPDF($orientation,$unit,$format);
//Iniciación de variables
$this->B=0;
$this->I=0;
$this->U=0;
$this->HREF='';
}

function 
WriteHTML($html)
{
//Intérprete de HTML
$html=str_replace("\n",' ',$html);
$a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach(
$a as $i=>$e)
{
if(
$i%2==0)
{
//Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
//Etiqueta
if($e[0]=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
//Extraer atributos
$a2=explode(' ',$e);
$tag=strtoupper(array_shift($a2));
$attr=array();
foreach(
$a2 as $v)
{
if(
preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
$attr[strtoupper($a3[1])]=$a3[2];
}
$this->OpenTag($tag,$attr);
}
}
}
}

function 
OpenTag($tag,$attr)
{
//Etiqueta de apertura
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,true);
if(
$tag=='A')
$this->HREF=$attr['HREF'];
if(
$tag=='BR')
$this->Ln(5);
}

function 
CloseTag($tag)
{
//Etiqueta de cierre
if($tag=='B' || $tag=='I' || $tag=='U')
$this->SetStyle($tag,false);
if(
$tag=='A')
$this->HREF='';
}

function 
SetStyle($tag,$enable)
{
//Modificar estilo y escoger la fuente correspondiente
$this->$tag+=($enable : -1);
$style='';
foreach(array(
'B','I','U') as $s)
{
if(
$this->$s>0)
$style.=$s;
}
$this->SetFont('',$style);
}

function 
PutLink($URL,$txt)
{
//Escribir un hiper-enlace
$this->SetTextColor(0,0,255);
$this->SetStyle('U',true);
$this->Write(5,$txt,$URL);
$this->SetStyle('U',false);
$this->SetTextColor(0);
}
}
//fin clase de pdf generator

//lo k kieras mostrar aqui
$html=' <a href="http://www.ejemplo.org">TodoTrucos.com tu web de trucos online</a><br><br><h2>Trucos de '.$juego.'</h2><br><br>';

$pdf=new PDF();
//Primera página
$pdf->AddPage();
$pdf->SetFont('Arial','',20);

//imagen yo la pondr en la variable $html
//$pdf->Image('logo.png',10,12,30,0,'','http://www.fpdf.org');

$pdf->SetLeftMargin(45);
$pdf->SetFontSize(14);
//codigo k escribe el html
$pdf->WriteHTML($html);
//sacar pdf
$pdf->Output();
?>


me genera el pdf pero no le da el formato al texto, ningun color, vinculos, ni demas...

que podria hacer para solucionar esto?

Muchas gracias desde ya.
  #5 (permalink)  
Antiguo 02/01/2011, 22:04
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Desacuerdo Respuesta: Problema con fpdf

Cita:
Iniciado por Pury Ver Mensaje
me genera el pdf pero no le da el formato al texto, ningun color, vinculos, ni demas...

que podria hacer para solucionar esto?

Muchas gracias desde ya.
recuerdo que ya habías abierto un tema preguntando lo mismo...

y una de las sugerencias era usar DOMPDF, pero bueno, de paso lee las normas del foro, ya que andas duplicando temas....
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.

Etiquetas: css, fpdf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:43.