What is FPDF?
FPDF is a PHP class which allows to generate PDF files with pure PHP, which is to say without using the Pdflib library. The advantage is this pdflib requires a fee for a commercial usage. F from FPDF stands for free:you The IT for any kind the usage and modify it to suit your.
Fpdf allows us to create PDF files without having to call Pdflib
Here is a very simple example of creating a PDF file with fpdf and adding a page
?
Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/fpdf.php ');
$pdf = new FPDF;
$pdf->addpage ();
$pdf->output (' a.pdf ', ' D ');
?>
Of course, you can also use $pdf->open () to create a new PDF file
But here, AddPage () contains open (), and he completes a new PDF file and adds 1 pages two steps
The Define (' Fpdf_fontpath ', ' fpdf152/font/') in the example above, defines the directory where the font files are stored
After downloading the compressed package, you will see the font folder, just point to that folder on the line
The above program doesn't show anything yet.
Now let's add two sentences.
?
Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/fpdf.php ');
$pdf = new FPDF;
$pdf->addpage ();
$pdf->setfont (' Arial ');
$pdf->text (5,20, ' Test pdf ');
$pdf->output (' a.pdf ', ' D ');
?>
SetFont () Set the font, this step in the 1th time to call fpdf must be, otherwise the PDF file will be prompted when open "no font" and nothing displayed
It is best to define a more commonly used font, and Chinese does not support it.
To support Chinese or more biased font to use the AddFont (), but I did not pass the test, I hope that the pass can be pointed ^^
Text () prints a string with a horizontal coordinate of 5 and an ordinate of 20, with the string content "test PDF"
The parameter ' D ' in the final output () can be referenced in the manual, which is clearly written.
The exported PDF file will display ' Test PDF '.
If you are interested, add a picture.
?
Define (' Fpdf_fontpath ', ' fpdf152/font/');
Require (' fpdf152/fpdf.php ');
$pdf = new FPDF;
$pdf->addpage ();
$pdf->setfont (' Arial ');
$pdf->text (5,20, ' Test pdf ');
$pdf->image (' jianxin_mark.jpg ', 5, 30, 60, 50);
$pdf->output (' a.pdf ', ' D ');
?>
Image () can insert a picture in the PDF, preceded by the filename, to include the path, 5 is the horizontal axis, 30 is the ordinate, 60 is the picture width, 50 is the height
OK, so a PDF file with text and pictures is established ^^
In fact, there are many functions, manuals are written, but not very detailed, you need to explore their own ^^