PHP
  Home arrow PHP arrow Page 3 - Constructing Multi-Line 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

Constructing Multi-Line PDF Documents with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2007-11-06


    Table of Contents:
  • Constructing Multi-Line PDF Documents with PHP 5
  • Review: building basic PDF documents using PHP 5
  • Displaying multiple lines of text on a single PDF document
  • Building a multi-line PDF document using the set_text_pos() method

  • 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


    Constructing Multi-Line PDF Documents with PHP 5 - Displaying multiple lines of text on a single PDF document
    ( Page 3 of 4 )

    As I anticipated in the previous section, the “PDFlib” library also incorporates a handy method, called “continue_text().” As its name clearly implies, it allows you to “continue” an existing line of text previously included into a given PDF document. This makes it possible to build several blocks of text that are composed of multiple lines.

    To demonstrate the implementation of this brand new method, below I listed an illustrative hands-on example. It first builds a basic PDF file, and then includes into it a few lines of trivial text.

    Having said that, please take a look at the corresponding code sample, which is as follows:

    // example creating a basic PDF document with PHP and multiple
    lines using the 'continue_text()' method

      try {

    // 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->set_text_pos(50,500);

      $pdf->show("PHP is great for creating PDFs!");

      $pdf->continue_text('This is another line of text');

      $pdf->continue_text('This is another line of text');

      $pdf->continue_text('This is another line of text');

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

    }

    As you can see, in this specific case I used the aforementioned “continue_text()” method that comes packaged with the “PDFLib” library to build a simple PDF file, which this time displays multiple lines of basic text. Obviously, the functionality offered by the method in question is indeed remarkable, since most PDF files display, in one form or another, more than one line of strings.

    To complement the above example, below I included an image that depicts the  output generated by the code sample that you learned previously. It is as follows:

    Pretty easy to grasp, right? At this point you hopefully learned how to build basic PDF documents that are capable of displaying multiple lines of simple text, directly from inside your PHP 5 scripts. So what’s the next step? Well, as you probably realized, the prior example used the “set_text_pos()” method to define the corresponding X,Y coordinates where the text should be displayed on the pertinent PDF document.

    Thus, considering the functionality provided by this method, in the last section of this tutorial I’m going to show you how to use it to display chunks of text at different positions on the same PDF file.

    To see how this will be achieved, please jump ahead and read the next few lines. I’ll be there, waiting for you.



     
     
    >>> 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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek