1 | <?php
|
---|
2 | //============================================================+
|
---|
3 | // File name : example_045.php
|
---|
4 | // Begin : 2008-03-04
|
---|
5 | // Last Update : 2013-05-14
|
---|
6 | //
|
---|
7 | // Description : Example 045 for TCPDF class
|
---|
8 | // Bookmarks and Table of Content
|
---|
9 | //
|
---|
10 | // Author: Nicola Asuni
|
---|
11 | //
|
---|
12 | // (c) Copyright:
|
---|
13 | // Nicola Asuni
|
---|
14 | // Tecnick.com LTD
|
---|
15 | // www.tecnick.com
|
---|
16 | // info@tecnick.com
|
---|
17 | //============================================================+
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Creates an example PDF TEST document using TCPDF
|
---|
21 | * @package com.tecnick.tcpdf
|
---|
22 | * @abstract TCPDF - Example: Bookmarks and Table of Content
|
---|
23 | * @author Nicola Asuni
|
---|
24 | * @since 2008-03-04
|
---|
25 | */
|
---|
26 |
|
---|
27 | // Include the main TCPDF library (search for installation path).
|
---|
28 | require_once('tcpdf_include.php');
|
---|
29 |
|
---|
30 | // create new PDF document
|
---|
31 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
---|
32 |
|
---|
33 | // set document information
|
---|
34 | $pdf->SetCreator(PDF_CREATOR);
|
---|
35 | $pdf->SetAuthor('Nicola Asuni');
|
---|
36 | $pdf->SetTitle('TCPDF Example 045');
|
---|
37 | $pdf->SetSubject('TCPDF Tutorial');
|
---|
38 | $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
|
---|
39 |
|
---|
40 | // set default header data
|
---|
41 | $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 045', PDF_HEADER_STRING);
|
---|
42 |
|
---|
43 | // set header and footer fonts
|
---|
44 | $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
|
---|
45 | $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
|
---|
46 |
|
---|
47 | // set default monospaced font
|
---|
48 | $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
---|
49 |
|
---|
50 | // set margins
|
---|
51 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
---|
52 | $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
|
---|
53 | $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
|
---|
54 |
|
---|
55 | // set auto page breaks
|
---|
56 | $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
---|
57 |
|
---|
58 | // set image scale factor
|
---|
59 | $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
---|
60 |
|
---|
61 | // set some language-dependent strings (optional)
|
---|
62 | if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
|
---|
63 | require_once(dirname(__FILE__).'/lang/eng.php');
|
---|
64 | $pdf->setLanguageArray($l);
|
---|
65 | }
|
---|
66 |
|
---|
67 | // ---------------------------------------------------------
|
---|
68 |
|
---|
69 | // set font
|
---|
70 | $pdf->SetFont('times', 'B', 20);
|
---|
71 |
|
---|
72 | // add a page
|
---|
73 | $pdf->AddPage();
|
---|
74 |
|
---|
75 | // set a bookmark for the current position
|
---|
76 | $pdf->Bookmark('Chapter 1', 0, 0, '', 'B', array(0,64,128));
|
---|
77 |
|
---|
78 | // print a line using Cell()
|
---|
79 | $pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
|
---|
80 |
|
---|
81 | // Create a fixed link to the first page using the * character
|
---|
82 | $index_link = $pdf->AddLink();
|
---|
83 | $pdf->SetLink($index_link, 0, '*1');
|
---|
84 | $pdf->Cell(0, 10, 'Link to INDEX', 0, 1, 'R', false, $index_link);
|
---|
85 |
|
---|
86 | $pdf->AddPage();
|
---|
87 | $pdf->Bookmark('Paragraph 1.1', 1, 0, '', '', array(128,0,0));
|
---|
88 | $pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
|
---|
89 |
|
---|
90 | $pdf->AddPage();
|
---|
91 | $pdf->Bookmark('Paragraph 1.2', 1, 0, '', '', array(128,0,0));
|
---|
92 | $pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
|
---|
93 |
|
---|
94 | $pdf->AddPage();
|
---|
95 | $pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0, '', 'I', array(0,128,0));
|
---|
96 | $pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
|
---|
97 |
|
---|
98 | $pdf->AddPage();
|
---|
99 | $pdf->Bookmark('Paragraph 1.3', 1, 0, '', '', array(128,0,0));
|
---|
100 | $pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
|
---|
101 |
|
---|
102 | // fixed link to the first page using the * character
|
---|
103 | $html = '<a href="#*1" style="color:blue;">link to INDEX (page 1)</a>';
|
---|
104 | $pdf->writeHTML($html, true, false, true, false, '');
|
---|
105 |
|
---|
106 |
|
---|
107 | // add some pages and bookmarks
|
---|
108 | for ($i = 2; $i < 12; $i++) {
|
---|
109 | $pdf->AddPage();
|
---|
110 | $pdf->Bookmark('Chapter '.$i, 0, 0, '', 'B', array(0,64,128));
|
---|
111 | $pdf->Cell(0, 10, 'Chapter '.$i, 0, 1, 'L');
|
---|
112 | }
|
---|
113 |
|
---|
114 | // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
---|
115 |
|
---|
116 | // add a new page for TOC
|
---|
117 | $pdf->addTOCPage();
|
---|
118 |
|
---|
119 | // write the TOC title
|
---|
120 | $pdf->SetFont('times', 'B', 16);
|
---|
121 | $pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
|
---|
122 | $pdf->Ln();
|
---|
123 |
|
---|
124 | $pdf->SetFont('dejavusans', '', 12);
|
---|
125 |
|
---|
126 | // add a simple Table Of Content at first page
|
---|
127 | // (check the example n. 59 for the HTML version)
|
---|
128 | $pdf->addTOC(1, 'courier', '.', 'INDEX', 'B', array(128,0,0));
|
---|
129 |
|
---|
130 | // end of TOC page
|
---|
131 | $pdf->endTOCPage();
|
---|
132 |
|
---|
133 | // ---------------------------------------------------------
|
---|
134 |
|
---|
135 | //Close and output PDF document
|
---|
136 | $pdf->Output('example_045.pdf', 'I');
|
---|
137 |
|
---|
138 | //============================================================+
|
---|
139 | // END OF FILE
|
---|
140 | //============================================================+
|
---|