Export HTML to PDF


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.

About admin

Just another php developer trying to give something back to the community.
This entry was posted in PhP, Tools and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s