如何在 fpdi 中添加页眉徽标和页脚带有页码的徽标

问题描述

如何使用 fpdi 添加页眉(徽标)和页脚(带有页码的徽标) 或者如果您建议任何其他类似 tcpdf 的文件,请给我任何 tcpdf.PHP 文件的 CDN 链接(如果可能)

<?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,'Title',1,'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,'Page '.$this->PageNo().'/{nb}','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',34);
$pdf->Cell(189,'Tender Details','C');
$pdf->Ln(20);
$heading="";
$ttitle="";
$tno="";
$tdate="";
$itemname="123gytfytfytfytftyfyty";

$pdf->SetFont('Arial',20);
$pdf->Cell(30);
$pdf->Cell(170,5,'heading- '.$heading.'',1);
$pdf->Ln(10);
$pdf->Cell(30);
$pdf->Cell(170,'Tender Title- '.$ttitle.'','Tender Number- '.$tno.'','Tender Date- '.$tdate.'','Item Name- '.$itemname.'',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',12);
$pdf->Write(5,$cd);
$pdf->Ln(10);
$pdf->SetFont('times','BU',12);
$pdf->Cell(170,'Item Name- ',1);
$pdf->Ln(5);
$pdf->SetFont('times',$itemname,1);
$pdf->Ln(15);
$pdf->SetFont('times',24);
$pdf->Cell(189,'Technical Specification Acceptance','C');
$pdf->Ln(7);
$pdf->Cell(189,'Item name test','C');
$pdf->Ln(5);

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


$pdf->addPage();
$pdf->SetFont('times',24);
$pdf->Ln(30);
$pdf->Cell(189,'Item name test1','C');
$pdf->Ln(5);
$pdf->SetFillColor(224,'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',$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','By me');
}
$pdf->Output();
?>

如何使用 fpdi 添加页眉(徽标)和页脚(带有页码的徽标) 或者如果您建议使用其他任何类似 tcpdf 的文件

您可以在此处查看此文件的部署版本 (http://twenfluence.tech/pdf/pdf.php)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)