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_010.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-08-11
6
//
7
// Description : Example 010 for TCPDF class
8
//               Text on multiple columns
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: Text on multiple columns
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
/**
38
 * Extend TCPDF to work with multiple columns
39
 */
40
class MC_TCPDF extends TCPDF {
41
 
42
	/**
43
	 * Print chapter
44
	 * @param int $num chapter number
45
	 * @param string $title chapter title
46
	 * @param string $file name of the file containing the chapter body
47
	 * @param boolean $mode if true the chapter body is in HTML, otherwise in simple text.
48
	 * @access public
49
	 */
50
	public function PrintChapter($num, $title, $file, $mode=false) {
51
		// disable existing columns
52
		$this->setEqualColumns();
53
		// add a new page
54
		$this->AddPage();
55
		// reset margins
56
		$this->selectColumn();
57
		// print chapter title
58
		$this->ChapterTitle($num, $title);
59
		// set columns
60
		$this->setEqualColumns(3, 57);
61
		// print chapter body
62
		$this->ChapterBody($file, $mode);
63
	}
64
 
65
	/**
66
	 * Set chapter title
67
	 * @param int $num chapter number
68
	 * @param string $title chapter title
69
	 * @access public
70
	 */
71
	public function ChapterTitle($num, $title) {
72
		$this->SetFont('helvetica', '', 14);
73
		$this->SetFillColor(200, 220, 255);
74
		$this->Cell(180, 6, 'Chapter '.$num.' : '.$title, 0, 1, '', 1);
75
		$this->Ln(4);
76
	}
77
 
78
	/**
79
	 * Print chapter body
80
	 * @param string $file name of the file containing the chapter body
81
	 * @param boolean $mode if true the chapter body is in HTML, otherwise in simple text.
82
	 * @access public
83
	 */
84
	public function ChapterBody($file, $mode=false) {
85
		$this->selectColumn();
86
		// get esternal file content
87
		$content = file_get_contents($file, false);
88
		// set font
89
		$this->SetFont('times', '', 9);
90
		$this->SetTextColor(50, 50, 50);
91
		// print content
92
		if ($mode) {
93
			// ------ HTML MODE ------
94
			$this->writeHTML($content, true, false, true, false, 'J');
95
		} else {
96
			// ------ TEXT MODE ------
97
			$this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0);
98
		}
99
		$this->Ln();
100
	}
101
} // end of extended class
102
 
103
// ---------------------------------------------------------
104
// EXAMPLE
105
// ---------------------------------------------------------
106
// create new PDF document
107
$pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
108
 
109
// set document information
110
$pdf->SetCreator(PDF_CREATOR);
111
$pdf->SetAuthor('Nicola Asuni');
112
$pdf->SetTitle('TCPDF Example 010');
113
$pdf->SetSubject('TCPDF Tutorial');
114
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
115
 
116
// set default header data
117
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 010', PDF_HEADER_STRING);
118
 
119
// set header and footer fonts
120
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
121
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
122
 
123
// set default monospaced font
124
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
125
 
126
//set margins
127
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
128
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
129
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
130
 
131
//set auto page breaks
132
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
133
 
134
//set image scale factor
135
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
136
 
137
//set some language-dependent strings
138
$pdf->setLanguageArray($l);
139
 
140
// ---------------------------------------------------------
141
 
142
// print TEXT
143
$pdf->PrintChapter(1, 'LOREM IPSUM [TEXT]', '../cache/chapter_demo_1.txt', false);
144
 
145
// print HTML
146
$pdf->PrintChapter(2, 'LOREM IPSUM [HTML]', '../cache/chapter_demo_2.txt', true);
147
 
148
// ---------------------------------------------------------
149
 
150
//Close and output PDF document
151
$pdf->Output('example_010.pdf', 'I');
152
 
153
//============================================================+
154
// END OF FILE
155
//============================================================+