HomePHP Constructing Multi-Line PDF Documents with PHP 5
Constructing Multi-Line PDF Documents with PHP 5
If you’re a PHP developer interested in developing web applications that deliver the contents of their database tables in PDF format, then hopefully this group of articles will be what you’re looking for. Welcome to the second article of the series “Building PDF documents with PHP 5.” Composed of five instructive tutorials, this series shows you the basics for creating PDF files directly from your own PHP 5 scripts, and complements the theoretical concepts with copious hands-on examples.
Having introduced you to the main subject of this series, now let me refresh your memory of the topics that were discussed in the previous tutorial. In that article, we learned that creating primitive PDF documents using PHP is a process that’s reduced to spawning a new instance of the “PDFlib” class that comes bundled with the popular “PDFLib” library, and then calling one or more of its pertinent methods to open a new PDF document and a page, which usually need to include some basic contents in them, like text strings and images as well.
With regard to specifying the dimensions of the PDF page that will be used for constructing the corresponding document, the “PDFLib” package offers the handy “begin_page_ext()” method. It's useful for creating PDF pages of different sizes, including some popular formats, like A3, A4, and A5.
In addition, you saw how to include some basic texts into several PDF files by using a combination of the “set_text_pos()” and “show()” methods. Naturally these are packaged with the “PDFLib” library. In this way you learned some of the most common tasks associated with the creation of PDF files.
However, to be frank, I'm just starting to scratch the surface when it comes to building PDF files with PHP 5. There are many other helpful methods, provided by aforementioned “PDFLib” package. Thus, in this second part of the series I’ll provide you with some examples that illustrate how to build PDF files that contain multiple lines of text; remember, in the preceding article I worked only with single-line strings. Additionally, I'll teach you how to position these texts on a given PDF page.
With the preliminaries out of the way, it’s time to continue learning more about building PDF files with PHP 5. Let’s go!