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