0

When I generate a PDF content is displayed but not the image. Why?

I think the PDF is generated before the image is loaded. Is there any way to slow down the operation?

<?php
  // Include the main TCPDF library (search for installation path).
  include('tcpdf/tcpdf.php');
  // Variables globals
  $ID = "";
  // create new PDF document
  $pdf = new TCPDF('P', PDF_UNIT, 'A4', true, 'UTF-8', false);
  // set document information
  $pdf->SetCreator (PDF_CREATOR);
  $pdf->SetAuthor ('Disseny de bases de dades');
  $pdf->SetTitle ('Llistat dagencies de la ciutat de ');
  $pdf->SetSubject ('Exemple de creació de pdf amb intercacció amb una base de dades');
  $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  // add a page
  $pdf->AddPage();
  // Amb la funció empty verifiquem si l'usuari arriva a la pàgina després d'introduir les dades al formulari o bé si acaba de
  // carregar la pàgina i encara no ha omplert cap dada al formulari.
  if (!empty($_GET)) {
    // La funció "isset" s'utilitza per a saber si una variable ha estat definida.
    if(isset($_GET['ID'])) {
      $ID= $_GET['ID'];
    }
  }
  //El tercer pas es realitzar la connexió a la base de dades.
  // Ens conectem a la base de dades.
  $localhost = "localhost";
  $mysqli = new mysqli( $localhost, $user, $pwd, $database);
  $mysqli->set_charset("utf8");
  $busqueda = "SELECT A.nombre AS nombre, A.fecha_instalacion AS instalacion, A.descripcion AS descripcion, A.latitud AS latitud, A.longitud AS longitud, T.Nombre AS nombretipo FROM Atraccion AS A INNER JOIN R_clasificacion ON R_clasificacion.ID_Atraccion=A.ID INNER JOIN Tipos AS T ON R_clasificacion.ID_Tipos=T.ID WHERE A.ID= '".$ID."'  ";
  if ($result = $mysqli->query($busqueda)) {
    if ($result->num_rows > 0) {
      while($row = $result->fetch_array(MYSQLI_ASSOC)) {
        $nombre = $row['nombre'];
        $fecha = $row['instalacion'];
        $descripcion = $row['descripcion'];
        $nombretipo = $row['nombretipo'];
        $longitud = $row['longitud'];
        $latitud = $row['latitud'];
      }
    }
  }
  // set some text to print
  $html = "

    <style>
        @import url(http://fonts.googleapis.com/css?family=Muli:400italic);
        #titulos {text-align: left; font-family: 'Muli', sans-serif;}
        #imagenes {float: right;  margin: 0 0 0 5%;}
        #textos { color: red;text-align: justify; margin-right: 5em;}
        #contenedor {margin: 3% 7% 3% 7%;};
    </style>";
  $html .="
    <html lang=\"es\">
        <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
    <head>
        <title>Página a imprimir</title>
    </head>
    <body>
    <div id=\"contenedor\">
    <div id=\"titulos\"><h1>".$nombre."</h1></div>

here it is where I add the link to the image:

    <div id=\"imagenes\">";
    $html .="
    <div><img src=\"https://maps.googleapis.com/maps/api/staticmap?center=41.088867,1.156965&zoom=15&size=585x300&maptype=roadmap&markers=color:red%7Clabel:C%7C".$latitud.",".$longitud."\" height=\"200\" width=\"350\"/></div>";
    $html .="

The rest of PDF content (shown without problems):

<div><img src=\"imagenes/".$ID.".jpg\" height=\"200\" width=\"350\"></div>
</div>
<div id=\"textos\">
<p>Fecha de inauguración: ".$fecha."</p>
<p>Ubicado en el parque en: ".$nombretipo."</p>
<P>".$descripcion."</P>
</div>
</div>
</body>
</html>";

$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('htmlout.pdf', 'I');
?>
dda
  • 6,030
  • 2
  • 25
  • 34
Kossmo
  • 1
  • 1
  • would these be the same issue? http://stackoverflow.com/questions/2687352/tcpdf-remote-image-loading-problem – kaho Jun 02 '15 at 16:32
  • I think it had to do with XXAMP that by putting it on a web server if you loaded me, thank you very much anyway – Kossmo Jun 04 '15 at 09:52

0 Answers0