在tcpdf中修复页脚图像

时间:2017-04-03 13:19:25

标签: yii tcpdf

 $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");

我想在fooder中为每个新页面添加图片..请任何人帮助我......

2 个答案:

答案 0 :(得分:2)

只需将显示图像的代码放在Footer()基本方法中。通过AddPage()方法和Close()为任何新页面调用此基本方法。 重要说明:不应直接调用Footer方法。

这个方法应该在你的类中实现,所以要覆盖它:

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');
}

我希望这会有所帮助,我很清楚你的问题。

答案 1 :(得分:0)

<?xml version="1.0" encoding="UTF-8"?><body>
<div id="container-4">
    <div class="df-width-40">ipsum</div>
</div>

<div id="container-5">
    <div class="df-width-100">lorem</div>
</div>
</body>

此代码完美地放置在页面页脚的中心。感谢很多pti_jul。: - )))))