Foros del Web » Programando para Internet » PHP »

la forma mas facil de exportar a pdf o .doc

Estas en el tema de la forma mas facil de exportar a pdf o .doc en el foro de PHP en Foros del Web. hola amigos, estoy tratando de exportar un tablas a pdf con php, yo ocupo doompdf, pero la verdad es que me tirar un error cuando ...
  #1 (permalink)  
Antiguo 29/06/2008, 00:08
Avatar de besotico  
Fecha de Ingreso: junio-2008
Ubicación: Iquique, Chile, Chile
Mensajes: 70
Antigüedad: 15 años, 11 meses
Puntos: 0
Exclamación la forma mas facil de exportar a pdf o .doc

hola amigos, estoy tratando de exportar un tablas a pdf con php, yo ocupo doompdf, pero la verdad es que me tirar un error cuando hay muchas tablas, como que se me "marea" un poco el codigo...

he buscado formas de hacerlo y encontre la alternativa de "R&OS" en las faq y en google, pero la verdad es que es bastante complicado, no soy novato pero es bastante engorroso el trabajo de exportacion..

ahora tambien tengo problemas en doompdf al incluir imagenes, con el codigo "$pdf -> image ('ruta,ancho,alto,etc');

existe alguna forma para exportar a alguno de los formatos mencionados en el titulo sin que sea un gran problema?

estoy tomando datos de mysql para lo cual con un poco de ingenio lo hago excelentemente con doompdf...

el error que me arroja es el siguiente

Código:
Fatal error: Uncaught exception 'DOMPDF_Internal_Exception' with message 'Frame not found in cellmap' in 
C:\AppServ\www\rnm\includes\dompdf\include\cellmap.cls.php:237 Stack trace: #0 
C:\AppServ\www\rnm\includes\dompdf\include\table_cell_frame_reflower.cls.php(66): 
Cellmap->get_frame_position(Object(Table_Cell_Frame_Decorator)) #1 
C:\AppServ\www\rnm\includes\dompdf\include\frame_decorator.cls.php(387): Table_Cell_Frame_Reflower->reflow() #2 
C:\AppServ\www\rnm\includes\dompdf\include\table_row_frame_reflower.cls.php(70): Frame_Decorator->reflow() #3 
C:\AppServ\www\rnm\includes\dompdf\include\frame_decorator.cls.php(387): Table_Row_Frame_Reflower->reflow() #4 
C:\AppServ\www\rnm\includes\dompdf\include\table_frame_reflower.cls.php(468): Frame_Decorator->reflow() #5 
C:\AppServ\www\rnm\includes\dompdf\include\frame_decorator.cls.php(387): Table_Frame_Reflower->reflow() #6 
C:\AppServ\www\rnm\includes\dompdf\include\block_frame_reflower.cls.php(408): Frame_Decorator->reflow() #7 
C:\AppServ\www\rnm\includes\dompdf\include\frame_d in C:\AppServ\www\rnm\includes\dompdf\include\cellmap.cls.php on line 237
y mi codigo es

Código PHP:
require_once("dompdf/dompdf_config.inc.php");
$html =

'
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />

<title></title>
<style type="text/css">
<!--
#apDiv1 {
    position:absolute;
    left:157px;
    top:120px;
    width:39px;
    height:20px;
    z-index:1;
}
#apDiv2 {
    position:absolute;
    left:276px;
    top:117px;
    width:36px;
    height:23px;
    z-index:2;
}
#apDiv3 {
    position:absolute;
    left:55px;
    top:118px;
    width:44px;
    height:21px;
    z-index:3;
}
-->
</style>
</head>
<body>

'
;

//Requeridos
include '../req/config.inc.php';
$seniores $_GET['seniores'];
$rut $_GET['rut'];
$direccion $_GET['direccion'];
$ciudad $_GET['ciudad'];
$giro $_GET['giro'];
$telefono $_GET['telefono'];
$guia $_GET['guia'];
$condiciones $_GET['condiciones'];
$neto $_GET['neto'];
$iva $_GET['iva'];
$total $_GET['total'];
//$dia 
//$mes
//$anio

$query_folio_factura mysql_query("SELECT * FROM config") or die (mysql_error());
$obtener_folio_factura mysql_fetch_assoc($query_folio_factura);
$folio_factura1 $obtener_folio_factura['config_factura'];
$folio_factura2=$folio_factura1 1;

function 
add_ceros($numero,$ceros) {
$order_diez explode(".",$numero);
$dif_diez $ceros strlen($order_diez[0]);
for(
$m ;
$m $dif_diez;
$m++)
{
@
$insertar_ceros .= 0;
}
return 
$insertar_ceros .= $numero;
}
$folio_factura add_ceros($folio_factura2,6);


$query_venta_id mysql_query("SELECT * FROM ventas WHERE folio_factura = '$folio_factura'") or die (mysql_error());
$obtener_venta_id mysql_fetch_assoc($query_venta_id);
$venta_id $obtener_venta_id['venta_id'];


            
$query=mysql_query  ("SELECT * FROM ventas_detalle WHERE venta_id='$venta_id'") or die (mysql_error());
;

*/
$html .='
<div id="apDiv1">$mes</div>
<div id="apDiv2">$ano</div>
<div id="apDiv3">$dia</div>
<br />
  <br />
  <br />
  <br />
  <br>
  <br>
  <br />  
  <br />
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="494" valign="top">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$seniores.'</td>

