PHP 7 HTML2PDF Library Script to Convert Raw HTML to Dynamic PDF Document in Browser Full Project For Beginners

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

 

 

Step 1 – Install HTML2PDF

 

 

composer require spipu/html2pdf

 

 

Require the Package inside Code

 

 

use Spipu\Html2Pdf\Html2Pdf;

 

 

index.php

 

 

$html2pdf = new Html2Pdf();
$html2pdf->writeHTML('<h1 style="color:pink;">CodeWall PDF</h1> <br/> <p>Convert this HTML to PDF please!</p>');
$html2pdf->output('myPdf.pdf); // Generate and load the PDF in the browser.

// $html2pdf->output('myPdf.pdf, 'D'); // Generate the PDF execution and force download immediately.

 

 

Html2Pdf

Html2Pdf is a HTML to PDF converter written in PHP, and compatible with PHP 5.6 to 7.4.

It allows the conversion of valid HTML in PDF format, to generate documents like invoices, documentation, …

You have to write a code of HTML for Html2Pdf, and not try to convert directly an already existing html page.

Specific tags have been implemented, to adapt the html standard to a PDF usage.

You must use Composer to install this library.

It uses TCPDF for the PDF part.

Requirements

Html2Pdf works with PHP >5.6 and Composer.

You will also need at least the following php extensions:

  • gd
  • mbstring

Documentation

You will find the install documentation here.

You will find all the documentation here.

You will find lots of examples here.

Leave a Reply