One of the biggest advantages of PHP is its ease of support for new technologies, the scalability of which allows developers to easily add new modules, and the support of the world's technology community and the support of numerous extension modules makes PHP one of the most full-featured Web programming languages. Currently available expansion modules enable developers to perform IMAP and POP3 operations, dynamically generating images and Shockwave Flash animations, credit card verification, encrypted decryption of sensitive data, and the ability to parse XML-formatted data. But that's not all, and now there's a new module that can be bundled with PHP, which is the Pdflib extension module, which enables developers to dynamically generate files in the PDF (Adobe Portable Document Format) format. Let's take a look at how to use this module in PHP.
In order to enable PHP to have the ability to manipulate PDF documents, you must first install the Pdflib extension Library in your system, if you are using a LUnix system, you can start from http://www.pdflib.com/pdflib/ index.html download A and compile, if you are using the Windows system, it is easier, just download a compiled Pdflib library, and then in the PHP configuration file to the corresponding line comments removed.
Extension=php_pdf.dll
If you are loading dynamically, you can also refer to the following command:
DL ("Php_pdf.dll");
In addition, you must also have an Adobe Acrobat PDF reader, which is used to browse the PDF format, and if you do not, you can download it from http://www.adobe.com/free of charge.
Once you have made the preliminary preparation, you can create a PDF file, the following is a simple example:
<?php
Create a new PDF document handle
$pdf = Pdf_new ();
Open a file
Pdf_open_file ($pdf, "pdftest.pdf");
Start a new page (A4)
Pdf_begin_page ($pdf, 595, 842);
Get and use font objects
$arial = Pdf_findfont ($pdf, "Arial", "Host", 1);
Pdf_setfont ($pdf, $arial, 10);
Output text
Pdf_show_xy ($pdf, "This is a exam of PDF Documents, It is a good Lib,", 50, 750);
Pdf_show_xy ($pdf, "If you like,please try yourself!", 50, 730);
End one page
Pdf_end_page ($pdf);
Close and save a file
Pdf_close ($pdf);
?>
Then save it as a PHP file, browse in the browser, PHP will execute the above code, it produces a new PDF file, and saved to the specified location.
Now we analyze what code to use PHP to create a PDF file, there are four steps: 1, create a document handle; 2, register the font and color of the document; 3, write text or paint to the file handle with the function provided by Pdflib; 4, save the document.