PHP on dompdf

179 views
Skip to first unread message

Kamilo Vasquez Caro

unread,
Aug 6, 2013, 3:07:14 PM8/6/13
to dom...@googlegroups.com
Hi i'm new user of dompdf, i'm currently working with tcpdf but is too har to handless so the realquestion is how i can render php code with dompdf

BrianS

unread,
Aug 13, 2013, 9:18:07 PM8/13/13
to dom...@googlegroups.com
dompdf basically acts like a web browser (minus the JS support) that renders a HTML page to PDF. So what you typically want to do is completely generate your HTML document first and then pass that to dompdf for PDF rendering.

The actual steps for generating the PDF once you have the HTML are pretty simple. Let's say you have created your HTML in the script that will also render the PDF. You would do something like this:

<?php
/* lots of code above that creates the HTML document and stores it in the $html variable */
$dompdf = new DOMPDF;
$dompdf->load_html( $html );
$dompdf->render( );
$dompdf->stream( );
?>

Done.

Or let's say you have an external file that already creates your HTML. You can reference that file from within another script that uses dompdf to create the PDF. For example:

<?php
$dompdf = new DOMPDF;
$dompdf->load_html_file( 'http://example.com/some_document.php' );
$dompdf->render( );
$dompdf->stream( );
?>

Done. And that's all there is to it.

There are a lot of things you can do with the underlying rendering engine (CPDF or PDFLib), but you should focus first on understanding how to use dompdf.
Reply all
Reply to author
Forward
0 new messages