PHP
  Home arrow PHP arrow Page 2 - Constructing Multi-Line PDF Documents ...
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 
 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

Constructing Multi-Line PDF Documents with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      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

    Dell PowerEdge Servers

    Constructing Multi-Line PDF Documents with PHP 5 - Review: building basic PDF documents using PHP 5
    (Page 2 of 4 )

    As usual with my articles on PHP development, before I move forward and show you how to include multiple lines of text into a given PDF document, I'm going to give you a good review. I want you to recall how to utilize some basic methods included with the “PDFLib” library to build a few simple PDF files.

    Below I listed the source code of two examples shown in the first installment of the series. They demonstrate how to create a couple of PDF documents, in A4 and A5 format respectively. Their respective signatures are as follows:

    // example creating a basic PDF (A4) document with PHP

    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","pdf_example.php");

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

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

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

     

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

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

      $pdf->set_text_pos(50,800);

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

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

    }

    // example creating a basic A5 PDF document with PHP 5

      try {

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

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

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

    }

    So far, so good. After looking at the two previous code samples, I’m pretty sure that you now remember the basics of building simple PDF documents that include single lines of text. So now we'll go one step further and see how to create PDF files that display multiple lines.

    As you may guess, this interesting process will be discussed in the next section, so click on the link that appears below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · Over the course of this second installment of the series, you’ll learn the basics on...
     

       

    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 6 hosted by Hostway