how to convert dynamic contents of html page to pd

2019-05-10 19:17发布

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.

标签: php pdf dompdf
4条回答
够拽才男人
2楼-- · 2019-05-10 19:38

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/

查看更多
欢心
3楼-- · 2019-05-10 19:42

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.

查看更多
狗以群分
4楼-- · 2019-05-10 19:47

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

查看更多
男人必须洒脱
5楼-- · 2019-05-10 19:54

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!

查看更多
登录 后发表回答