PHP Script to create PDF document using FPDF

Download FPDF from here.
http://www.fpdf.org
Keep the fpdf.php file in your working directory, keep the font directory in the same place.

Run this code , you are ready with your first pdf file created from FPDF class.
<?Php
require('fpdf.php');
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(80,10,'Hello World!',1,0,R,true,'http://www.plus2net.com');
$pdf->Output('my_file.pdf','D'); // Force download to user machine as my_file.pdf
?>
In the above code we have used cell to add our text to the pdf file. We have just added one line 'Hello World' and created the pdf file. Here is the details of Cell Cell for creating pdf document
Try to change the script by adding backgroud color like this.
$pdf->SetFillColor(193,229,252);
$pdf->Cell(80,10,'Hello World!',1,0,R,true,'http://www.plus2net.com');
$pdf->Output('my_file.pdf','D'); 
We used $pdf->Output('my_file','D') to get output directly. This line will force download to user machine the pdf file my_file.pdf. We can change this to save the file in local ( server ) side machine.
$pdf->Output('my_file.pdf','F'); // Saved at local ( server side )  as my_file.pdf
//$pdf->Output('my_file.pdf','I'); // Send to browser and displayed wiht the plugin, file can be saved using  set file name. 
//$pdf->Output('my_file.pdf','S'); // Output as sting , file name is ignored.  

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Visitors Rating
Your Rating


Google+

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer