PHPGurukul

How to convert html to Pdf using Dompdf in PHP

GitHub. Step 1: Reference the namespace of Dompdf

namespace Dompdf;
Step 2: include Dompdf library
require_once 'dompdf/autoload.inc.php';
Step 3: Initiate the Dompdf class
$dompdf = new Dompdf();

Basic Parameters

Load HTML content
$dompdf->loadHtml('<h1>PHPGURUKUL | Programming Blog </h1>');
loadhtml() use to generate PDF and render on browser. Set the paper size. This is optional.
$dompdf->setPaper('A4', 'landscape');
setPaper()– $size(string)— ‘legal’,’letter’,’A4′ $orientation(string) — ‘portrait’ or ‘landscape’. Render to HTML to PDF
$dompdf->render();
For view the PDF
$dompdf->stream("",array("Attachment" => false));
For download the PDF
$dompdf->stream("sample.pdf");
[mks_button size="medium" title="View Demo" style="squared" url="https://phpgurukul.com/demos/dompdf/" target="_blank" bg_color="#dd3333" txt_color="#FFFFFF" icon="fa-play" icon_type="fa" nofollow="0"] [sdm_download id="7152" fancy="1" show_size="1" show_version="1"]]]>

Anuj Kumar

This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others.
I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials.
.

Recommended Tutorials for you


Add comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.