Teach you how to use PHP to generate PDF files online

Source: Internet
Author: User
Tags american time define manual pdflib php class require

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 you can go down to the latest version of Windows:
Http://www.fpdf.org/en/dl.php?v=152&f=zip

Here you can go to the Chinese manual:
http://www.fpdf.org/en/dl.php?id=72

For other versions you can come down here:
http://www.fpdf.org/
This is also the official website of Fpdf, if have the question to ask above, reply very fast, I asked 1 questions in the morning they will be back in the afternoon. But all that time was American time.

Here is a very simple example of creating a PDF file with fpdf and adding a page

The following are the referenced contents:
?
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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.