PHP PDF Generate tutorial
Here is the tutorial for
php pdf creation.
For this you need to download a file called
fpdf.php
Basic Code to generate pdf in php
|
require("fpdf.php");
$pdf = new FPDF( );
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,10,'PHP - The Good Parts!');
$pdf->Output();
|
Take a look at the code, First you need to include the fpdf.php file using
require() function.
after requiring the library file, we instantiate an object of the FPDF class and call it $pdf.
Then we add a page with the AddPage method, set our output font,
define the cell (location) for our string of output, and then—using the
Output method—display the PDF in the browser.
Output for the above code will be
PHP PDF generate using cell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
require("fpdf.php");
$pdf = new FPDF( );
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(10,10,'PHP - The Good Parts!', 0,0,'L');
$pdf->SetX(90);
$pdf->Cell(90,10,'Beware the Ides of March!', 1,0,'C');
$pdf->Output();
|
In the above code we’ve used cell method.
For the first text “PHP – The Good Parts!” we’ve given x=10 and y=10
and 0,0,’L’ denotes column, row and text alignment respectively.
So the output will be
NOTE:
You may want to disable your browser’s caching capabilities while you
are developing and testing the layout of your FPDF PDFs because some
browsers will not reload the page with changes if the changes are so
small that they don’t register as such with the cache control.
Attachments
1)
FPDF.php
0 comments:
Post a Comment