how to convert dynamic php file to pdf?
-
I try to convert dynamic php database file to pdf. I try with DOMPDF, but I have a problem with defining the string. I'll explain: Here is a 'hello world' script for dompdf: require_once("dompdf_config.inc.php"); $html = '<html><body>'. '<p>Hello World!</p>'. '</body></html>'; $dompdf = new DOMPDF(); $dompdf->load_html($html); $dompdf->render(); $dompdf->stream("hello_world.pdf"); The thing is that instead of a simple '<html><body>'. '<p>Hello World!</p>'. '</body></html>' I have a long php file full of functions and sql queries. because of it I have inside it many ",',; e.t.c signs. I also have a javascript dynamic chart (jqplot) in this page. So instead of pdf file I get errors errors errors... Does anyone has a solution for this? I will really appreciate any answer, and will be really really thankful for a solution...
-
Answer:
You can use ob_start and ob_get_contents to run PHP code and capture the output as a string. For the JavaScript chart, though, you're out of luck. DOMPDF is pretty smart, but it's not that smart. You'll need to either use a non-JavaScript chart solution, do without the charts, or use a web browser to generate the PDF.
AnnaVas at Stack Overflow Visit the source
Other answers
First you'll need to generate HTML from your PHP, then pass it to DOMPDF: <?php require_once("dompdf_config.inc.php"); ob_start(); require_once("path/to/input/file.php"); $dompdf = new DOMPDF(); $dompdf->load_html(ob_get_clean()); $dompdf->render(); $dompdf->stream("file.pdf"); ?> You can also do a regular HTTP request: <?php require_once("dompdf_config.inc.php"); $dompdf = new DOMPDF(); $dompdf->load_html_file('http://example.com/file.php'); $dompdf->render(); $dompdf->stream("file.pdf"); ?> If you need JavaScript support, try http://code.google.com/p/wkhtmltopdf/, it's based on Webkit and does it's work perfectly.
Paker
I am not sure why you need to generate HTML to build a PDF in the first place but as others have suggested, build out your PHP script and then use something like http://www.fpdf.org or http://www.tcpdf.org. They both build PDFs just fine and can take HTML input.
JM4
Related Q & A:
- How To Convert Online Pagemaker File To Pdf?Best solution by Yahoo! Answers
- How to use external PHP file in СakePHP 2?Best solution by Stack Overflow
- How to convert a HTML file to XML file?Best solution by Stack Overflow
- How to create dynamic php pages?Best solution by Stack Overflow
- How to convert Matlab .m file to C code?Best solution by mathworks.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.