0

Tengo este código que no se renderiza a pdf.

<html>
<head>
<style type="text/css">


</style>

</head>
<body  >

<?php

   
 //ob_start();

	   include('config.php');
	  /* $link = mysql_connect("localhost", "root", "******"); 
	   mysql_select_db("****", $link);*/
       if(isset($_GET['id']))
    {
		$id=$_GET['id'];
	
				
	}
	
	$sq = "SELECT * from caso WHERE bl = '$id' ORDER BY id_bl DESC LIMIT 5";
		$result1 = mysqli_query($connex, $sq);
		while($row2 = mysqli_fetch_assoc($result1))
			{
			$bl3=$row2['bl'];
			$bl4=$row2['nom_cli'];
			$bl5=$row2['cod_cli'];
			$bl6=$row2['fech'];
			$bl7=$row2['origen'];
     		$bl8=$row2['cant'];
			$bl9=$row2['alm'];
			$bl10=$row2['ret'];
			$bl11=$row2['coment'];
			}
	   
	   echo"   <head> <style type='text/css'>

.logo{
	position: relative;
    right: 50 px;
	width:75 px;	
	
	
}
body {
    font-family: 'Helvetica';
	font-size: 8px;
}
table {
    border-collapse: collapse;
}
</style>
</head>  ";
	   
      echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
      echo"<img src='logo2.jpg' class='logo' />";
	  
	  echo"<center><h1>Informe de carga Foto.</h1></center>";
	   echo'<hr>';
	   echo'<br>'; 

	  
	  echo '<table  border="0" cellpadding="4" align="" cellspacing="0" >';
 	echo '<tr>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
 		echo'<td  align="right"><b>Número de caso:</b></td>';
 		echo"<td  style='color:red'  >$bl3 </td>";
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td  align="right"><b>Cliente:</b></td>';
 		echo"<td style='color:red'>$bl4</td>";
		echo'<td>&nbsp;</td>';
 		echo'<td><b>Codigo de cliente:</b></td>';
 		echo"<td>$bl5</td>";
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';  
 		echo'<td><b>Fecha de creación:</b></td>';
 		echo"<td>$bl6</td>"; 
	echo '</tr>'; 
	echo'<tr>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
 		echo'<td  align="right"><b>Origen:</b></td>';
 		echo"<td>$bl7</td>";
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
  		echo'<td><b>Cantidad de items:</b></td>';
 		echo"<td>$bl8</td>";
		echo'<td>&nbsp;</td>';
		echo'<td><b>Almacenamiento:</b></td>';
 		echo"<td>$bl9</td>"; 
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td align="right"><b>Retención:</b></td>';
 		echo"<td>$bl10</td>"; 
 	echo'</tr>'; 
	echo'<tr>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
 		echo'<td align="right"><b>Comentario:</b></td>';
 		echo"<td>$bl11</td>";
 		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
 		echo'<td>&nbsp;</td>';
 		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>'; 
 		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
		echo'<td>&nbsp;</td>';
 		echo'<td>&nbsp;</td>';
 		echo'<td>&nbsp;</td>'; 
 	echo'</tr>'; 
 echo'</table>';
echo "<br>";

echo"<hr></hr>";

	  
	  
   
		$sql = "SELECT * FROM acarga WHERE bl3 = '$id'";
		$result = mysqli_query($connex, $sql);
	 echo' <table  width="100%" height="99" border="0" >';
  echo '<tr>'; 
 echo'   <th>&nbsp;</th>';
  echo'  <th>&nbsp;</th>';
   echo' <th>Cód item</th>';
   echo' <th><label for="textfield3"></label></th>';
   echo' <th></th>';
   echo' <th><label for="textfield4"></label></th>';
   echo' <th>Cód camión</th>';
   echo' <th><label for="textfield5"></label></th>';
   echo' <th>Tipo P.A.</th>';
   echo' <th><label for="textfield6"></label></th>';
   echo' <th>Código P.A.</th>';
   echo' <th><label for="textfield7"></label></th>';
   echo' <th>Destino</th>';
   echo' <th><label for="textfield8"></label></th>';
    echo'<th>Estado de carga</th>';
   echo' <th><label for="textfield9"></label></th>';
   echo' <th>Fecha</th>';
   echo' <th><label for="textfield10"></label></th>';
   echo' <th>Hora</th>';
    echo'<th>&nbsp;</th>';
   echo' <th>Comentario</th>';
   echo' <th>&nbsp;</th>';
   echo' <th>Foto</th>';
   echo' <th>&nbsp;</th>';
   echo '</tr>'; 
    //while($row = mysql_fetch_array($result))
   
   while($row = mysqli_fetch_assoc($result))
   {
	$a=$row['cod_it'];
	$b=$row['bl3'];
	$c=$row['uni_ca'];
	$d=$row['tipo_pa'];
	$e=$row['num_int'];
	$f=$row['dest'];
	$g=$row['estado'];
	$h=$row['fecha'];
	$i=$row['hora'];
	$j=$row['comenta'];
    //$k=$row['ruta_imagen'];
	$imageURL = $row['ruta_imagen'];

  echo'<tr>';
  echo'<td></td>';
  echo'<td></td>';
  echo"<td align='center' > $a </td>   ";
  echo'<td></td>';
  echo"<td  align='center' > </td>   ";
  echo'<td></td>';
  echo"<td align='center' > $c </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td align='center' > $d </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td align='center' > $e </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td align='center' > $f </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td align='center' > $g </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td align='center' > $h </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td  align='center' > $i </td>   ";
  echo'<td>&nbsp;</td>';
  echo"<td  align='center' > $j </td>   ";
  echo'<td>&nbsp;</td>';
 echo"<td><img src='img/$imageURL' width='400' /></td>";
  echo'<td>&nbsp;</td>';
  echo'</tr>';
   
   
   }
   
  echo' </table>';


require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
</body>
</html>

y se muestra de esta forma en vez de pdf: introducir la descripción de la imagen aquí

1
  • Dado a que FPDF no renderiza el html es necesario hacer un diseño directamente desde sus funciones, aunque tambien podrias simplemente crear un script en JS para imprimir esa pestaña tal cual lo tienes en la imagen, (tambien hay otras librerias con otras funcionalidades, que renderizan tu html)
    – ByGroxD
    el 5 jun. 2018 a las 4:54

1 respuesta 1

0

Al fpdf no se puede trabajar con HTML, a menos que utilices una extensión, pero te recomiendo dompdf, te crea El pdf a base de css y html, los datos php los recibes mediante post o get según tus datos, es mas facil ;)

2
  • Hola que tal?, te comento que esto es un comentario no una respuesta, te pido de manera amable que la elimines y revises nuestras normas de la comunidad, saludos!.
    – ByGroxD
    el 5 jun. 2018 a las 4:51
  • @angel Ruiz estaba usando el dompdf pero me muestra error al momento de imprimir imagenes de forma dinamica, no reconoce el formato o algo asi el 5 jun. 2018 a las 13:44

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.