To add an image to your PDF file, use the
Image() method, as demonstrated here:
<!--p
require 'fpdf.php';
$pdf=new FPDF('P', 'pt', 'A4');
$pd-->AddPage();
$pdf->SetFont('Times', 'B', 16);
$pdf->Cell(0,10,'Easy PayPal with PHP', 0, 2, 'C');
$pdf->Image('easypaypalwithphp.jpg');
$pdf->Output();
?>
The
Image() method is surprisingly powerful in the sense that although it accepts quite a few input parameters, all are optional except for the image file name. It will automatically determine the image's dimensions and image type (JPEG or PNG for instance), however you can override these defaults using other available parameters. See the
Image() documentation for all the details.
When making sensitive or copyright material available to customers, it's often useful to include a
watermark, which identifies the individual downloading the material. I call this
SRM, or Shame Rights Management, because if the customer ever decides to upload the material to a file sharing service, he does so knowing that his name, e-mail address, or other identifying details are embedded in the document.
You can easily embed information in the footer of every generated PDF page using a slick FPDF feature, which merely requires you to extend the FPDF class and override the Footer() method, within it defining what you would like to appear in the page footer. FPDF will automatically detect this method and execute it each time a new page is created. For instance, the following example will embed the e-mail address jason@example.com into the PDF footer:
<!--p
require 'fpdf.php';
class WJGPDF extends FPDF
{
function Footer()
{
$thi-->SetY(-25);
$this->SetFont('Times', 'B', 12);
$this->Cell(0,20,'Licensed to jason@example.com', 0, 0, 'C');
}
}
$pdf=new WJGPDF('P', 'pt', 'A4');
$pdf->AddPage();
$pdf->SetFont('Times', 'B', 16);
$pdf->Cell(0,10,'Easy PayPal with PHP', 0, 2, 'C');
$pdf->Output();
?>
As you can see, the FPDF library packs quite a punch, and I've hardly scratched the surface in terms of what it can do! Be sure to check out the
FPDF website for tutorials, documentation, and other useful information.