Home arrow Zend arrow PDFs with PHP part 2

PDFs with PHP part 2

This tutorial is intended for the PHP programmer who needs to incorporate PDF generation in a script without using external libraries such as PDFlib (often unavailable due to licensing restrictions or lack of funds). This tutorial is the second of two parts, and builds on what was covered in the first part. Therefore, if you have not yet gone through Part 1, you are advised to do so (or at least read through it), before going through this tutorial (Part 2). Apart from what was dealt with in Part 1, no knowledge of PDF file structure is required to understand this tutorial, as all references are explained.

  1. PDFs with PHP part 2
  2. Color
  3. RGB Color
  4. Line Drawing
  5. Circles
  6. Page Add Modifications
  7. File Checking
  8. Example Use
By: Zend
Rating: starstarstarstarstar / 5
January 07, 2004

print this article



We saw in Part 1 how PDF files are, after all, just plain text files, with specific markup syntax that describes what should happen to objects within the document, such as text and images. We shall now further examine this syntax, to allow us to create a more complete PDF document (i.e more than simple text).

Learning Objectives
With the combined knowledge from Part 1, and from the current tutorial (Part 2), you should be able to put together a simple PDF class that can:
   Add colors to your PDF documents;
   Add lines, rectangles and circles;
   Insert JPEG images.

You need to have a fully functional PHP install (either PHP 4 or PHP 5), and a running web server to output the PDF file from your script.

Acrobat Reader, XPDF, or equivalent is required, to display the results of your work.

You do not need any external library, either separate or compiled into PHP, to generate your PDF files.

How It Works
We already have the class from Part 1 of this tutorial. In Part 2 we will just add a few more class variables and methods to it.

We shall review the various methods and features of the PDF language, and then finally put it all together as one class.

New Class Variables
In addition to the class variables we introduced in Part 1, we will also need the following.
var $_fill_color = '0 g';  // Color used on text and fills.
var $_draw_color = '0 G';  // Line draw color.
var $_line_width = 1;      // Drawing line width.
var $_images = array();    // An array of used images.
In the PDF specifications, black is the default value for fill and draw colors, and the default line width is 1 point. Therefore we will use these values as our class defaults for the above variables.

>>> More Zend Articles          >>> More By Zend

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Taking the Zend Certified PHP Engineer Exam:...
- Quick Introduction to PHP 5
- PHP SOAP Extension
- Improving Performance
- PDFs with PHP part 2
- PDFs with PHP part 1
- PHP at Lycos
- Build Database Interfaces

Developer Shed Affiliates


Dev Shed Tutorial Topics: