Code

Randy Dustin. Web Developer.

Get started generating PDF’s today! Part 1 – installation

July 28th, 2009

FPDF

FPDF describes itself as

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

Installation

  1. Download the library and place it in a directory accessible by your web server

    It generally makes sense to put it in an includes directory.

  2. Include it in your web application
    /* sample web app */
    //include the FPDF library
    require_once('includes/fpdf.php');
    
  3. Create the page
    //instantiate the object
    $fpdf = new FPDF();
    
    //create a page
    $fpdf->AddPage();
    
    //set the font, font-style, and size
    $fpdf->SetFont('Arial', 'B', 14);
    
    //create the text to be output and go to the next line
    $fpdf->Cell(22, 12, "Randy Dustin", 0,1);
    //the next line
    $fpdf->Cell(22, 12, "Pretty much the coolest person on Earth!");
    
    //create the page
    $fpdf->Output();
    

For more information and tutorials on building pdfs you can go to the FPDF website and reference their tutorials and the manual

We will be continuing this series soon with a closer look at our options when creating a page. Some things to look for are:

  • Changing page orientation and size
  • Changing Font styles
  • Changing the size and style of text cells
  • The different options for saving the final product

Read Part 2 – playing with the options

Leave a Reply

© Copyright 2009 Randy Dustin

Hosted by A Small Orange