Skip to content Skip to sidebar Skip to footer

Converting Html In Php File To Pdf File

I have a php file which queries a database and then writes and updates the html accordingly. I have a button on this page 'Export As PDF'..I am trying to convert this page to a pd

Solution 1:

I recently done this by using TCPDF. TCPDF is a further developed version of FPDF.

See this link for an expample regarding converting to PDF. Also, here you can find more examples. Example 61 could also come in quite handy.

Sample code which TCPDF uses:

$html= '<h1>HTMLExample</h1>
<div style="text-align:center">IMAGES<br />
<img src="../images/logo_example.png" alt="test alt attribute" width="100" height="100" border="0"/><img src="../images/tiger.ai" alt="test alt attribute" width="100" height="100" border="0"/><img src="../images/logo_example.jpg" alt="test alt attribute" width="100" height="100" border="0"/></div>';

// output the HTML content$pdf->writeHTML($html, true, false, true, false, '');

Solution 2:

One thing that you could do is run the PHP file, but use output buffering to capture the contents that the PHP script is writing out. Then, save those contents to an .html file and pass that file to the converter.

Solution 3:

The php file you are supplying has to run through a parser before it's valid html code.

$content = file_get_contents( $filename ); //shorter than what you did
ob_start();
echo$content;
$pdf->WriteHTML( ob_get_contents() );
ob_end_clean();

Post a Comment for "Converting Html In Php File To Pdf File"