source: trunk/client/inc/hpdf5/tecnickcom/tcpdf/examples/example_030.php@ 430

Last change on this file since 430 was 347, checked in by roby, 4 years ago

Aggiornamento per compatibilità con php7.4

File size: 5.8 KB
Line 
1<?php
2//============================================================+
3// File name : example_030.php
4// Begin : 2008-06-09
5// Last Update : 2013-05-14
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 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: Colour gradients
23 * @author Nicola Asuni
24 * @since 2008-06-09
25 */
26
27// Include the main TCPDF library (search for installation path).
28require_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 030');
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.' 030', 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)
62if (@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('helvetica', 'B', 20);
71
72// --- first page ------------------------------------------
73
74// add a page
75$pdf->AddPage();
76
77$pdf->Cell(0, 0, 'TCPDF Gradients', 0, 1, 'C', 0, '', 0, false, 'T', 'M');
78
79// set colors for gradients (r,g,b) or (grey 0-255)
80$red = array(255, 0, 0);
81$blue = array(0, 0, 200);
82$yellow = array(255, 255, 0);
83$green = array(0, 255, 0);
84$white = array(255);
85$black = array(0);
86
87// set the coordinates x1,y1,x2,y2 of the gradient (see linear_gradient_coords.jpg)
88$coords = array(0, 0, 1, 0);
89
90// paint a linear gradient
91$pdf->LinearGradient(20, 45, 80, 80, $red, $blue, $coords);
92
93// write label
94$pdf->Text(20, 130, 'LinearGradient()');
95
96// set the coordinates fx,fy,cx,cy,r of the gradient (see radial_gradient_coords.jpg)
97$coords = array(0.5, 0.5, 1, 1, 1.2);
98
99// paint a radial gradient
100$pdf->RadialGradient(110, 45, 80, 80, $white, $black, $coords);
101
102// write label
103$pdf->Text(110, 130, 'RadialGradient()');
104
105// paint a coons patch mesh with default coordinates
106$pdf->CoonsPatchMesh(20, 155, 80, 80, $yellow, $blue, $green, $red);
107
108// write label
109$pdf->Text(20, 240, 'CoonsPatchMesh()');
110
111// set the coordinates for the cubic Bézier points x1,y1 ... x12, y12 of the patch (see coons_patch_mesh_coords.jpg)
112$coords = array(
113 0.00,0.00, 0.33,0.20, //lower left
114 0.67,0.00, 1.00,0.00, 0.80,0.33, //lower right
115 0.80,0.67, 1.00,1.00, 0.67,0.80, //upper right
116 0.33,1.00, 0.00,1.00, 0.20,0.67, //upper left
117 0.00,0.33); //lower left
118$coords_min = 0; //minimum value of the coordinates
119$coords_max = 1; //maximum value of the coordinates
120
121// paint a coons patch gradient with the above coordinates
122$pdf->CoonsPatchMesh(110, 155, 80, 80, $yellow, $blue, $green, $red, $coords, $coords_min, $coords_max);
123
124// write label
125$pdf->Text(110, 240, 'CoonsPatchMesh()');
126
127// --- second page -----------------------------------------
128$pdf->AddPage();
129
130// first patch: f = 0
131$patch_array[0]['f'] = 0;
132$patch_array[0]['points'] = array(
133 0.00,0.00, 0.33,0.00,
134 0.67,0.00, 1.00,0.00, 1.00,0.33,
135 0.8,0.67, 1.00,1.00, 0.67,0.8,
136 0.33,1.80, 0.00,1.00, 0.00,0.67,
137 0.00,0.33);
138$patch_array[0]['colors'][0] = array('r' => 255, 'g' => 255, 'b' => 0);
139$patch_array[0]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
140$patch_array[0]['colors'][2] = array('r' => 0, 'g' => 255,'b' => 0);
141$patch_array[0]['colors'][3] = array('r' => 255, 'g' => 0,'b' => 0);
142
143// second patch - above the other: f = 2
144$patch_array[1]['f'] = 2;
145$patch_array[1]['points'] = array(
146 0.00,1.33,
147 0.00,1.67, 0.00,2.00, 0.33,2.00,
148 0.67,2.00, 1.00,2.00, 1.00,1.67,
149 1.5,1.33);
150$patch_array[1]['colors'][0]=array('r' => 0, 'g' => 0, 'b' => 0);
151$patch_array[1]['colors'][1]=array('r' => 255, 'g' => 0, 'b' => 255);
152
153// third patch - right of the above: f = 3
154$patch_array[2]['f'] = 3;
155$patch_array[2]['points'] = array(
156 1.33,0.80,
157 1.67,1.50, 2.00,1.00, 2.00,1.33,
158 2.00,1.67, 2.00,2.00, 1.67,2.00,
159 1.33,2.00);
160$patch_array[2]['colors'][0] = array('r' => 0, 'g' => 255, 'b' => 255);
161$patch_array[2]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 0);
162
163// fourth patch - below the above, which means left(?) of the above: f = 1
164$patch_array[3]['f'] = 1;
165$patch_array[3]['points'] = array(
166 2.00,0.67,
167 2.00,0.33, 2.00,0.00, 1.67,0.00,
168 1.33,0.00, 1.00,0.00, 1.00,0.33,
169 0.8,0.67);
170$patch_array[3]['colors'][0] = array('r' => 0, 'g' => 0, 'b' => 0);
171$patch_array[3]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
172
173$coords_min = 0;
174$coords_max = 2;
175
176$pdf->CoonsPatchMesh(10, 45, 190, 200, '', '', '', '', $patch_array, $coords_min, $coords_max);
177
178// write label
179$pdf->Text(10, 250, 'CoonsPatchMesh()');
180
181// ---------------------------------------------------------
182
183//Close and output PDF document
184$pdf->Output('example_030.pdf', 'D');
185
186//============================================================+
187// END OF FILE
188//============================================================+
Note: See TracBrowser for help on using the repository browser.