【问题标题】:TCPDF - page borders in all pagesTCPDF - 所有页面中的页面边框
【发布时间】:2013-10-07 11:48:16
【问题描述】:

我正在使用 TCPDF Vendor 包在 CakePHP 应用程序中生成 PDF 报告。 我必须在生成的 PDF 的每一页上创建页面边框。

我使用this solution 制作页面边框,但只能在生成的 PDF 的第一页上绘制边框。

我正在使用以下代码:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();

$pdf->SetLineStyle( array( 'width' => 15, 'color' => array(0,0,0)));

$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight());
$pdf->Line(0,0,0,$pdf->getPageHeight());

//rest of my code to make proper Html
.....
.....

$pdf->writeHTML($content_html, true, 0, true, 0); //$content_html contains the whole Html which outputs me several PDF pages

ob_clean();
$pdf_status = $pdf->Output($directory_path.$file_name.EXT_PDF, 'F'); // save pdf on the given path

请提出解决方案。任何帮助将不胜感激。

【问题讨论】:

  • 从外观上看,您是在第一页上绘制边框,然后编写多页 HTML。你没有告诉它在任何地方写下其余页面的边框。我不相信这是可能的。
  • @MichaelDeMutis,是的,我想在其余页面上也写边框。

标签: php html cakephp pdf tcpdf


【解决方案1】:

以下是我用来在生成的 pdf 中的所有页面上制作边距边框的技巧。

  1. Create a new class extend from TCPDF class
  2. Override the Header method.(每次生成新的pdfpage都会调用这个方法)

请查看下面给出的代码:

<?php
App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','tcpdf/config/lang/eng');
class AUTHPDF extends TCPDF
{
    protected $processId = 0;
    protected $header = '';
    protected $footer = '';
    static $errorMsg = '';

    /**
      * This method is used to override the parent class method.
    **/
    public function Header()
    {
       $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);
       $this->SetLineStyle( array( 'width' => 0.40, 'color' => array(153, 204, 0)));

       $this->Line(5, 5, $this->getPageWidth()-5, 5); 

       $this->Line($this->getPageWidth()-5, 5, $this->getPageWidth()-5,  $this->getPageHeight()-5);
       $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
       $this->Line(5, 5, 5, $this->getPageHeight()-5);
    }
}

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多