Thursday, August 25, 2016

How to convert PDF file using HTML and CSS with watermark in php

Hi , I am really happy to share which I have found one of the library  to  create PDF file as per design it nice and easily integrate using PHP.

Step1. download the library from github then extract it and paste into http://localhost/mpdf (xampp/htdoc/mpdf).

Step2. Create a generatepdf.php file within mpdf folder and paste the below code like

 Step3. include the library class mPDF

require(mpdf.php");
$img = 'phptechnicalgroupLogo.png';

$html = '<style>
table { border-collapse: collapse; margin-top: 0; text-align: center; }
td { padding: 0.5em; }
h1 { margin-bottom: 0; }z
</style>


<table border="0" cellspacing="0" cellpadding="0" width="100">
<tr>
<td><img style="vertical-align: top" src="'.$img.'" width="300" /></td><td></td><td></td>
</tr>

</table>



<table border="0" cellspacing="0" cellpadding="0" width="90%" align="center">
<tr>
<td style="text-align:center;width:100%;" style="padding-top:100px;padding-bottom:10px;"><h2><u>Candidate Profile Details</u></h2></td>
</tr>
<tr>
<td style="width:100%;vertical-align:top;padding-left:130px;">
<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">

<TR>
<TD  style="text-align:left;width:45%;font-face:verdana;font-size:14px;"><b>First Name</b></TD>
<TD  style="text-align:center;width:5%;font-face:verdana;font-size:14px;"><b>:</b></TD>
<TD  style="text-align:left;width:50%;font-face:verdana;font-size:14px;">Bikash ranjan</TD>
</TR>
<TR>
<TD style="text-align:left;font-face:verdana;font-size:14px;"><b>Last Name</TD>
<TD  style="text-align:center;font-face:verdana;font-size:14px;"><b>:</b></TD>
<TD  style="text-align:left;font-face:verdana;font-size:14px;">nayak</b></TD>
</TR>
<TR>
<TD style="text-align:left;font-face:verdana;font-size:14px;"><b>Position Title</TD>
<TD  style="text-align:center;font-face:verdana;font-size:14px;"><b>:</b></TD>
<TD  style="text-align:left;font-face:verdana;font-size:14px;">role</TD>
</TR><TR>
<TD style="text-align:left;font-face:verdana;font-size:14px;"><b>Candidate Total Experience</TD>
<TD  style="text-align:center;font-face:verdana;font-size:14px;"><b>:</b></TD>
<TD  style="text-align:left;font-face:verdana;font-size:14px;">2 Month</b></TD>
</TR>
<TR>
<TD style="text-align:left;font-face:verdana;font-size:14px;"><b>Candidates Relevant Experience</TD>
<TD  style="text-align:center;font-face:verdana;font-size:14px;"><b>:</b></TD>
</tr>
</TABLE>
</td>
</tr></table>';
##################CREATE AN OBJECT OF mPDF class#################
$mpdf=new mPDF('c');
$mpdf->WriteHTML($html);

//call watermark content aand image
$mpdf->SetWatermarkText('TALENDRONE.COM');
$mpdf->showWatermarkText = true;
$mpdf->watermarkTextAlpha = 0.1;


//save the file put which location you need folder/filname
$mpdf->Output("bikashprofile.pdf", 'F');


//out put in browser below output function
//$mpdf->Output();


Output in New PDF file



No comments:

Post a Comment