Computing Magazine

Export HTML to PDF

Posted on the 25 May 2012 by Akahgy


Export a HTML page to PDF in PhP


The best solution is installing a 3rd party tool like wkhtmltopdf . The tool is easy to install on Windows, but a bit more tricky on a Linux machine.

The tool works by running  the wkhtmltopdf command and adding the path to the command line:

$htmlfile = ‘index’.  time() . ‘.html’;
file_put_contents( $htmlfile, ‘<html>content</html>’);
exec(‘wkhtmltopdf “‘. $htmlfile .’” “html2pdf.pdf”‘);

The tool can also be used from command line, in the same way.

Back to Featured Articles on Logo Paperblog