2
//============================================================+
3
// File name : example_059.php
5
// Last Update : 2010-09-13
7
// Description : Example 059 for TCPDF class
8
// Table Of Content using HTML templates.
10
// Author: Nicola Asuni
16
// 09044 Quartucciu (CA)
20
//============================================================+
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
30
require_once('../config/lang/eng.php');
31
require_once('../tcpdf.php');
34
* TCPDF class extension with custom header and footer for TOC page
36
class TOC_TCPDF extends TCPDF {
39
* Overwrite Header() method.
42
public function Header() {
44
// *** replace the following parent::Header() with your code for TOC page
47
// *** replace the following parent::Header() with your code for normal pages
53
* Overwrite Footer() method.
56
public function Footer() {
58
// *** replace the following parent::Footer() with your code for TOC page
61
// *** replace the following parent::Footer() with your code for normal pages
68
// create new PDF document
69
$pdf = new TOC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
71
// set document information
72
$pdf->SetCreator(PDF_CREATOR);
73
$pdf->SetAuthor('Nicola Asuni');
74
$pdf->SetTitle('TCPDF Example 059');
75
$pdf->SetSubject('TCPDF Tutorial');
76
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
78
// set default header data
79
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 059', PDF_HEADER_STRING);
81
// set header and footer fonts
82
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
83
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
85
// set default monospaced font
86
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
89
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
90
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
91
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
93
//set auto page breaks
94
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
96
//set image scale factor
97
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
99
//set some language-dependent strings
100
$pdf->setLanguageArray($l);
103
$pdf->SetFont('helvetica', '', 10);
105
// ---------------------------------------------------------
107
// create some content ...
112
// set a bookmark for the current position
113
$pdf->Bookmark('Chapter 1', 0, 0);
115
// print a line using Cell()
116
$pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
119
$pdf->Bookmark('Paragraph 1.1', 1, 0);
120
$pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
123
$pdf->Bookmark('Paragraph 1.2', 1, 0);
124
$pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
127
$pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0);
128
$pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
131
$pdf->Bookmark('Paragraph 1.3', 1, 0);
132
$pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
134
for ($i = 2; $i < 12; ++$i) {
136
$pdf->Bookmark('Chapter '.$i, 0, 0);
137
$pdf->Cell(0, 10, 'Chapter '.$i, 0, 1, 'L');
141
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
144
// add a new page for TOC
147
// write the TOC title and/or other elements on the TOC page
148
$pdf->SetFont('times', 'B', 16);
149
$pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
151
$pdf->SetFont('helvetica', '', 10);
153
// define styles for various bookmark levels
154
$bookmark_templates = array();
157
* The key of the $bookmark_templates array represent the bookmark level (from 0 to n).
158
* The following templates will be replaced with proper content:
159
* #TOC_DESCRIPTION# this will be replaced with the bookmark description;
160
* #TOC_PAGE_NUMBER# this will be replaced with page number.
163
* 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.
164
* The following is just an example, you can get various styles by combining various HTML elements.
167
// A monospaced font for the page number is mandatory to get the right alignment
168
$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>';
169
$bookmark_templates[1] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="5mm"> </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>';
170
$bookmark_templates[2] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="10mm"> </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>';
171
// add other bookmark level templates here ...
173
// add table of content at page 1
174
// (check the example n. 45 for a text-only TOC
175
$pdf->addHTMLTOC($page=1, $toc_name='INDEX', $bookmark_templates, $correct_align=true);
180
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
182
// ---------------------------------------------------------
184
//Close and output PDF document
185
$pdf->Output('example_059.pdf', 'I');
187
//============================================================+
189
//============================================================+