Subversion Repositories Applications.annuaire

Rev

Rev 296 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_020.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-08-08
6
//
7
// Description : Example 020 for TCPDF class
8
//               Two columns composed by MultiCell of different
9
//               heights
10
//
11
// Author: Nicola Asuni
12
//
13
// (c) Copyright:
14
//               Nicola Asuni
15
//               Tecnick.com s.r.l.
16
//               Via Della Pace, 11
17
//               09044 Quartucciu (CA)
18
//               ITALY
19
//               www.tecnick.com
20
//               info@tecnick.com
21
//============================================================+
22
 
23
/**
24
* Creates an example PDF TEST document using TCPDF
25
* @package com.tecnick.tcpdf
26
* @abstract TCPDF - Example: Two columns composed by MultiCell of different heights
27
* @author Nicola Asuni
28
* @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
29
* @link http://tcpdf.org
30
* @license http://www.gnu.org/copyleft/lesser.html LGPL
31
* @since 2008-03-04
32
*/
33
 
34
require_once('../config/lang/eng.php');
35
require_once('../tcpdf.php');
36
 
37
// extend TCPF with custom functions
38
class MYPDF extends TCPDF {
39
 
40
	public function MultiRow($left, $right) {
41
		// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
42
 
43
		$page_start = $this->getPage();
44
		$y_start = $this->GetY();
45
 
46
		// write the left cell
47
		$this->MultiCell(40, 0, $left, 1, 'R', 1, 2, '', '', true, 0);
48
 
49
		$page_end_1 = $this->getPage();
50
		$y_end_1 = $this->GetY();
51
 
52
		$this->setPage($page_start);
53
 
54
		// write the right cell
55
		$this->MultiCell(0, 0, $right, 1, 'J', 0, 1, $this->GetX() ,$y_start, true, 0);
56
 
57
		$page_end_2 = $this->getPage();
58
		$y_end_2 = $this->GetY();
59
 
60
		// set the new row position by case
61
		if (max($page_end_1,$page_end_2) == $page_start) {
62
			$ynew = max($y_end_1, $y_end_2);
63
		} elseif ($page_end_1 == $page_end_2) {
64
			$ynew = max($y_end_1, $y_end_2);
65
		} elseif ($page_end_1 > $page_end_2) {
66
			$ynew = $y_end_1;
67
		} else {
68
			$ynew = $y_end_2;
69
		}
70
 
71
		$this->setPage(max($page_end_1,$page_end_2));
72
		$this->SetXY($this->GetX(),$ynew);
73
	}
74
 
75
}
76
 
77
// create new PDF document
78
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
79
 
80
// set document information
81
$pdf->SetCreator(PDF_CREATOR);
82
$pdf->SetAuthor('Nicola Asuni');
83
$pdf->SetTitle('TCPDF Example 020');
84
$pdf->SetSubject('TCPDF Tutorial');
85
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
86
 
87
// set default header data
88
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 020', PDF_HEADER_STRING);
89
 
90
// set header and footer fonts
91
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
92
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
93
 
94
// set default monospaced font
95
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
96
 
97
//set margins
98
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
99
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
100
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
101
 
102
//set auto page breaks
103
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
104
 
105
//set image scale factor
106
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
107
 
108
//set some language-dependent strings
109
$pdf->setLanguageArray($l);
110
 
111
// ---------------------------------------------------------
112
 
113
// set font
114
$pdf->SetFont('helvetica', '', 20);
115
// add a page
116
$pdf->AddPage();
117
 
118
$pdf->Write(0, 'Example of text layout using Multicell()', '', 0, 'L', true, 0, false, false, 0);
119
 
120
$pdf->Ln(5);
121
 
122
$pdf->SetFont('times', '', 9);
123
 
124
//$pdf->SetCellPadding(0);
125
//$pdf->SetLineWidth(2);
126
 
127
// set color for background
128
$pdf->SetFillColor(255, 255, 200);
129
 
130
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus. Phasellus quis velit velit, non condimentum quam. Sed neque urna, ultrices ac volutpat vel, laoreet vitae augue. Sed vel velit erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras eget velit nulla, eu sagittis elit. Nunc ac arcu est, in lobortis tellus. Praesent condimentum rhoncus sodales. In hac habitasse platea dictumst. Proin porta eros pharetra enim tincidunt dignissim nec vel dolor. Cras sapien elit, ornare ac dignissim eu, ultricies ac eros. Maecenas augue magna, ultrices a congue in, mollis eu nulla. Nunc venenatis massa at est eleifend faucibus. Vivamus sed risus lectus, nec interdum nunc.
131
 
132
Fusce et felis vitae diam lobortis sollicitudin. Aenean tincidunt accumsan nisi, id vehicula quam laoreet elementum. Phasellus egestas interdum erat, et viverra ipsum ultricies ac. Praesent sagittis augue at augue volutpat eleifend. Cras nec orci neque. Mauris bibendum posuere blandit. Donec feugiat mollis dui sit amet pellentesque. Sed a enim justo. Donec tincidunt, nisl eget elementum aliquam, odio ipsum ultrices quam, eu porttitor ligula urna at lorem. Donec varius, eros et convallis laoreet, ligula tellus consequat felis, ut ornare metus tellus sodales velit. Duis sed diam ante. Ut rutrum malesuada massa, vitae consectetur ipsum rhoncus sed. Suspendisse potenti. Pellentesque a congue massa.';
133
 
134
// print some rows just as example
135
for ($i = 0; $i < 10; ++$i) {
136
	$pdf->MultiRow('Row '.($i+1), $text."\n");
137
}
138
 
139
// reset pointer to the last page
140
$pdf->lastPage();
141
 
142
// ---------------------------------------------------------
143
 
144
//Close and output PDF document
145
$pdf->Output('example_020.pdf', 'I');
146
 
147
//============================================================+
148
// END OF FILE
149
//============================================================+