我使用TCPDF
供应商包在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
请提出解决方案。任何帮助将不胜感激。
答案 0 :(得分:4)
以下是我用来在生成的pdf中的所有页面上制作边距边界的技巧。
Create a new class extend from TCPDF class
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);
}
}