Subversion Repositories Applications.annuaire

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_059.php
4
// Begin       : 2010-05-06
5
// Last Update : 2010-09-13
6
//
7
// Description : Example 059 for TCPDF class
8
//               Table Of Content using HTML templates.
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: Table Of Content using HTML templates.
26
 * @author Nicola Asuni
27
 * @copyright 2004-2010 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 2010-05-06
31
 */
32
 
33
require_once('../config/lang/eng.php');
34
require_once('../tcpdf.php');
35
 
36
/**
37
 * TCPDF class extension with custom header and footer for TOC page
38
 */
39
class TOC_TCPDF extends TCPDF {
40
 
41
	/**
42
 	 * Overwrite Header() method.
43
	 * @access public
44
	 */
45
	public function Header() {
46
		if ($this->tocpage) {
47
			// *** replace the following parent::Header() with your code for TOC page
48
			parent::Header();
49
		} else {
50
			// *** replace the following parent::Header() with your code for normal pages
51
			parent::Header();
52
		}
53
	}
54
 
55
	/**
56
 	 * Overwrite Footer() method.
57
	 * @access public
58
	 */
59
	public function Footer() {
60
		if ($this->tocpage) {
61
			// *** replace the following parent::Footer() with your code for TOC page
62
			parent::Footer();
63
		} else {
64
			// *** replace the following parent::Footer() with your code for normal pages
65
			parent::Footer();
66
		}
67
	}
68
 
69
} // end of class
70
 
71
// create new PDF document
72
$pdf = new TOC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
73
 
74
// set document information
75
$pdf->SetCreator(PDF_CREATOR);
76
$pdf->SetAuthor('Nicola Asuni');
77
$pdf->SetTitle('TCPDF Example 059');
78
$pdf->SetSubject('TCPDF Tutorial');
79
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
80
 
81
// set default header data
82
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 059', PDF_HEADER_STRING);
83
 
84
// set header and footer fonts
85
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
86
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
87
 
88
// set default monospaced font
89
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
90
 
91
//set margins
92
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
93
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
94
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
95
 
96
//set auto page breaks
97
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
98
 
99
//set image scale factor
100
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
101
 
102
//set some language-dependent strings
103
$pdf->setLanguageArray($l);
104
 
105
// set font
106
$pdf->SetFont('helvetica', '', 10);
107
 
108
// ---------------------------------------------------------
109
 
110
// create some content ...
111
 
112
// add a page
113
$pdf->AddPage();
114
 
115
// set a bookmark for the current position
116
$pdf->Bookmark('Chapter 1', 0, 0);
117
 
118
// print a line using Cell()
119
$pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
120
 
121
$pdf->AddPage();
122
$pdf->Bookmark('Paragraph 1.1', 1, 0);
123
$pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
124
 
125
$pdf->AddPage();
126
$pdf->Bookmark('Paragraph 1.2', 1, 0);
127
$pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
128
 
129
$pdf->AddPage();
130
$pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0);
131
$pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
132
 
133
$pdf->AddPage();
134
$pdf->Bookmark('Paragraph 1.3', 1, 0);
135
$pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
136
 
137
for ($i = 2; $i < 12; ++$i) {
138
	$pdf->AddPage();
139
	$pdf->Bookmark('Chapter '.$i, 0, 0);
140
	$pdf->Cell(0, 10, 'Chapter '.$i, 0, 1, 'L');
141
}
142
 
143
 
144
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
145
 
146
 
147
// add a new page for TOC
148
$pdf->addTOCPage();
149
 
150
// write the TOC title and/or other elements on the TOC page
151
$pdf->SetFont('times', 'B', 16);
152
$pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
153
$pdf->Ln();
154
$pdf->SetFont('helvetica', '', 10);
155
 
156
// define styles for various bookmark levels
157
$bookmark_templates = array();
158
 
159
/*
160
 * The key of the $bookmark_templates array represent the bookmark level (from 0 to n).
161
 * The following templates will be replaced with proper content:
162
 *     #TOC_DESCRIPTION#    this will be replaced with the bookmark description;
163
 *     #TOC_PAGE_NUMBER#    this will be replaced with page number.
164
 *
165
 * NOTES:
166
 *     If you want to align the page number on the right you have to use a monospaced font like courier, otherwise you can left align using any font type.
167
 *     The following is just an example, you can get various styles by combining various HTML elements.
168
 */
169
 
170
// A monospaced font for the page number is mandatory to get the right alignment
171
$bookmark_templates[0] = '<table border="0" cellpadding="0" cellspacing="0" style="background-color:#EEFAFF"><tr><td width="155mm"><span style="font-family:times;font-weight:bold;font-size:12pt;color:black;">#TOC_DESCRIPTION#</span></td><td width="25mm"><span style="font-family:courier;font-weight:bold;font-size:12pt;color:black;" align="right">#TOC_PAGE_NUMBER#</span></td></tr></table>';
172
$bookmark_templates[1] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="5mm">&nbsp;</td><td width="150mm"><span style="font-family:times;font-size:11pt;color:green;">#TOC_DESCRIPTION#</span></td><td width="25mm"><span style="font-family:courier;font-weight:bold;font-size:11pt;color:green;" align="right">#TOC_PAGE_NUMBER#</span></td></tr></table>';
173
$bookmark_templates[2] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="10mm">&nbsp;</td><td width="145mm"><span style="font-family:times;font-size:10pt;color:#666666;"><i>#TOC_DESCRIPTION#</i></span></td><td width="25mm"><span style="font-family:courier;font-weight:bold;font-size:10pt;color:#666666;" align="right">#TOC_PAGE_NUMBER#</span></td></tr></table>';
174
// add other bookmark level templates here ...
175
 
176
// add table of content at page 1
177
// (check the example n. 45 for a text-only TOC
178
$pdf->addHTMLTOC($page=1, $toc_name='INDEX', $bookmark_templates, $correct_align=true);
179
 
180
// end of TOC page
181
$pdf->endTOCPage();
182
 
183
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
184
 
185
// ---------------------------------------------------------
186
 
187
//Close and output PDF document
188
$pdf->Output('example_059.pdf', 'I');
189
 
190
//============================================================+
191
// END OF FILE
192
//============================================================+