ලේසියෙන්ම හොයාගන්න මෙතනින්

Generate Reports in PHP

You may need to generate reports based on your data retrieved from database. Here I will show how you can do it easily and free. I m using a library called FPDF.
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

FPDF has other advantages: high level functions. Here is a list of its main features:

  • Choice of measure unit, page format and margins
  • Page header and footer management
  • Automatic page break
  • Automatic line break and text justification
  • Image support (JPEG, PNG and GIF)
  • Colors
  • Links
  • TrueType, Type1 and encoding support
  • Page compressing 
You can download this library. Click Here.

Put fpdf.php library file into controller or whereever appropriate. And keep the fonts folder, in the same folder where fpdf.php located. Because it needs some font types.
Now go to your one of php files and insert this code. Please Note, you need to change fpdf.php file location in this code, to refer file you placed.
<?php require('fpdf.php'); 
 $pdf = new FPDF();  
 $pdf->AddPage();  
 $pdf->SetFont('Arial','B',16); 
 $pdf->Cell(40,10,'Hello World!'); 
 $pdf->Output();  
?>


To Set Page Format, Page Size,

$pdf = new FPDF('P','mm','A4');

References - http://www.fpdf.org/


No comments :

Post a Comment