PHP
  Home arrow PHP arrow Page 3 - Positioning Strings with the show_xy()...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-11-27

    Table of Contents:
  • Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
  • Inserting Blocks of Text
  • Going One Step Further
  • Completion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Positioning Strings with the show_xy() Method in PDF Documents with PHP 5 - Going One Step Further
    (Page 3 of 4 )

    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:

      try{

     

    // 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

     

       if(!$pdf->begin_document("","")){

     

    throw new PDFlibException("Error creating PDF document. ".$pdf-
    >get_errmsg());

     

    }

     

      $pdf->set_info("Creator","example.php");

     

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

     

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

     

     

      $pdf->begin_page_ext(421,595,"");

     

     

       $font=$pdf->load_font("Helvetica-Bold","winansi","");

     

     

      $pdf->setfont($font,24.0);

     

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

     

    // end page

     

      $pdf->end_page_ext("");

     

    // end document

     

      $pdf->end_document("");

     

     

    // get buffer contents

     

      $buffer=$pdf->get_buffer();

     

    // get length of buffer

     

       $len=strlen($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();

    exit();

    }

    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


       · Over the course of this last installment of the series, you’ll learn how to use the...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway