Helo Readers,
If you want to convert the HTML to PDF read the below code:
When we do this first of all we require the fpdf library file which can be downloaded from the official site of FPDF.
After download it, Just copy the folder into your directory and customize it according to your need.
After that make te HTML page as per as your need, here we make a simple HTML form to get some user input data for PDF. When user input the data and submit it generate the pdf with this input data.
<pre><html>
<head>
<title>Convert HTML file into PDF in PHP</title>
</head>
<body>
<div class="">
<form class="" action="pdf.php" method="post">
<input type="text" class="" name="name" placeholder="Name">
<input type="text" class="" name="email" placeholder="Email">
<textarea name="comment" class="" rows="4" cols="8" placeholder="Comment"></textarea>
<button type="submit" class="">Submit</button>
<button type="button" class="">Cancel</button>
</form>
</div>
</body>
</html></pre>
<p>Then we make the pdf.php file where the above HTML form post</p>
<pre>
require('WriteHTML.php');
$pdf=new PDF_HTML();
$pdf->AliasNbPages();
$pdf->SetAutoPageBreak(true, 11);
$pdf->AddPage();
$pdf->Image('logo.png',18,13,33);
$pdf->SetFont('Arial','B',14);
$pdf->WriteHTML('<para><h1></h1>');
$pdf->SetFont('Arial','B',7);
$htmlTable='<TABLE>
<TR>
<TD>Name:</TD>
<TD>'.$_POST['name'].'</TD>
</TR>
<TR>
<TD>Email:</TD>
<TD>'.$_POST['email'].'</TD>
</TR>
<TR>
<TD>Comment:</TD>
<TD>'.$_POST['comment'].'</TD>
</TR>
</TABLE>';
$pdf->WriteHTML2("<br><br><br>$htmlTable");
$pdf->SetFont('Arial','B',6);
$pdf->Output();
</pre>
1 Comment(s)