Use TCPDF to dynamically create a PDF

Source: Internet
Author: User
Tags php development environment

Introduction: TCPDF is a popular open-source PHP library that helps you create PDF documents. Its flexibility and versatility allow you to create complex color documents with any font and graphic features you need. TCPDF is fully written in PHP and uses all the magic of PDF without any external libraries. This article introduces TCPDF, and then shows you how to copy a simple HTML invoice on a downloadable PDF file.

Introduction

TCPDF is one of the most active projects hosted on Sourceforge.net. It fully implements a powerful PDF generation engine on PHP. This makes it easier to install, even on websites where you cannot access the system directory or compile your own code. In addition, iterative development is easier by allowing you to directly view the results generated by PHP code without any intermediate steps.

TCPDF supports a series of useful image formats, including SVG vector formats and bitmap formats, such as JPEG and PNG. A simple and independent utility allows you to process TrueType, OpenType, PostScript Type 1, and CID-0 fonts so that they can be added to documents created in TCPDF. You can use TCPDF to generate numerous 1-D and 2-D barcode formats, and it supports all common PDF functions, such as bookmarks, document links, compression, comments, document encryption, and digital signatures.

Write TCPDF in PHP and use its pages, which makes it easy to create and deploy Web pages generated by PDF. When you develop and deploy TCPDF using any Web server or your favorite PHP development environment, I will use the following tools:

  • Eclipse V3.5.2-one of my newest open-source development environments, which supports a wide range of programming languages and environments.
  • PHP Development Tools V2.2.0-PHP plug-in for Eclipse.
  • MAMP Pro V1.9-a convenient package for Mac OS X, which provides Apache, MySQL, and PHP in an isolated environment through a useful GUI front-end. Although Mac OS x is installed with Apache and PHP, I still choose to use this tool because it provides a series of stable and easy-to-Separate Web servers/databases/PHP.
  • TCPDF V5.0.006-current stable version of TCPDF.

You can find the download link for all the above tools in the references section.

Download os-tcpdf-CreatingPDFs-Invoice.zip:

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is available in/July 6, 2013,/July 24, September/. You can use TCPDF to dynamically create a PDF file.

For the download method, see

 

If you have installed PHP, let's see how to use TCPDF on your own website. We will check the installation process, and then we will use PHP to generate a Web page showing invoice-style documents that may come from any e-commerce site. Afterwards, we will use TCPDF to create a printable PDF invoice in a similar format.

Install TCPDF

When you download TCPDF from Sourceforge.net, it provides a self-contained ZIP Archive, that is, you can use your favorite ZIP Extraction Tool to decompress the archive, you will eventually get a TCPDF directory containing all the information you need.

If you add the TCPDF directory to your web document directory, you can access the TCPDF document by loading doc/index.html and load examples/index. view any examples in the php file, which can also be found on the TCPDF website (see references ).

However, before you can view the example, You need to configure your TCPDF installation.

Configuration-UNIX-like system

If you are running UNIX-like®When TCPDF is installed on the system, you need to change the file mode because not all of them are marked as executable. In Microsoft®Windows®The system has a side effect of creating a TCPDF archive. Fortunately, it is easy to adjust these in an imbalance from shell (refer to listing 1 ). You also need to ensure that the cache and image directory are writable because TCPDF will store temporary files there.

Next, you need to allocate the file to the user and the web server group. Although this is usually the user www and the Group www, it depends on your system. If you are running TCPDF outside your personal website, (usually public_html in your home directory), skip this step.


Listing 1. Adjusting file mode and ownership

$ cd tcpdf$ find . -type f | xargs chmod -x$ chmod +w cache images$ chown -R www:www .


Note that the command may use.Replace:To separate users and groups on some systems. If there is a problem, check the detailed information of the documents.

Next, let's take a look at the highlights of page 2nd:

  • 1
  • 2
  • 3
  • Next Page

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.