Thursday 7 June 2012

Printable certificate of course completion

I worked on the Moodle plugin CertificatesWall to add feature to make printable certificate of course completion.
To make the printable certificate it was needed to convert the image to PDF.
As the plugin is written with PHP it was needed to get PHP library that allows to generate PDF from an image.

And i have found very good library FPDF

The code is simple.

$imgfile='...'; //source image file
$destfile='...';  //final destination file


require(SITE_DIR.'include/fpdf/fpdf.php');
$pdf = new FPDF('L','mm','A4'); //set output format size
$pdf->SetTitle($title);   //set title of the page
$pdf->SetTopMargin(0);  //disable white spaces
$pdf->SetLeftMargin(0);
$pdf->AddPage();  

$dpi=getImageOptimalDPIForWidth($imgfile,297,210);   //this is my function to get optimal dpi
                                                                                            //to get image fill all page
$pdf->Image($imgfile,0,0,-$dpi);  //add image to the page
$pdf->Output($destfile,'F');           //output PDF file



No comments:

Post a Comment