HomePHP Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
As you know, more and more web sites try to engage their visitors by delivering their database contents in several formats, such as Adobe’s Portable Document Format (PDF). The good news regarding this topic is that you, as a PHP developer, can take advantage of this language’s versatility and get started quickly building PDF files directly from your own scripts.
Welcome to the final installment of the series that began with “Building PDF Documents with PHP 5.” Composed of five educational tutorials, this series provides you with a friendly introduction to using the most important methods that come packaged with the popular “PDFlib” library and to performing some tasks associated with PDF files, such as creating and deleting documents on the fly, inserting blocks of texts and images, and working with single and multi-line strings.
Having introduced you to the subject covered by this group of articles, it’s time to recapitulate briefly the topics that were discussed in the previous tutorial of the series. This way you’ll be able to see more easily how that article and the current one can link with each other.
Getting straight to the point, hopefully you’ll recall that in the previous article I showed you how to use the helpful “rect()” method which comes integrated with the “PDFlib” package to draw some basic rectangles on a given sample PDF file.
Indeed, as you saw for yourself, incorporating primitive shapes like the pertinent rectangles to an existing PDF file is an easy-to-follow process. It’s only limited to creating an instance of the already familiar “PDFlib” class that I used with all of the hands-on examples that you learned so far, and calling the adequate method responsible for drawing a specific shape.
Nevertheless, regardless of the ease with which the “PDFlib” library can be used to perform different tasks, like drawing different shapes, inserting images, and so forth, undoubtedly the king of all of them is working with text. In truth, one of the most common challenges that an average PHP developer has to tackle when building PDF files from scratch consists of creating PDF documents whose contents are mostly composed of simple text.
Considering this fact, this last installment of the series will be entirely focused on using a handy method that naturally belongs to the “PDFlib” library, called “show_xy()”, which allows you to display complete blocks of text at different positions within a given PDF document, by using only a couple of X,Y coordinates.
So, are you ready to learn how to use the “show_xy()” method to create text-based PDF files? Well, let’s not waste more time in preliminaries and begin now!