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

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

  • 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.

  • Include it in your web application
/* sample web app */
//include the FPDF library
require_once('includes/fpdf.php');
  • 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

Your email address will not be published. Required fields are marked *