Adding Image to PDF file by FPDF

PDF Image

Adding image to fpdf class PDF documents by using Image function with header and footer of all pages

<?Php
require('fpdf.php');
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->Image('images/pdf-header.jpg',0,0);
$pdf->Output();
?>
The ouput of above code is here . ( Show 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.plus2net.com');
$pdf->Output();
?>
The ouput of above code is here . ( Show Output )

Adding image at header and footer

adding image to pdf page
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();
?>
The output of above code is here . ( Show Output )

Example: Inserting Multiple Images in a PDF

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image('image1.jpg', 10, 10, 40);
$pdf->Image('image2.png', 60, 10, 40);
$pdf->Output();

Example: Resizing Image Dynamically

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
list($width, $height) = getimagesize('image.jpg');
$pdf->Image('image.jpg', 10, 10, $width/4, $height/4); // Resizing
$pdf->Output();

Questions



Cell Line()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    21-12-2022

    i have to add image in fpdf cell can you have any idea how to do this

    30-03-2023

    how to convert a pdf file into an image file in PHP or scriptcase

    31-10-2024

    you can use the Imagick extension, which is part of ImageMagick.




    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer