PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] fix footer image in tcpdf

 February 16, 2022     tcpdf, yii     No comments   

Issue

 $path = Yii::app()->basePath;
            require_once($path . '/extensions/tcpdf/tcpdf.php');
            $pdf = new TCPDF();
            $pdf->setPrintHeader(false);
            $pdf->setPrintFooter(true);
            $pdf->SetAutoPageBreak(TRUE, 0);
            $pdf->AddPage();
            $pdf->SetLineWidth(0.1);
            $pdf->SetFont('times', '', 10);
            $pdf->SetMargins(20, 20, 20, true);
           $footer_image_file = Yii::app()->request->baseUrl.'/images/logo.jpg';
           $content = '<div> $content </div>'; 
            $pdf->writeHTML($content, true, false, true, false, '');
            ob_end_clean();
            $pdf->Output("Reports.pdf", "D");

I want to add image in fooder for every new pages.. please anyone help me...


Solution

Simply put the code displaying the image within the Footer() base method. This base method is called for any new page by either the AddPage() method and Close(). Important : The Footer method should not be called directly.

This method is supposed to be implemented in your class, so override it like this :

function Footer()
{ 
   .... /* Put your code here (see a working example below) */

   $logoX = 186; // 186mm. The logo will be displayed on the right side close to the border of the page
   $logoFileName = "/images/myLogo.jpg";
   $logoWidth = 15; // 15mm
   $logo = $this->PageNo() . ' | '. $this->Image($logoFileName, $logoX, $this->GetY()+2, $logoWidth);

   $this->SetX($this->w - $this->documentRightMargin - $logoWidth); // documentRightMargin = 18
   $this->Cell(10,10, $logo, 0, 0, 'R');
}

I hope this helps and I've well understood your question.



Answered By - pti_jul
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing