The full name of PDF is PortableDocumentFormat. it is a portable document format released by Adobe. PDF has a feature unrelated to the operating system, which makes it an ideal document format for electronic document distribution and digital information dissemination on the Internet. Today we will discuss how to use PHP to create PDF documents and use PHP "> <LINKhref ="
The full name of PDF is Portable Document Format. it is a Portable Document Format launched by Adobe. PDF has a feature unrelated to the operating system, which makes it an ideal document format for electronic document distribution and digital information dissemination on the Internet. Today we will discuss how to use PHP to create PDF documents and use PHP to modify PDF files.
To use a PDF file in PHP, we need to use a TCPDF package. a PHP class is used to read PDF files.
Create a PDF file in PHP
You can download the TCPDF package from the link below.
TCPDF-PHP class for PDF: http://sourceforge.net/projects/tcpdf/files/
This is a free and easy-to-use plug-in package. the following example shows how to use the TCPDF package.
Example 1: use PHP to generate a simple PDF document
Require_once ('../config/lang/eng. php'); require_once (' ../tcpdf. php ');
// Create new PDF document
$ Pdf = new TCPDF (pai_page_orientation, pai_unit, pai_page_format, true, 'utf-8', false );
// Set document information
$ Pdf-> SetCreator (pai_creator );
$ Pdf-> SetAuthor ('Nicola Asuni ');
$ Pdf-> SetTitle ('tcpdf Example 002 ');
$ Pdf-> SetSubject ('tcpdf Tutorial ');
$ Pdf-> SetKeywords ('tcpdf, PDF, example, test, Guide ');
// Remove default header/footer
$ Pdf-> setPrintHeader (false );
$ Pdf-> setPrintFooter (false );
// Set default monospaced font
$ Pdf-> setdefamonomonospacedfont (pai_font_monospaced );
// Set margins
$ Pdf-> SetMargins (pai_margin_left, pai_margin_top, pai_margin_right );
// Set auto page breaks
$ Pdf-> SetAutoPageBreak (TRUE, pai_margin_bottom );
// Set image scale factor
$ Pdf-> setImageScale (pai_image_scale_ratio );
// Set some language-dependent strings
$ Pdf-> setmediaagearray ($ l );
//---------------------------------------------------------
// Set font
$ Pdf-> SetFont ('Times ', 'bi', 20 );
// Add a page
$ Pdf-> AddPage ();
// Print a line using Cell ()
$ Pdf-> Cell (0, 10, 'example 002', 1, 1, 'C ');
//---------------------------------------------------------
// Close and output PDF document
$ Pdf-> Output('example_002.pdf ',' I ');?>