Dalam membuat aplikasi yang memerlukan pencetakan, sering kita harus menampilkan footer pada setiap pencetakan yang terjadi. Dalam framework Yii kita dapat melakukan extension TCPDF supaya dapat menampilkan footer. Berikut akan dijelaskan bagaimana kita meng- extend class pdf ini.

Pertama-tama pastikan anda sudah menginstall estension TCPDF di Yii. Jika belum silahkan mengikuti http://www.proweb.co.id/articles/web_application/print_pdf_di_yii.html .

Selanjutnya silahkan masuk ke directory protected/extensions/tcpdf.
Pada directory ini silahkan membuat file mypdf.php dengan content seperti berikut ini:

require_once(dirname(__FILE__).’/config/tcpdf_config.php’);
require_once(dirname(__FILE__).’/tcpdf.php’);

class MYPDF extends TCPDF {

    //Page header
    public $my_header;
     public $my_footer;

    public $my_x0;
    public $my_y0;

    public $my_x;
    public $my_y;

    public $my_w;
    public $my_h;

    public function Header() {
        $this->SetFont(“times”, “”, 10);
        //die($this->my_header);
        $this->writeHTMLCell ($this->my_w, $this->my_h, $this->my_x + $this->my_x0, $this->my_y + $this->my_y0, $this->my_header, $border=0, $ln=0, $fill=false, $reseth=true, $align=”, $autopadding=true);        

    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont(‘helvetica’, ‘I’, 8);
        // Page number
        //$this->Cell(0, 10, $this->footerText .$this->getAliasNumPage().’/’.$this->getAliasNbPages(), 0, false, ‘C’, 0, ”, 0, false, ‘T’, ‘M’);
        $this->writeHTML ( $this->my_footer . ” <span style=\”font-size: x-small;\”>Page ” .$this->getAliasNumPage().’/’.$this->getAliasNbPages().”</span>”);        

    }
}

?>

 

Pada contoh di atas kita melakukan extension pada class TCPDF..

Kemudian contoh coding untuk memanggil adalah :
        $pdf = Yii::createComponent(‘application.extensions.tcpdf.mypdf’,
                            ‘P’, ‘mm’, ‘A4’, true, ‘UTF-8’);

        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor(Yii::app()->user->id);
        $pdf->SetTitle(“Purchase Order “.$model->purchase_no);
        //$pdf->SetSubject(“TCPDF Tutorial”);
        //$pdf->SetKeywords(“TCPDF, PDF, example, test, guide”);
        $pdf->setTopMargin(20);
        $pdf->setPrintHeader(true);
        $pdf->setPrintFooter(true);
        //$pdf->AliasNbPages();
        $pdf->my_x0=$x0;
        $pdf->my_y0=$y0;
        $pdf->my_header=$header_html;// . $header_table_html .”</table>” ;
        $pdf->AddPage();
        $pdf->SetFont(“times”, “”, 10);

        $add_info='<span style=”font-size: small;”>Putih:Vendor &nbsp;&nbsp;&nbsp; Pink:Arsip &nbsp;&nbsp;&nbsp; Hijau:Finance &nbsp;&nbsp;&nbsp; Kuning:Arsip</span>
        <br/><span style=”font-size: x-small;”>Print at ‘.
        date(“Y-m-d H:i:s”,time()). ” by “. $modeltmp->username .”(” .Yii::app()->user->id .”)”.'</span>’ ;

        $pdf->my_footer=$add_info;

Dan seterusnya.

Kunjungi www.proweb.co.id untuk menambah wawasan anda.

Setting Footer pada TCPDF di YII
× Ada yang dapat saya bantu ? Available on SundayMondayTuesdayWednesdayThursdayFridaySaturday