PHP
  Home arrow PHP arrow Page 4 - 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Positioning Strings with the show_xy() Method in PDF Documents with PHP 5 - Completion
    (Page 4 of 4 )

    Completing the implementation of the “show_xy()” method: developing a final hands-on example

    As I said earlier, the last example that I’m going to provide you in this article will be focused on illustrating yet another concrete implementation for the useful “show_xy()” method that you learned in the previous sections.

    So, taking this into account, now take some time and analyze the following code sample, which uses the aforementioned method to display a primitive string of text within a sample PDF file, this time using a new pair of X,Y coordinates:

     

     

      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; insert a file name to create the PDF
    document on disk */

     

       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!",10,400);

     

    // 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();

    }

    This time, I’m not going to bore you explaining how the above example works, since it’s very similar to the one shown in the prior section. Of course, the only difference to spot here is that the sample text has been displayed at a different position within the sample PDF document, something that’s clearly demonstrated by the following image:

    And that’s all for now. The last code sample should give you a clear idea on how to use the “show_xy()” method bundled with the “PDFlib” library to display easily several strings of text using only a couple of X,Y coordinates.

    As with many other topics about PHP development, the best way to master the creation of PDF files is practice, so don’t waste more time. Start coding your own examples!

    Final thoughts

    It’s hard to believe, but we've actually come to the end of this series. However, hopefully the overall experience has been instructive, and fun too. As you learned with the numerous examples that were developed in this group of articles, building basic PDF files with PHP 5 is indeed a no-brainer process, except for the annoyance of having to install third-party software on the web server, like the “PDFlib” library (although other options are available at no cost, like FPDF and TCPDF), which isn’t always as easy as expected.

    See you in the next PHP development tutorial!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 1 hosted by Hostway