如何使用html2pdf库以pdf格式显示mysql中的图像

时间:2014-05-28 15:33:14

标签: php mysql pdf html2pdf

我想使用HTML2PDF库创建PDF。我想用PDF格式显示来自MySQL的图像,但它不起作用。在这里我的代码:

<?php
include "../koneksi.php";
$tanggal = date('d/m/Y');
$sql = mysql_query("SELECT brg_stok.id_brg, brg_stok.kd_brg, brg_stok.barang, kategori.nama_kategori, brg_stok.harga, brg_stok.stok, brg_stok.gambar, brg_stok.dimensi, brg_stok.status FROM brg_stok LEFT JOIN kategori ON brg_stok.id_kategori=kategori.id_kategori ORDER BY brg_stok.kd_brg"); 

&GT;

<?php
    $i = 1;
    while($baris = mysql_fetch_array($sql)) {
        echo "<tr>";                                    
        echo "<td style='text-align: center; '>".$i.".</td>"; 
        echo "<td style='text-align: center; '>".$baris['kd_brg']."</td>"; 
        echo "<td>".$baris['barang']."</td>";
        echo "<td style='text-align: center; '>".$baris['nama_kategori']."</td>";
        echo "<td>Rp.  ".$baris['harga']."</td>";
        echo "<td style='text-align: center; '>".$baris['stok']."</td>";
            //here's the problem
        echo "<td>";
            echo '<img src="../'.$baris['image'].'" alt="'.$baris['barang'].'" title="'.$baris['barang'].' "width="100" height="100" />';
        echo "</td>";

        echo "<td>".$baris['dimensi']."</td>";
        echo "<td>".$baris['status']."</td>";
        echo "</tr>";
        $i++;
    }

&GT;

<? $content = ob_get_clean(); 
   $content = '<page style="font-family: freeserif">'.nl2br($content).'</page>';
   require_once('libraries/pdf/html2pdf.class.php');
   try
   {
    $html2pdf = new HTML2PDF('L','A4','en', false, 'ISO-8859-15',array(20, 10, 20, 0));
    $html2pdf->setDefaultFont('Arial');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output($filename);
   }
   catch(HTML2PDF_exception $e) { echo $e; }
 ?>

这里出现错误: http://i60.tinypic.com/16iy4ub.png 输出不是pdf格式

请任何人帮忙,谢谢!

0 个答案:

没有答案