Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

PHP 7 FPDF Example to Add Header & Footer Images in All Pages of PDF With Hyperlinks inside Browser

Posted on January 17, 2023

 

 

Welcome folks today in this blog post we will be adding images in all pages of pdf with hyperlinks inside header and footer in browser using fpdf library in php. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an index.php file and copy paste the following code

 

 

index.php

 

 

PHP
1
2
3
4
5
6
7
<?Php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image('images/pdf-header.jpg',20,60,180,20,'JPG','www.plus2net.com');
$pdf->Output();
?>

 

 

As you can see we are adding the image inside the header section of the pdf document. And then we are downloading the pdf as an attachment inside the browser.

 

 

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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();
?>

 

 

As you can see we are using the for loop to add all the images inside the pdf document. And then we are adding the images inside the header and the footer sections of the pdf document.

 

Recent Posts

  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Android Java Project to Download Youtube Video Thumbnail From URL & Save it inside SD Card
  • Android Java Project to Embed Google Maps & Add Markers Using Maps SDK
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme