Team LiB
Previous Section Next Section

Chapter 28. Printable Document Generation


Although PHP has many uses both from the terminal through the command-line interface as well as from the Web, its primary purpose is as a dynamic document-generation language. In most cases, PHP is used to generate markup languages such as HTML or XML; however, this chapter focuses on the other types of documents that can be generated using PHPnamely Rich Text Format (RTF) and Portable Document Format (PDF) documents.

The first question that must be asked is simple: Why would you want to generate these types of documents? In a Web environment, HTML combined with technologies such as cascading style sheets (CSS) provide all the formatting technology needed. As good as these technologies are at rendering your content within the context of a Web browser, they perform quite poorly at generating documents that can or need to be printed. The need for consistency between what is seen on the screen and what is printed to a printer can be very important, and this chapter will provide you with a number of means of accomplishing that goal.

To begin, the following list shows the requirements of a printable document solution in PHP:

  • Consistency in rendering and printing

  • A cross-platform solution

  • Flexible enough for most tasks

  • Easy to understand and implement in PHP

As previously mentioned, two document formats best suit all these requirementsPDF and RTF. Although neither is a particularly easy format to understand, I'll show you a number of methods you can use to generate documents in each format. The first technique I'll introduce is the concept of generating dynamic RTF documents through the use of templates.

    Team LiB
    Previous Section Next Section