0

how can i add header(logo) and footer(logo with page number) using fpdi or if you are suggesting any other like tcpdf pls give me any cdn link for tcpdf.php file (if possible)

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
use setasign\Fpdi\Fpdi;
use setasign\Fpdi\PdfReader;

require_once('fpdf/fpdf.php');
require_once('fpdi/src/autoload.php');

class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('logo.png',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(30,10,'Title',1,0,'C');
// Line break
$this->Ln(20);
}

// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$pdf = new Fpdi();
//first page
$pageCount = $pdf->setSourceFile('generated.pdf');
$pageId = $pdf->importPage(1, PdfReader\PageBoundaries::MEDIA_BOX);
$pdf->addPage();
$pdf->useImportedPage($pageId);

$pdf->addPage();
$pdf->Ln(60);
$pdf->SetFont('Arial','B',34);
$pdf->Cell(189,10,'Tender Details',0,1,'C');
$pdf->Ln(20);
$heading="";
$ttitle="";
$tno="";
$tdate="";
$itemname="123gytfytfytfytftyfyty";

$pdf->SetFont('Arial','B',20);
$pdf->Cell(30);
$pdf->Cell(170,5,'Heading- '.$heading.'',0,1);
$pdf->Ln(10);
$pdf->Cell(30);
$pdf->Cell(170,5,'Tender Title- '.$ttitle.'',0,1);
$pdf->Ln(10);
$pdf->Cell(30);
$pdf->Cell(170,5,'Tender Number- '.$tno.'',0,1);
$pdf->Ln(10);
$pdf->Cell(30);
$pdf->Cell(170,5,'Tender Date- '.$tdate.'',0,1);
$pdf->Ln(10);
$pdf->Cell(30);
$pdf->Cell(170,5,'Item Name- '.$itemname.'',0,1);
$cd="We are from Ascentech Lightening Solution, a MSME firm, manufacturer of LED Lights along with Medical Lights and Emergency Lights. We have participated in your tender  2021-01-06. Please find below list of documents for the same.";
$pdf->addPage();
$pdf->Ln(30);
$pdf->SetFont('times','B',12);
$pdf->Write(5,$cd);
$pdf->Ln(10);
$pdf->SetFont('times','BU',12);
$pdf->Cell(170,5,'Item Name- ',0,1);
$pdf->Ln(5);
$pdf->SetFont('times','B',12);
$pdf->Cell(170,5,$itemname,0,1);
$pdf->Ln(15);
$pdf->SetFont('times','BU',24);
$pdf->Cell(189,10,'Technical Specification Acceptance',0,1,'C');
$pdf->Ln(7);
$pdf->Cell(189,10,'Item name test',0,1,'C');
$pdf->Ln(5);

$pdf->SetFillColor(224,235,255);
$pdf->SetFont('Arial','B',12);
$pdf->SetX(25);
$pdf->Cell(15,10,'Sr. no',1,0,'C',1);
$pdf->Cell(90,10,'Technical Specification',1,0,'C',1);
$pdf->Cell(30,10,'Values',1,0,'C',1);
$pdf->Cell(30,10,'Offered',1,0,'C',1);
//$pdf->Cell(18,10,'Browse',1,0,'C',1);
//$pdf->Cell(45,10,'Browse Documents',1,0,'C',1);
$pdf->SetFont('Arial','',12);
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');


$pdf->addPage();
$pdf->SetFont('times','BU',24);
$pdf->Ln(30);
$pdf->Cell(189,10,'Item name test1',0,1,'C');
$pdf->Ln(5);
$pdf->SetFillColor(224,235,255);
$pdf->SetFont('Arial','B',12);
$pdf->SetX(25);
$pdf->Cell(15,10,'Sr. no',1,0,'C',1);
$pdf->Cell(90,10,'Technical Specification',1,0,'C',1);
$pdf->Cell(30,10,'Values',1,0,'C',1);
$pdf->Cell(30,10,'Offered',1,0,'C',1);
//$pdf->Cell(18,10,'Browse',1,0,'C',1);
//$pdf->Cell(45,10,'Browse Documents',1,0,'C',1);
$pdf->SetFont('Arial','',12);
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Ln(10);
$pdf->SetX(25);
$pdf->Cell(15,10,'1',1,0,'C');
$pdf->Cell(90,10,'test',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');
$pdf->Cell(30,10,'yes',1,0,'C');


// get the page count
$pageCount = $pdf->setSourceFile('generated.pdf');
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    // import a page
    $templateId = $pdf->importPage($pageNo);
    // get the size of the imported page
    $size = $pdf->getTemplateSize($templateId);

    // create a page (landscape or portrait depending on the imported page size)
    if ($size[0] > $size[1]) {
        $pdf->AddPage('L', array($size[0], $size[1]));
    } else {
        $pdf->AddPage('P', array($size[0], $size[1]));
    }

    // use the imported page
    $pdf->useTemplate($templateId);

    $pdf->SetFont('Helvetica');
    $pdf->SetXY(5, 5);
    $pdf->Write(8, 'By me');
}
$pdf->addPage();
// get the page count
$pageCount = $pdf->setSourceFile('generated.pdf');
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    // import a page
    $templateId = $pdf->importPage($pageNo);
    // get the size of the imported page
    $size = $pdf->getTemplateSize($templateId);

    // create a page (landscape or portrait depending on the imported page size)
    if ($size[0] > $size[1]) {
        $pdf->AddPage('L', array($size[0], $size[1]));
    } else {
        $pdf->AddPage('P', array($size[0], $size[1]));
    }

    // use the imported page
    $pdf->useTemplate($templateId);

    $pdf->SetFont('Helvetica');
    $pdf->SetXY(5, 5);
    $pdf->Write(8, 'By me');
}
$pdf->Output();
?>

How can I add header(logo) and footer(logo with page number) using fpdi or if you are suggesting any other like tcpdf.

You can check the deployed version of this file here (http://twenfluence.tech/pdf/pdf.php)

  • Follow [tutorial 2](http://www.fpdf.org/en/tutorial/tuto2.htm) on the fPDF site for details on how to create headers and footers. – Dave Feb 01 '21 at 11:54
  • Deve, thanks! but i tried the same with the above that's not working. can you pls?? – Đęĕpák Ğųpţą Feb 01 '21 at 12:37
  • There is nothing in what you posted that includes a header or footer function as described in the tutorial I linked. Used properly you don't have to do anything to have headers and footers added automatically. – Dave Feb 01 '21 at 14:52
  • i am saying i tried to add header and footer from the given tutorial in my code but its not working...can you pls just try at once if you – Đęĕpák Ğųpţą Feb 02 '21 at 05:09
  • What you posted shows no attempt to use a header and footer as detailed in that tutorial. Please [edit] your question with your attempt with a header and footer. What is there now has not changed and has no header or footer function defined. – Dave Feb 02 '21 at 12:30
  • ok wait i am editing – Đęĕpák Ğųpţą Feb 02 '21 at 12:35
  • I edited my question can you please check what's the error – Đęĕpák Ğųpţą Feb 04 '21 at 01:39

0 Answers0