Web Development

How to convert html to Pdf using Dompdf in PHP

DOMPDF is convert HTML to PDF. You can download the latest version of Dompdf from 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");
View Demo
Download Source Code(How to convert html to Pdf using Dompdf in PHP)
Size: 3.66 MB
Version: V 1.0

Recommended Tutorials for you


Related posts

How to prevent Cross-Site Request Forgery (CSRF) in PHP

Anuj Kumar

How to maintain the password history using php and mysql

Anuj Kumar

How to Salt & Hash a Password using Sha256

Anuj Kumar

How to get Current Indian time in PHP

Anuj Kumar

PHP Email Verification Script

Anuj Kumar

How to get current page URL in php

Anuj Kumar

How to Generate PDF from MySQL Data using PHP

Anuj Kumar

How to delete multiple records in PHP

Anuj Kumar

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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