Convert HTML To PDF In PHP With Dompdf Example

03-Apr-2023

.

Admin

Convert HTML To PDF In PHP With Dompdf Example

Hi guys,

Today i will explained how to convert html to pdf in php with using dompdf. This example is so easy to use in php. This example to i am use to dompdf and create html file to pdf view and dowload pdf file using php.

So First dowload to the dompdf generater in your folder.So let's start to the example.

index.php


<?php

require_once 'dompdf/autoload.inc.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();

// Load HTML content

// $dompdf->loadHtml('<h1>Welcome to niceshipest.com</h1>');

// Load html file

$html = file_get_contents("index_pdf.html");

$dompdf->loadHtml($html);

$dompdf->setPaper('A4', 'landscape');

$dompdf->render();

$dompdf->stream("niceshipest", array("Attachment" => 0));

?>

Pdf View

Index_pdf.html

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Convert HTML To PDF In PHP With Dompdf</title>

</head>

<body>

<h1>

Pdf File Generate To Niceshipest.com

</h1>

</body>

</html>

Now you can check your own.

I hope it can help you...

Output :

#PHP 8

#PHP