source: trunk/client/inc/hpdf5/tecnickcom/tcpdf/examples/example_013.php@ 384

Last change on this file since 384 was 347, checked in by roby, 3 years ago

Aggiornamento per compatibilità con php7.4

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