<td width="136" valign="top" align="center">
<p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$rut.'</div>
</td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="474" valign="top">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$direccion.'</td>

<td width="156" valign="top" align="center">
<p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$ciudad.'</div>
</td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="466" valign="top">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$giro.'</td>

<td width="164" valign="top" align="center">
<p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
.$telefono.'&nbsp;</div>
</td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="363" valign="top">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

<td width="267" valign="top" align="center">
<p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
</td>
</tr>
</table><br />
<br />
<br />
<br />
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="75" valign="top" height="700">
<div align="center">&nbsp;</div>
</td>

<td width="380" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="85" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="90" valign="top" align="center">
<div align="center">&nbsp;</div>
</td>
</tr>
</table><br />

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="300" valign="top">&nbsp;</td>
<td width="145" valign="top">
<div align="center">&nbsp;</div>
</td>
<td width="85" valign="top">
<p align="left">&nbsp;&nbsp;&nbsp;</div>
</td>
<td width="90" valign="top" align="center">
<p align="left">&nbsp;&nbsp; '
.$neto.'</div>
</td>
</tr>
<tr>
<td width="300" valign="top">&nbsp;</td>

<td width="145" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="85" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="90" valign="top" align="center">
<div align="center"></div>
</td>
</tr>

<tr>
<td width="300" valign="top">&nbsp;</td>

<td width="145" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="85" valign="top">
<p align="left">&nbsp;</div>
</td>

<td width="90" valign="top" align="center">
<p align="left">&nbsp;&nbsp; '
.$iva.'</div>
</td>
</tr>

<tr>
<td width="300" valign="top">&nbsp;</td>

<td width="145" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="85" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="90" valign="top" align="center">
<div align="center"></div>
</td>
</tr>

<tr>
<td width="300" valign="top">&nbsp;</td>

<td width="145" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="85" valign="top">
<div align="center">&nbsp;</div>
</td>

<td width="90" valign="top" align="center">
<p align="left">'
.$total.'</div>
</td>
</tr>
</table>
</body>
</html>
'
;
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf"); 
como pueden observar existen muchos espacios y varias cosas que no son "normales" a esta altura, como por ejemplo los <p align..> que estan a modo de prueba ya que pense que quizas los <div align..> no funcionaban, he hecho varias modificacaciones pero siempre obtengo el mismo error... la razon de las cosas mencionadas anteriormente es que es para imprimir datos sobre una factura de imprenta (no digital) y necesito que los datos vayan donde tienen que ir... si alguien puediera ayudarme por favor llevo semanas tratando de hacerlo y no consigo lograrlo :( y lo peor es que el tiempo para la entrega de mi sistema ya esta en contra.. ya presente mi beta y tengo 1 semana para terminar

prometo liberar mi codigo de fuente si logro sacar esto adelante ya que este foro me ha dado mucho y en muy poco tiempo...
  #2 (permalink)  
Antiguo 29/06/2008, 23:16
Avatar de besotico  
Fecha de Ingreso: junio-2008
Ubicación: Iquique, Chile, Chile
Mensajes: 70
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: la forma mas facil de exportar a pdf o .doc

no existe alguien que me pueda ayudar?
  #3 (permalink)  
Antiguo 01/08/2008, 04:10
 
Fecha de Ingreso: febrero-2005
Ubicación: Cádiz
Mensajes: 50
Antigüedad: 19 años, 2 meses
Puntos: 2
Respuesta: la forma mas facil de exportar a pdf o .doc

yo tengo el uso de esta funcion:
Código PHP:
function pdf_create($html$filename$stream=TRUE)
{
   require_once(
"dompdf/dompdf_config.inc.php");
   require_once(
"convertcharset/ConvertCharset.class.php");
    
    
$dompdf = new DOMPDF();
    
$convertcharset = new ConvertCharset();
        
$html $convertcharset->Convert($html'utf-8''iso-8859-1');
    
$dompdf->load_html($html);
    
    
$dompdf->render();
     if (
$stream) {
          
$dompdf->stream($filename.".pdf");
    } else {
        
write_file("./invoices_temp/invoice_$filename.pdf"$dompdf->output());
    }

donde $html lo tengo con tablas como tu. Sé que las tablas anidadas son incompatibles, y da errores en las librerías, revisa algunas anidadas o tablas con celdas que ocupen más de un espacio. Han de ser tablas simples y creo que separadas por <p></p>

De todas formas las cabeceras y los pies han de ponerse en etiquetas dentro del html de la forma
Código PHP:
<script type="text/php" charset="UTF-8">
...
</script> 
  #4 (permalink)  
Antiguo 01/08/2008, 04:42
 
Fecha de Ingreso: febrero-2005
Ubicación: Cádiz
Mensajes: 50
Antigüedad: 19 años, 2 meses
Puntos: 2
Respuesta: la forma mas facil de exportar a pdf o .doc

El problema de las imagenes tambien lo he tenido yo, he buscado en las clases de las librerías y he encontrado:
Código PHP:
  function  addJpegFromFile($img$x$y$w =  0$h =  0) {

    
// attempt to add a jpeg image straight from a file, using no GD commands
    // note that this function is unable to operate on a remote file.
.
.
.

Es decir, que antes de sacarla de la bbdd tienes que guardarla a un fichero y luego coger ese fichero de una ruta local, porque usa fopen, que no puede abrir ficheros externos.
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 15:02.