how to convert dynamic contents of html page to pdf

隐身守侯 提交于 2019-12-07 17:04:06

问题


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.



来源:https://stackoverflow.com/questions/9825433/how-to-convert-dynamic-contents-of-html-page-to-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!