Welcome to the fourth part of the series that began with “Building PDF documents with PHP 5.” Since PHP 5 comes packaged with robust capabilities for delivering database contents in a considerable variety of formats, including Adobe’s PDF (Portable Document Format), this series teaches you how to create this type of file with only minor hassles, directly from your own scripts.
If you already read the two preceding tutorials of the series, you’ve acquired a solid background in building simple PDF documents with PHP 5. In those articles I covered the basics of this process, including the adequate implementation of the “set_text_pos()”, “show()”, and “continue_text()” methods that come integrated with the PDFLib library. I did this in order to display both single and multi-line texts, as well as incorporate some basic images into a given PDF document.
Creating dynamic PDF files is a process reduced to spawning an instance of the already familiar PDFLib class, bundled with the homonymous library, and then calling the appropriate set of methods in accordance with the kind of tasks that must be performed on the file in question, such as opening a new document and a new page, adding some lines of text, including images, you name it.
In addition, you’ll certainly recall that in the previous installment of the series I showed you how to create different blocks of text inside a determined PDF document, which in this context are called “text flows.” As you saw, these text flows are useful when you want to incorporate several paragraphs that have predefined dimensions -- that have specific widths and heights respectively.
Regarding the incorporation of text flows into a given PDF document, I showed a concrete example of how to use a combination of the handy “create_text_flow()”, “fit_text_flow()”, and “delete_text_flow()” methods, to display a single block of text at a specific position within the pertinent document. Certainly this is a procedure that can be performed effortlessly, mostly because of the easy learning curve offered by the aforementioned methods.
All right, now that you know how to include basic blocks of text into a simple PDF file, in addition to incorporating some images, the question that comes up here is: what’s the next step to take? Well, in this fourth part of the series I’m going to show you how to draw a few basic shapes, once a PDF document has been opened, like empty and filled rectangles, which can be useful if you want to decorate the document with these kinds of forms.
Now, let’s get rid of the boring preliminaries and start learning more about how to draw a few simple rectangles in a specific PDF file. Let’s get going!