php - TCPDF - page borders in all pages -


i generating pdf report in cakephp application using tcpdf vendor package. have create page borders on each page of generated pdf.

i used this solution make page border, able draw border on first page of generated pdf.

i using following code:

$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 code make proper html ..... .....  $pdf->writehtml($content_html, true, 0, true, 0); //$content_html contains whole html outputs me several pdf pages  ob_clean(); $pdf_status = $pdf->output($directory_path.$file_name.ext_pdf, 'f'); // save pdf on given path 

kindly suggest solution. appreciated.

following trick used make margin border on pages in generated pdf.

  1. create new class extend tcpdf class
  2. override header method. (this method called on each new pdfpage generation)

please code given below:

<?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 = '';      /**       * method used override 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);     } } 

Comments

  1. 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(0,0,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);
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

ios - Can NSManagedObject conform to NSCoding -