PHP 7 DomPDF Library Script to Generate PDF Document From HTML Template in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments


Welcome folks today in this blog post we will be generating pdf document from html template using dompdf library in browser using php 7 . All the full source code of the application is shown below.




Get Started




In order to get started you need to make an index.php file and copy paste the following code







<!DOCTYPE html>
  <title>PDF Create</title>
  <style type="text/css">
    th, td {
      border: solid 1px #777;
      padding: 2px;
      margin: 2px;

<img src="1.jpg">
    <th>Phone Number</th>
    <td>Faruque Ahamed Mollick</td>
    <td>Ansaruddin SK</td>
    <td>Mintu SK</td>
    <td>Dewan Ukil</td>
    <td>Aryan Khan</td>
    <td>Arijit Singh</td>





Now create a index.php file which will create the pdf document from the above template using dompdf library as shown below

See also  PHP 7 Script to Build a Login Form Using HTML5 and MySQL Database in Browser Full Project For Beginners







  require_once 'dompdf/lib/html5lib/Parser.php';
  require_once 'dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
  require_once 'dompdf/lib/php-svg-lib/src/autoload.php';
  require_once 'dompdf/src/Autoloader.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml( file_get_contents('test.html') );

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


// View PDF on browser instead of download
$dompdf->stream("dompdf_outFRK.pdf", array("Attachment" => false));


Leave a Reply