-->

how to convert dynamic contents of html page to pd

2019-05-10 19:23发布

问题:

In html page some tags are dynamically created using jquery and contents are loaded from msql db using jquery and php. I want convert this dynamic page to pdf. I have tried following code but it generate pdf of static part of html page.

<?php
    ob_start();
?>
//html code and internal css, javascript used in external file with jquery library
<?php
  include('dompdf/dompdf_config.inc.php');
  $contents = ob_get_contents();
  ob_end_clean();
  $dompdf = new DOMPDF();
  $dompdf->load_html($contents);
  $dompdf->render();
  $dompdf->stream('file.pdf'); 
?>

So how to store contents of dynamic html page in a php variable after processing it ( using javascript/php ) and convert it to pdf usin dompdf or other converter.

回答1:

I'd suggest you take a look at wkhtmltopdf. I've had good results with getting it to render google charts, which are built dynamically from a javascript api.

http://code.google.com/p/wkhtmltopdf/



回答2:

As Marc said, you have to read generated DOM with javascript.. something like $('html').html() and then post it to php to generate pdf



回答3:

This may not meet exactly what you are looking for, but wkhtmltopdf could be what you need. Since PHP is a server-side technology, you will have a difficult time getting it to process any client-side javascript. wkhtmltopdf scans the page, javascript and all, then generates a pdf file on the server. Hope this helps you out!



回答4:

Consider using a tool like wkhtmltopdf to directly generate a page as a PDF. It will run javascript and generate the page as WebKit would render it.



标签: php pdf dompdf