Convert HTML to PDF using PHP code (HTML2FPDF Class library)
In web development, you often need to create PDF (Portable Document Format) to view or download/ print a document.
Here is a simple class that will provide you a simple way to do create PDF.HTML2FPDF Class library consist of three classes namely PDF, HTML2FPDF and FPDF (modified FPDF class). The class PDF extends the class HTML2FPDF that extends the class FPDF.
Convert a sample html page into a PDF file using HTML2FPDF Library by following below simple steps.
$fp = fopen("scriptarticle-sample.html","r");
$strContent = fread($fp, filesize("scriptarticle-sample.html"));
echo "PDF file has been generated successfully!";
The HTML2FPDF class library will work best with the XHTML 1.0.
Download the full code by the link below.