Page borders in all pages Using TCPDF


You can add borders to all pages in pdf generated using TCPDF by simple two steps.

  • Create a new class extend from TCPDF class
  • Override the Header method. (Header method is called on a generation of each new page in TCPDF)
<?php
App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','tcpdf/config/lang/eng');
class PTCPDF 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(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);
     }
}

For Latest Tech Updates Go To www.techstazo.com

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s