296 |
aurelien |
1 |
<?php
|
|
|
2 |
//============================================================+
|
|
|
3 |
// File name : example_013.php
|
|
|
4 |
// Begin : 2008-03-04
|
|
|
5 |
// Last Update : 2010-08-08
|
|
|
6 |
//
|
|
|
7 |
// Description : Example 013 for TCPDF class
|
|
|
8 |
// Graphic Transformations
|
|
|
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: Graphic Transformations
|
|
|
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 |
// 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 013');
|
|
|
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.' 013', 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 |
// add a page
|
|
|
76 |
$pdf->AddPage();
|
|
|
77 |
|
|
|
78 |
$pdf->Write(0, 'Graphic Transformations', '', 0, 'C', 1, 0, false, false, 0);
|
|
|
79 |
|
|
|
80 |
// set font
|
|
|
81 |
$pdf->SetFont('helvetica', '', 10);
|
|
|
82 |
|
|
|
83 |
// --- Scaling ---------------------------------------------
|
|
|
84 |
$pdf->SetDrawColor(200);
|
|
|
85 |
$pdf->SetTextColor(200);
|
|
|
86 |
$pdf->Rect(50, 70, 40, 10, 'D');
|
|
|
87 |
$pdf->Text(50, 66, 'Scale');
|
|
|
88 |
$pdf->SetDrawColor(0);
|
|
|
89 |
$pdf->SetTextColor(0);
|
|
|
90 |
// Start Transformation
|
|
|
91 |
$pdf->StartTransform();
|
|
|
92 |
// Scale by 150% centered by (50,80) which is the lower left corner of the rectangle
|
|
|
93 |
$pdf->ScaleXY(150, 50, 80);
|
|
|
94 |
$pdf->Rect(50, 70, 40, 10, 'D');
|
|
|
95 |
$pdf->Text(50, 66, 'Scale');
|
|
|
96 |
// Stop Transformation
|
|
|
97 |
$pdf->StopTransform();
|
|
|
98 |
|
|
|
99 |
// --- Translation -----------------------------------------
|
|
|
100 |
$pdf->SetDrawColor(200);
|
|
|
101 |
$pdf->SetTextColor(200);
|
|
|
102 |
$pdf->Rect(125, 70, 40, 10, 'D');
|
|
|
103 |
$pdf->Text(125, 66, 'Translate');
|
|
|
104 |
$pdf->SetDrawColor(0);
|
|
|
105 |
$pdf->SetTextColor(0);
|
|
|
106 |
// Start Transformation
|
|
|
107 |
$pdf->StartTransform();
|
|
|
108 |
// Translate 7 to the right, 5 to the bottom
|
|
|
109 |
$pdf->Translate(7, 5);
|
|
|
110 |
$pdf->Rect(125, 70, 40, 10, 'D');
|
|
|
111 |
$pdf->Text(125, 66, 'Translate');
|
|
|
112 |
// Stop Transformation
|
|
|
113 |
$pdf->StopTransform();
|
|
|
114 |
|
|
|
115 |
// --- Rotation --------------------------------------------
|
|
|
116 |
$pdf->SetDrawColor(200);
|
|
|
117 |
$pdf->SetTextColor(200);
|
|
|
118 |
$pdf->Rect(70, 100, 40, 10, 'D');
|
|
|
119 |
$pdf->Text(70, 96, 'Rotate');
|
|
|
120 |
$pdf->SetDrawColor(0);
|
|
|
121 |
$pdf->SetTextColor(0);
|
|
|
122 |
// Start Transformation
|
|
|
123 |
$pdf->StartTransform();
|
|
|
124 |
// Rotate 20 degrees counter-clockwise centered by (70,110) which is the lower left corner of the rectangle
|
|
|
125 |
$pdf->Rotate(20, 70, 110);
|
|
|
126 |
$pdf->Rect(70, 100, 40, 10, 'D');
|
|
|
127 |
$pdf->Text(70, 96, 'Rotate');
|
|
|
128 |
// Stop Transformation
|
|
|
129 |
$pdf->StopTransform();
|
|
|
130 |
|
|
|
131 |
// --- Skewing ---------------------------------------------
|
|
|
132 |
$pdf->SetDrawColor(200);
|
|
|
133 |
$pdf->SetTextColor(200);
|
|
|
134 |
$pdf->Rect(125, 100, 40, 10, 'D');
|
|
|
135 |
$pdf->Text(125, 96, 'Skew');
|
|
|
136 |
$pdf->SetDrawColor(0);
|
|
|
137 |
$pdf->SetTextColor(0);
|
|
|
138 |
// Start Transformation
|
|
|
139 |
$pdf->StartTransform();
|
|
|
140 |
// skew 30 degrees along the x-axis centered by (125,110) which is the lower left corner of the rectangle
|
|
|
141 |
$pdf->SkewX(30, 125, 110);
|
|
|
142 |
$pdf->Rect(125, 100, 40, 10, 'D');
|
|
|
143 |
$pdf->Text(125, 96, 'Skew');
|
|
|
144 |
// Stop Transformation
|
|
|
145 |
$pdf->StopTransform();
|
|
|
146 |
|
|
|
147 |
// --- Mirroring horizontally ------------------------------
|
|
|
148 |
$pdf->SetDrawColor(200);
|
|
|
149 |
$pdf->SetTextColor(200);
|
|
|
150 |
$pdf->Rect(70, 130, 40, 10, 'D');
|
|
|
151 |
$pdf->Text(70, 126, 'MirrorH');
|
|
|
152 |
$pdf->SetDrawColor(0);
|
|
|
153 |
$pdf->SetTextColor(0);
|
|
|
154 |
// Start Transformation
|
|
|
155 |
$pdf->StartTransform();
|
|
|
156 |
// mirror horizontally with axis of reflection at x-position 70 (left side of the rectangle)
|
|
|
157 |
$pdf->MirrorH(70);
|
|
|
158 |
$pdf->Rect(70, 130, 40, 10, 'D');
|
|
|
159 |
$pdf->Text(70, 126, 'MirrorH');
|
|
|
160 |
// Stop Transformation
|
|
|
161 |
$pdf->StopTransform();
|
|
|
162 |
|
|
|
163 |
// --- Mirroring vertically --------------------------------
|
|
|
164 |
$pdf->SetDrawColor(200);
|
|
|
165 |
$pdf->SetTextColor(200);
|
|
|
166 |
$pdf->Rect(125, 130, 40, 10, 'D');
|
|
|
167 |
$pdf->Text(125, 126, 'MirrorV');
|
|
|
168 |
$pdf->SetDrawColor(0);
|
|
|
169 |
$pdf->SetTextColor(0);
|
|
|
170 |
// Start Transformation
|
|
|
171 |
$pdf->StartTransform();
|
|
|
172 |
// mirror vertically with axis of reflection at y-position 140 (bottom side of the rectangle)
|
|
|
173 |
$pdf->MirrorV(140);
|
|
|
174 |
$pdf->Rect(125, 130, 40, 10, 'D');
|
|
|
175 |
$pdf->Text(125, 126, 'MirrorV');
|
|
|
176 |
// Stop Transformation
|
|
|
177 |
$pdf->StopTransform();
|
|
|
178 |
|
|
|
179 |
// --- Point reflection ------------------------------------
|
|
|
180 |
$pdf->SetDrawColor(200);
|
|
|
181 |
$pdf->SetTextColor(200);
|
|
|
182 |
$pdf->Rect(70, 160, 40, 10, 'D');
|
|
|
183 |
$pdf->Text(70, 156, 'MirrorP');
|
|
|
184 |
$pdf->SetDrawColor(0);
|
|
|
185 |
$pdf->SetTextColor(0);
|
|
|
186 |
// Start Transformation
|
|
|
187 |
$pdf->StartTransform();
|
|
|
188 |
// point reflection at the lower left point of rectangle
|
|
|
189 |
$pdf->MirrorP(70,170);
|
|
|
190 |
$pdf->Rect(70, 160, 40, 10, 'D');
|
|
|
191 |
$pdf->Text(70, 156, 'MirrorP');
|
|
|
192 |
// Stop Transformation
|
|
|
193 |
$pdf->StopTransform();
|
|
|
194 |
|
|
|
195 |
// --- Mirroring against a straigth line described by a point (120, 120) and an angle -20°
|
|
|
196 |
$angle=-20;
|
|
|
197 |
$px=120;
|
|
|
198 |
$py=170;
|
|
|
199 |
|
|
|
200 |
// just for visualisation: the straight line to mirror against
|
|
|
201 |
|
|
|
202 |
$pdf->SetDrawColor(200);
|
|
|
203 |
$pdf->Line($px-1,$py-1,$px+1,$py+1);
|
|
|
204 |
$pdf->Line($px-1,$py+1,$px+1,$py-1);
|
|
|
205 |
$pdf->StartTransform();
|
|
|
206 |
$pdf->Rotate($angle, $px, $py);
|
|
|
207 |
$pdf->Line($px-5, $py, $px+60, $py);
|
|
|
208 |
$pdf->StopTransform();
|
|
|
209 |
|
|
|
210 |
$pdf->SetDrawColor(200);
|
|
|
211 |
$pdf->SetTextColor(200);
|
|
|
212 |
$pdf->Rect(125, 160, 40, 10, 'D');
|
|
|
213 |
$pdf->Text(125, 156, 'MirrorL');
|
|
|
214 |
$pdf->SetDrawColor(0);
|
|
|
215 |
$pdf->SetTextColor(0);
|
|
|
216 |
//Start Transformation
|
|
|
217 |
$pdf->StartTransform();
|
|
|
218 |
//mirror against the straight line
|
|
|
219 |
$pdf->MirrorL($angle, $px, $py);
|
|
|
220 |
$pdf->Rect(125, 160, 40, 10, 'D');
|
|
|
221 |
$pdf->Text(125, 156, 'MirrorL');
|
|
|
222 |
//Stop Transformation
|
|
|
223 |
$pdf->StopTransform();
|
|
|
224 |
|
|
|
225 |
// ---------------------------------------------------------
|
|
|
226 |
|
|
|
227 |
//Close and output PDF document
|
|
|
228 |
$pdf->Output('example_013.pdf', 'I');
|
|
|
229 |
|
|
|
230 |
//============================================================+
|
|
|
231 |
// END OF FILE
|
|
|
232 |
//============================================================+
|