- Create a new php file using any IDE of your choice ( Netbeans,Dreamweaver etc)
- Write the following code inside the file.
- Save in htdocs folder under XAMP.
- Run the file by entering “Localhost” in the browser.
- Download “fpdf” library from www.fpdf.org
- Unzip the library files in to the directory where your php file is located.
Write the following code into the php file.
require('./fpdf182/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'New Pdf file created.');
$pdf->Output();
Run the code, you can find a new pdf file created. You can save the file if you need, or take a print out. Here inside the brackets of “require” give the address of fpdf file which will be inside the downloaded library. Here I placed the files inside “fpdf182” directory.
In $pdf->SetFont('Arial','B',16);
You can set the font of the text which is to be written inside the pdf.
In $pdf->Cell(40,10,'New Pdf file created.');
40 and 10 is the position of the text and “New Pdf file created.” Is the text which is to be written inside the file.