Home arrow PHP arrow Page 3 - Positioning Strings with the show_xy() Method in PDF Documents with PHP 5

Going One Step Further - PHP

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.

  1. Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
  2. Inserting Blocks of Text
  3. Going One Step Further
  4. Completion
By: Alejandro Gervasio
Rating: starstarstarstarstar / 4
November 27, 2007

print this article



Going one step further in using the “show_xy()” method: displaying a block of text at a different position

As I anticipated in the section that you just read, the best way to grasp how the “show_xy()” method works consists of creating a certain number of examples, which will help you see how useful it can be to display several blocks of text using a pair of X,Y coordinates.

Based upon this premise, below I included another hands-on example. It shows how to position a determined string within a given PDF document, using the pertinent “show_xy()” method. The corresponding code sample is as follows:



// example creating a basic PDF document and display a
basic text using the 'show_xy()' method

// create new instance of the 'PDFlib' class


  $pdf=new PDFlib();


// open new PDF file




throw new PDFlibException("Error creating PDF document. ".$pdf-






  $pdf->set_info("Author","Alejandro Gervasio");


  $pdf->set_info("Title","Example on using PHP to create PDF











  $pdf->show_xy("PHP is great for creating PDFs!",30,300);


// end page




// end document





// get buffer contents




// get length of buffer





// display PDF document


  header("Content-type: application/pdf");


  header("Content-Length: $len");


  header("Content-Disposition: inline; filename=example.pdf");


echo $buffer;




catch (PDFlibException $e){


   echo 'Error Number:'.$e->get_errnum()."n";

  echo 'Error Message:'.$e->get_errmsg();



In this particular case, I used the handy “show_xy()” method to display a sample text on a previously opened PDF file, utilizing a new pair of X,Y coordinates, which should speak for itself about the remarkable functionality of the method in question.

In addition, bearing in mind that the prior example would be rather incomplete if its corresponding output isn’t shown, below I included a screen shot that depicts the results displayed by the example: 

The previous screen shot demonstrates how simple it is to display a sample text in a given PDF file using the handy “show_xy()” method. In this case, this text has been placed using an X offset of 30, while the respective X value is 300. Quite easy to grasp, right?

Well, now that you hopefully understood the basics in using the prior “show_xy()” method, I’m going to develop a final example that utilizes this method, in this way completing its practical demonstration.

As you might have guessed, to see how this final hands-on example will be properly built, you’ll have to click on the link below and read the next few lines. We’re almost finished!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: