Online Forum To Support Coders With Technical Assistance - Read Write Execute

How to generate pdf in PHP using FPDF

Ankit Agrawal
Ankit Agrawal
Published on January 29, 2019 · 1 min read

FPDF is php class that is used to generate pdf in php. IN FPDF F stands for free it means you can use or modify it accordingly.

Features :

  1. Header & Footer management
  2. Line break option
  3. Image support
  4. Links
  5. Colors

Example :

Simple Pdf


<?php
require('fpdf.php');
$aPdf = new FPDF();
$aPdf->AddPage();
$aPdf->SetFont('Arial','B',20);
$aPdf->Cell(100,100,'Welcome to Code Execute');
$aPdf->Output();
?>

 

Pdf with Header and Footer


<?php
require('fpdf.php');

class cePdf extends FPDF
{
	// Page header
	function Header()
	{
	    $this->SetFont('Arial','B',40);
	    $this->Cell(80);
	    $this->Cell(30,10,'Logo',0,0,'C');
	    $this->Ln(20);
	}

	// Page footer
	function Footer()
	{
	    $this->SetY(-15);
	    $this->SetFont('Arial','',10);
	    $this->Cell(0,10,'This is footer',0,0,'C');
	}
}

$aPdf = new cePdf();
$aPdf->AddPage();
$aPdf->SetFont('Arial','',15);
$aPdf->Cell(0,30,'Welcome to Code Execute',0,0,'L');
$aPdf->Output();
?>

Download Fpdf

 

Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article How can we use spacing classes in bootstrap 4 Next Article → How to download files using url in php