Subversion Repositories Applications.annuaire

Rev

Rev 296 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_003.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-08-08
6
//
7
// Description : Example 003 for TCPDF class
8
//               Custom Header and Footer
9
//
10
// Author: Nicola Asuni
11
//
12
// (c) Copyright:
13
//               Nicola Asuni
14
//               Tecnick.com s.r.l.
15
//               Via Della Pace, 11
16
//               09044 Quartucciu (CA)
17
//               ITALY
18
//               www.tecnick.com
19
//               info@tecnick.com
20
//============================================================+
21
 
22
/**
23
 * Creates an example PDF TEST document using TCPDF
24
 * @package com.tecnick.tcpdf
25
 * @abstract TCPDF - Example: Custom Header and Footer
26
 * @author Nicola Asuni
27
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
28
 * @link http://tcpdf.org
29
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
30
 * @since 2008-03-04
31
 */
32
 
33
require_once('../config/lang/eng.php');
34
require_once('../tcpdf.php');
35
 
36
 
37
// Extend the TCPDF class to create custom Header and Footer
38
class MYPDF extends TCPDF {
39
 
40
	//Page header
41
	public function Header() {
42
		// Logo
43
		$image_file = K_PATH_IMAGES.'logo_example.jpg';
44
		$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
45
		// Set font
46
		$this->SetFont('helvetica', 'B', 20);
47
		// Title
48
		$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
49
	}
50
 
51
	// Page footer
52
	public function Footer() {
53
		// Position at 15 mm from bottom
54
		$this->SetY(-15);
55
		// Set font
56
		$this->SetFont('helvetica', 'I', 8);
57
		// Page number
58
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
59
	}
60
}
61
 
62
// create new PDF document
63
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
64
 
65
// set document information
66
$pdf->SetCreator(PDF_CREATOR);
67
$pdf->SetAuthor('Nicola Asuni');
68
$pdf->SetTitle('TCPDF Example 003');
69
$pdf->SetSubject('TCPDF Tutorial');
70
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
71
 
72
// set default header data
73
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
74
 
75
// set header and footer fonts
76
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
77
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
78
 
79
// set default monospaced font
80
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
81
 
82
//set margins
83
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
84
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
85
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
86
 
87
//set auto page breaks
88
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
89
 
90
//set image scale factor
91
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
92
 
93
//set some language-dependent strings
94
$pdf->setLanguageArray($l);
95
 
96
// ---------------------------------------------------------
97
 
98
// set font
99
$pdf->SetFont('times', 'BI', 12);
100
 
101
// add a page
102
$pdf->AddPage();
103
 
104
// set some text to print
105
$txt = <<<EOD
106
TCPDF Example 003
107
 
108
Custom page header and footer are defined by extending the TCPDF class and overriding the Header() and Footer() methods.
109
EOD;
110
 
111
// print a block of text using Write()
112
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
113
 
114
// ---------------------------------------------------------
115
 
116
//Close and output PDF document
117
$pdf->Output('example_003.pdf', 'I');
118
 
119
//============================================================+
120
// END OF FILE
121
//============================================================+