Pages

Tuesday, March 16, 2021

Add Image to PDF By FPDF

 

PDF Image
<?Php
require('fpdf.php');
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->Image('images/pdf-header.jpg',0,0);
$pdf->Output();
?>
We can add position with height, width and link to above code.
<?Php
require('fpdf.php');
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->Image('images/pdf-header.jpg',20,60,180,20,'JPG','www.google.com');
$pdf->Output();
?>

Adding image at header and footer:


We can place image at header and footer of the page so it will be repeated in all pages. We will create one page which is extended up to 2nd page. We will use image inside our header so it will be repeated in 2nd page also. Same way we will add one image to footer of the page.
<?Php
require('fpdf.php');

class PDF extends FPDF
{
// Page header
function Header()
{
 $this->Image('images/pdf-header.jpg',0,0);
}
// Page footer
function Footer()
{
 $this->SetY(-20);
 $this->Image('images/pdf-footer.jpg');
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->SetMargins(10,60,10);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10,'This is line number '.$i,0,1);
$pdf->Output();
?>

No comments:

Post a Comment