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_011.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-08-08
6
//
7
// Description : Example 011 for TCPDF class
8
//               Colored Table
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: Colored Table
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
// extend TCPF with custom functions
37
class MYPDF extends TCPDF {
38
 
39
	// Load table data from file
40
	public function LoadData($file) {
41
		// Read file lines
42
		$lines = file($file);
43
		$data = array();
44
		foreach($lines as $line) {
45
			$data[] = explode(';', chop($line));
46
		}
47
		return $data;
48
	}
49
 
50
	// Colored table
51
	public function ColoredTable($header,$data) {
52
		// Colors, line width and bold font
53
		$this->SetFillColor(255, 0, 0);
54
		$this->SetTextColor(255);
55
		$this->SetDrawColor(128, 0, 0);
56
		$this->SetLineWidth(0.3);
57
		$this->SetFont('', 'B');
58
		// Header
59
		$w = array(40, 35, 40, 45);
60
		$num_headers = count($header);
61
		for($i = 0; $i < $num_headers; ++$i) {
62
			$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
63
		}
64
		$this->Ln();
65
		// Color and font restoration
66
		$this->SetFillColor(224, 235, 255);
67
		$this->SetTextColor(0);
68
		$this->SetFont('');
69
		// Data
70
		$fill = 0;
71
		foreach($data as $row) {
72
			$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
73
			$this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
74
			$this->Cell($w[2], 6, number_format($row[2]), 'LR', 0, 'R', $fill);
75
			$this->Cell($w[3], 6, number_format($row[3]), 'LR', 0, 'R', $fill);
76
			$this->Ln();
77
			$fill=!$fill;
78
		}
79
		$this->Cell(array_sum($w), 0, '', 'T');
80
	}
81
}
82
 
83
// create new PDF document
84
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
85
 
86
// set document information
87
$pdf->SetCreator(PDF_CREATOR);
88
$pdf->SetAuthor('Nicola Asuni');
89
$pdf->SetTitle('TCPDF Example 011');
90
$pdf->SetSubject('TCPDF Tutorial');
91
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
92
 
93
// set default header data
94
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 011', PDF_HEADER_STRING);
95
 
96
// set header and footer fonts
97
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
98
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
99
 
100
// set default monospaced font
101
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
102
 
103
//set margins
104
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
105
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
106
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
107
 
108
//set auto page breaks
109
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
110
 
111
//set image scale factor
112
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
113
 
114
//set some language-dependent strings
115
$pdf->setLanguageArray($l);
116
 
117
// ---------------------------------------------------------
118
 
119
// set font
120
$pdf->SetFont('helvetica', '', 12);
121
 
122
// add a page
123
$pdf->AddPage();
124
 
125
//Column titles
126
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
127
 
128
//Data loading
129
$data = $pdf->LoadData('../cache/table_data_demo.txt');
130
 
131
// print colored table
132
$pdf->ColoredTable($header, $data);
133
 
134
// ---------------------------------------------------------
135
 
136
//Close and output PDF document
137
$pdf->Output('example_011.pdf', 'I');
138
 
139
//============================================================+
140
// END OF FILE
141
//============================================================+