What is FPDF?
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. The advantage is that PDFlib requires a fee for a commercial usage. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
FPDF allows us to create pdf files without having to call PDFlib
here You can download the latest version under Windows:
http://www.fpdf.org/en/dl.php?v=152&f=zip
You can download the Chinese manual here:
http://www.fpdf.org/en/dl.php?id=72
If you want other versions, you can download it here:
http://www.fpdf.org /
This is also the official website of FPDF. If you have any questions, you can ask them there. The replies are very fast. I asked a question in the morning and they responded in the afternoon. But the times above are all American time.
The following is a very simple example of using FPDF to create a pdf file and add 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() includes open( ), he completed the two steps of creating a new pdf file and adding 1 page at the same time
In the above example, define('FPDF_FONTPATH','fpdf152/font/'); defines the directory where font files are stored
After downloading the compressed package, you will see the font folder, just point to that folder
The above program cannot display anything yet
Now let’s add a few 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() to set the font. This step must be done when calling FPDF for the first time, otherwise you will be prompted when the pdf file is opened. "No font defined" and nothing is displayed
It is best to define more commonly used fonts here, and Chinese is not supported.
To support Chinese or more biased fonts, you need to use AddFont(), but I failed the test for the time being. I hope someone who has passed it can give me some advice^^
Text() prints a string, the abscissa is 5. The ordinate is 20, and the string content is "test pdf"
Regarding the parameter 'D' in the final Output(), you can refer to the manual, it is written very clearly
The pdf file exported in this way will 'test pdf' is displayed.
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 pictures into pdf, preceded by the file name, including the path, 5 is the abscissa, 30 is the ordinate, 60 is the image width, 50 is the height
ok, so a pdf file with both text and pictures is created^^
In fact, there are many functions, which are written in the manual, but they are not very detailed. You need to research and discover them by yourself. ^^