PHP
  Home arrow PHP arrow Page 4 - Positioning Strings with the show_xy() Method in PDF Documents with PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 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? 
Google.com  
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: starstarstarstarstar / 4
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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!



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

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek