296 |
aurelien |
1 |
<?php
|
|
|
2 |
//============================================================+
|
|
|
3 |
// File name : example_030.php
|
|
|
4 |
// Begin : 2008-06-09
|
|
|
5 |
// Last Update : 2010-08-08
|
|
|
6 |
//
|
|
|
7 |
// Description : Example 030 for TCPDF class
|
|
|
8 |
// Colour gradients
|
|
|
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: Colour gradients
|
|
|
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-06-09
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
require_once('../config/lang/eng.php');
|
|
|
34 |
require_once('../tcpdf.php');
|
|
|
35 |
|
|
|
36 |
// create new PDF document
|
|
|
37 |
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
|
|
38 |
|
|
|
39 |
// set document information
|
|
|
40 |
$pdf->SetCreator(PDF_CREATOR);
|
|
|
41 |
$pdf->SetAuthor('Nicola Asuni');
|
|
|
42 |
$pdf->SetTitle('TCPDF Example 030');
|
|
|
43 |
$pdf->SetSubject('TCPDF Tutorial');
|
|
|
44 |
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
|
|
|
45 |
|
|
|
46 |
// set default header data
|
|
|
47 |
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 030', PDF_HEADER_STRING);
|
|
|
48 |
|
|
|
49 |
// set header and footer fonts
|
|
|
50 |
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
|
|
|
51 |
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
|
|
|
52 |
|
|
|
53 |
// set default monospaced font
|
|
|
54 |
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
55 |
|
|
|
56 |
//set margins
|
|
|
57 |
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
58 |
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
|
|
|
59 |
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
|
|
|
60 |
|
|
|
61 |
//set auto page breaks
|
|
|
62 |
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
63 |
|
|
|
64 |
//set image scale factor
|
|
|
65 |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
66 |
|
|
|
67 |
//set some language-dependent strings
|
|
|
68 |
$pdf->setLanguageArray($l);
|
|
|
69 |
|
|
|
70 |
// ---------------------------------------------------------
|
|
|
71 |
|
|
|
72 |
// set font
|
|
|
73 |
$pdf->SetFont('helvetica', 'B', 20);
|
|
|
74 |
|
|
|
75 |
// --- first page ------------------------------------------
|
|
|
76 |
|
|
|
77 |
// add a page
|
|
|
78 |
$pdf->AddPage();
|
|
|
79 |
|
|
|
80 |
$pdf->Cell(0, 0, 'TCPDF Gradients', 0, 1, 'C', 0, '', 0, false, 'T', 'M');
|
|
|
81 |
|
|
|
82 |
// set colors for gradients (r,g,b) or (grey 0-255)
|
|
|
83 |
$red = array(255, 0, 0);
|
|
|
84 |
$blue = array(0, 0, 200);
|
|
|
85 |
$yellow = array(255, 255, 0);
|
|
|
86 |
$green = array(0, 255, 0);
|
|
|
87 |
$white = array(255);
|
|
|
88 |
$black = array(0);
|
|
|
89 |
|
|
|
90 |
// set the coordinates x1,y1,x2,y2 of the gradient (see linear_gradient_coords.jpg)
|
|
|
91 |
$coords = array(0, 0, 1, 0);
|
|
|
92 |
|
|
|
93 |
// paint a linear gradient
|
|
|
94 |
$pdf->LinearGradient(20, 45, 80, 80, $red, $blue, $coords);
|
|
|
95 |
|
|
|
96 |
// write label
|
|
|
97 |
$pdf->Text(20, 130, 'LinearGradient()');
|
|
|
98 |
|
|
|
99 |
// set the coordinates fx,fy,cx,cy,r of the gradient (see radial_gradient_coords.jpg)
|
|
|
100 |
$coords = array(0.5, 0.5, 1, 1, 1.2);
|
|
|
101 |
|
|
|
102 |
// paint a radial gradient
|
|
|
103 |
$pdf->RadialGradient(110, 45, 80, 80, $white, $black, $coords);
|
|
|
104 |
|
|
|
105 |
// write label
|
|
|
106 |
$pdf->Text(110, 130, 'RadialGradient()');
|
|
|
107 |
|
|
|
108 |
// paint a coons patch mesh with default coordinates
|
|
|
109 |
$pdf->CoonsPatchMesh(20, 155, 80, 80, $yellow, $blue, $green, $red);
|
|
|
110 |
|
|
|
111 |
// write label
|
|
|
112 |
$pdf->Text(20, 240, 'CoonsPatchMesh()');
|
|
|
113 |
|
|
|
114 |
// set the coordinates for the cubic Bézier points x1,y1 ... x12, y12 of the patch (see coons_patch_mesh_coords.jpg)
|
|
|
115 |
$coords = array(
|
|
|
116 |
0.00,0.00, 0.33,0.20, //lower left
|
|
|
117 |
0.67,0.00, 1.00,0.00, 0.80,0.33, //lower right
|
|
|
118 |
0.80,0.67, 1.00,1.00, 0.67,0.80, //upper right
|
|
|
119 |
0.33,1.00, 0.00,1.00, 0.20,0.67, //upper left
|
|
|
120 |
0.00,0.33); //lower left
|
|
|
121 |
$coords_min = 0; //minimum value of the coordinates
|
|
|
122 |
$coords_max = 1; //maximum value of the coordinates
|
|
|
123 |
|
|
|
124 |
// paint a coons patch gradient with the above coordinates
|
|
|
125 |
$pdf->CoonsPatchMesh(110, 155, 80, 80, $yellow, $blue, $green, $red, $coords, $coords_min, $coords_max);
|
|
|
126 |
|
|
|
127 |
// write label
|
|
|
128 |
$pdf->Text(110, 240, 'CoonsPatchMesh()');
|
|
|
129 |
|
|
|
130 |
// --- second page -----------------------------------------
|
|
|
131 |
$pdf->AddPage();
|
|
|
132 |
|
|
|
133 |
// first patch: f = 0
|
|
|
134 |
$patch_array[0]['f'] = 0;
|
|
|
135 |
$patch_array[0]['points'] = array(
|
|
|
136 |
0.00,0.00, 0.33,0.00,
|
|
|
137 |
0.67,0.00, 1.00,0.00, 1.00,0.33,
|
|
|
138 |
0.8,0.67, 1.00,1.00, 0.67,0.8,
|
|
|
139 |
0.33,1.80, 0.00,1.00, 0.00,0.67,
|
|
|
140 |
0.00,0.33);
|
|
|
141 |
$patch_array[0]['colors'][0] = array('r' => 255, 'g' => 255, 'b' => 0);
|
|
|
142 |
$patch_array[0]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
|
|
|
143 |
$patch_array[0]['colors'][2] = array('r' => 0, 'g' => 255,'b' => 0);
|
|
|
144 |
$patch_array[0]['colors'][3] = array('r' => 255, 'g' => 0,'b' => 0);
|
|
|
145 |
|
|
|
146 |
// second patch - above the other: f = 2
|
|
|
147 |
$patch_array[1]['f'] = 2;
|
|
|
148 |
$patch_array[1]['points'] = array(
|
|
|
149 |
0.00,1.33,
|
|
|
150 |
0.00,1.67, 0.00,2.00, 0.33,2.00,
|
|
|
151 |
0.67,2.00, 1.00,2.00, 1.00,1.67,
|
|
|
152 |
1.5,1.33);
|
|
|
153 |
$patch_array[1]['colors'][0]=array('r' => 0, 'g' => 0, 'b' => 0);
|
|
|
154 |
$patch_array[1]['colors'][1]=array('r' => 255, 'g' => 0, 'b' => 255);
|
|
|
155 |
|
|
|
156 |
// third patch - right of the above: f = 3
|
|
|
157 |
$patch_array[2]['f'] = 3;
|
|
|
158 |
$patch_array[2]['points'] = array(
|
|
|
159 |
1.33,0.80,
|
|
|
160 |
1.67,1.50, 2.00,1.00, 2.00,1.33,
|
|
|
161 |
2.00,1.67, 2.00,2.00, 1.67,2.00,
|
|
|
162 |
1.33,2.00);
|
|
|
163 |
$patch_array[2]['colors'][0] = array('r' => 0, 'g' => 255, 'b' => 255);
|
|
|
164 |
$patch_array[2]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 0);
|
|
|
165 |
|
|
|
166 |
// fourth patch - below the above, which means left(?) of the above: f = 1
|
|
|
167 |
$patch_array[3]['f'] = 1;
|
|
|
168 |
$patch_array[3]['points'] = array(
|
|
|
169 |
2.00,0.67,
|
|
|
170 |
2.00,0.33, 2.00,0.00, 1.67,0.00,
|
|
|
171 |
1.33,0.00, 1.00,0.00, 1.00,0.33,
|
|
|
172 |
0.8,0.67);
|
|
|
173 |
$patch_array[3]['colors'][0] = array('r' => 0, 'g' => 0, 'b' => 0);
|
|
|
174 |
$patch_array[3]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
|
|
|
175 |
|
|
|
176 |
$coords_min = 0;
|
|
|
177 |
$coords_max = 2;
|
|
|
178 |
|
|
|
179 |
$pdf->CoonsPatchMesh(10, 45, 190, 200, '', '', '', '', $patch_array, $coords_min, $coords_max);
|
|
|
180 |
|
|
|
181 |
// write label
|
|
|
182 |
$pdf->Text(10, 250, 'CoonsPatchMesh()');
|
|
|
183 |
|
|
|
184 |
// ---------------------------------------------------------
|
|
|
185 |
|
|
|
186 |
//Close and output PDF document
|
|
|
187 |
$pdf->Output('example_030.pdf', 'I');
|
|
|
188 |
|
|
|
189 |
//============================================================+
|
|
|
190 |
// END OF FILE
|
|
|
191 |
//============================================================+
|