Use PHP to create and modify PDF documents

Source: Internet
Author: User
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 ');?>

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.