2
//============================================================+
3
// File name : example_045.php
5
// Last Update : 2010-08-08
7
// Description : Example 045 for TCPDF class
8
// Bookmarks and Table of Content
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: Bookmarks and Table of Content
26
* @author Nicola Asuni
30
require_once('../config/lang/eng.php');
31
require_once('../tcpdf.php');
33
// create new PDF document
34
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
36
// set document information
37
$pdf->SetCreator(PDF_CREATOR);
38
$pdf->SetAuthor('Nicola Asuni');
39
$pdf->SetTitle('TCPDF Example 045');
40
$pdf->SetSubject('TCPDF Tutorial');
41
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
43
// set default header data
44
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 045', PDF_HEADER_STRING);
46
// set header and footer fonts
47
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
48
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
50
// set default monospaced font
51
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
54
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
55
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
56
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
58
//set auto page breaks
59
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
61
//set image scale factor
62
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
64
//set some language-dependent strings
65
$pdf->setLanguageArray($l);
67
// ---------------------------------------------------------
70
$pdf->SetFont('times', 'B', 20);
75
// set a bookmark for the current position
76
$pdf->Bookmark('Chapter 1', 0, 0);
78
// print a line using Cell()
79
$pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
82
$pdf->Bookmark('Paragraph 1.1', 1, 0);
83
$pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
86
$pdf->Bookmark('Paragraph 1.2', 1, 0);
87
$pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
90
$pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0);
91
$pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
94
$pdf->Bookmark('Paragraph 1.3', 1, 0);
95
$pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
97
// add some pages and bookmarks
98
for ($i = 2; $i < 12; $i++) {
100
$pdf->Bookmark('Chapter '.$i, 0, 0);
101
$pdf->Cell(0, 10, 'Chapter '.$i, 0, 1, 'L');
104
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
106
// add a new page for TOC
109
// write the TOC title
110
$pdf->SetFont('times', 'B', 16);
111
$pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
114
$pdf->SetFont('dejavusans', '', 12);
116
// add a simple Table Of Content at first page
117
// (check the example n. 59 for the HTML version)
118
$pdf->addTOC(1, 'courier', '.', 'INDEX');
123
// ---------------------------------------------------------
125
//Close and output PDF document
126
$pdf->Output('example_045.pdf', 'I');
128
//============================================================+
130
//============================================================+