0

I want to convert html to PDF using PHP or javascript. i have a html having text and image both. I have tried using html2PDF but facing problem in image. if i am using relative path then it is not allow to create PDF and throw error about not found image and using absolute path it is not displaying images in my web view. so any one have solution for it? and is there any other solution convert html to PDF or image?

need to create more than 1 page in PDF and also create all those pages images

Nitin
  • 881
  • 2
  • 10
  • 37
  • 1
    Look For `HTML 2 PDF` its free http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php?rq=1 – Noman Jan 26 '16 at 07:20
  • Use FPDF, i used it once http://www.fpdf.org/ – Faisal Ashfaq Jan 26 '16 at 07:21
  • Prefer using DOMPDF - [link](https://github.com/dompdf/dompdf). Have a look at its documentations. Its pretty easy to use and images work perfectly fine in this. – prateekkathal Jan 26 '16 at 07:24
  • I have used TCPDF to create PDF from HTML.. i have array of html content .. i want to put one full html in one page of pdf.. if i setting auto-page break true then after its limit content is not displaying else if it will create multiple pages for html so how it is possible?? – Nitin Feb 02 '16 at 06:43

2 Answers2

0

You have to create an HTML or PHP file with the contents of the table and and link that opens the PDF

<table width="500px" cellpadding="5px" cellspacing="5px" border="1">
    <tr bgcolor="#CCCCCC">
        <td>Nombre</td>
        <td>Apellido</td>
        <td>Email</td>
        <td>Edad</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Antonio</td>
        <td>López</td>
        <td>alopez@gmail.com</td>
        <td>25</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Sergio</td>
        <td>Martínez</td>
        <td>sgm@gmail.com</td>
        <td>47</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Natalia</td>
        <td>Estrada</td>
        <td>natty@gmail.com</td>
        <td>22</td>
    </tr>
</table>
<p><a href="pdf.php">Ver tabla en PDF</a></p>




**Now only missing the key issue , the content of pdf.php file :**

<?php ob_start(); ?>
<h2>Lista de usuarios</h2>
<table width="500px" cellpadding="5px" cellspacing="5px" border="1">
    <tr bgcolor="#CCCCCC">
        <td>Nombre</td>
        <td>Apellido</td>
        <td>Email</td>
        <td>Edad</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Antonio</td>
        <td>López</td>
        <td>alopez@gmail.com</td>
        <td>25</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Sergio</td>
        <td>Martínez</td>
        <td>sgm@gmail.com</td>
        <td>47</td>
    </tr>
    <tr bgcolor="#FF9933">
        <td>Natalia</td>
        <td>Estrada</td>
        <td>natty@gmail.com</td>
        <td>22</td>
    </tr>
</table>
<?php
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html(ob_get_clean());
$dompdf->render();
$pdf = $dompdf->output();
$filename = "ejemplo".time().'.pdf';
file_put_contents($filename, $pdf);
$dompdf->stream($filename);
?>

I Hope this can help you

bathyscapher
  • 1,615
  • 1
  • 13
  • 18
0

There are several programs to html with php which always have small errors, if you convert pdf to html and php could prove "wkhtmltopdf" or "DOMPDF" aunq can give you errors tables Which one is the best PDF-API for PHP? here are the best converters

Community
  • 1
  • 1
maikgreus
  • 1
  • 1
  • i have used TCPDF and it has some problem for display images.. for that i have changed in its library for the same.. and working fine.. but i have issue having i have multiple pages and it should like every page will display in single page in pdf for ex.. if i have 5 pages then pdf has 5 pages and every page should have same contain as HTML.. for that any idea? – Nitin Jan 28 '16 at 06:09