Subversion Repositories Applications.annuaire

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_014.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-08-08
6
//
7
// Description : Example 014 for TCPDF class
8
//               Javascript Form and user rights (only works on Adobe Acrobat)
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: Javascript Form and user rights (only works on Adobe Acrobat)
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 014');
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.' 014', 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
// IMPORTANT: disable font subsetting to allow users editing the document
73
$pdf->setFontSubsetting(false);
74
 
75
// set font
76
$pdf->SetFont('helvetica', '', 10, '', false);
77
 
78
// add a page
79
$pdf->AddPage();
80
 
81
/*
82
It is possible to create text fields, combo boxes, check boxes and buttons.
83
Fields are created at the current position and are given a name.
84
This name allows to manipulate them via JavaScript in order to perform some validation for instance.
85
*/
86
 
87
// set default form properties
88
$pdf->setFormDefaultProp(array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 200), 'strokeColor'=>array(255, 128, 128)));
89
 
90
$pdf->SetFont('helvetica', 'BI', 18);
91
$pdf->Cell(0, 5, 'Example of Form', 0, 1, 'C');
92
$pdf->Ln(10);
93
 
94
$pdf->SetFont('helvetica', '', 12);
95
 
96
// First name
97
$pdf->Cell(35, 5, 'First name:');
98
$pdf->TextField('firstname', 50, 5);
99
$pdf->Ln(6);
100
 
101
// Last name
102
$pdf->Cell(35, 5, 'Last name:');
103
$pdf->TextField('lastname', 50, 5);
104
$pdf->Ln(6);
105
 
106
// Gender
107
$pdf->Cell(35, 5, 'Gender:');
108
//$pdf->ComboBox('gender', 10, 5, array('', 'M', 'F'));
109
$pdf->ComboBox('gender', 30, 5, array(array('', '-'), array('M', 'Male'), array('F', 'Female')));
110
$pdf->Ln(6);
111
 
112
// Drink
113
$pdf->Cell(35, 5, 'Drink:');
114
$pdf->RadioButton('drink', 5, array(), array(), 'Water');
115
$pdf->Cell(35, 5, 'Water');
116
$pdf->Ln(6);
117
$pdf->Cell(35, 5, '');
118
$pdf->RadioButton('drink', 5, array(), array(), 'Beer', true);
119
$pdf->Cell(35, 5, 'Beer');
120
$pdf->Ln(6);
121
$pdf->Cell(35, 5, '');
122
$pdf->RadioButton('drink', 5, array(), array(), 'Wine');
123
$pdf->Cell(35, 5, 'Wine');
124
$pdf->Ln(10);
125
 
126
// Listbox
127
$pdf->Cell(35, 5, 'List:');
128
$pdf->ListBox('listbox', 60, 15, array('', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7'), array('multipleSelection'=>'true'));
129
$pdf->Ln(20);
130
 
131
// Adress
132
$pdf->Cell(35, 5, 'Address:');
133
$pdf->TextField('address', 60, 18, array('multiline'=>true));
134
$pdf->Ln(19);
135
 
136
// E-mail
137
$pdf->Cell(35, 5, 'E-mail:');
138
$pdf->TextField('email', 50, 5);
139
$pdf->Ln(6);
140
 
141
// Newsletter
142
$pdf->Cell(35, 5, 'Newsletter:');
143
$pdf->CheckBox('newsletter', 5, true, array(), array(), 'OK');
144
$pdf->Ln(10);
145
 
146
// Date of the day
147
$pdf->Cell(35, 5, 'Date:');
148
$pdf->TextField('date', 30, 5, array(), array('v'=>date('Y-m-d'), 'dv'=>date('Y-m-d')));
149
$pdf->Ln(10);
150
 
151
$pdf->SetX(50);
152
 
153
// Button to validate and print
154
$pdf->Button('print', 30, 10, 'Print', 'Print()', array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
155
 
156
// Reset Button
157
$pdf->Button('reset', 30, 10, 'Reset', array('S'=>'ResetForm'), array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
158
 
159
// Submit Button
160
$pdf->Button('submit', 30, 10, 'Submit', array('S'=>'SubmitForm', 'F'=>'http://localhost/printvars.php', 'Flags'=>array('ExportFormat')), array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
161
 
162
 
163
// Form validation functions
164
$js = <<<EOD
165
function CheckField(name,message) {
166
	var f = getField(name);
167
	if(f.value == '') {
168
	    app.alert(message);
169
	    f.setFocus();
170
	    return false;
171
	}
172
	return true;
173
}
174
function Print() {
175
	if(!CheckField('firstname','First name is mandatory')) {return;}
176
	if(!CheckField('lastname','Last name is mandatory')) {return;}
177
	if(!CheckField('gender','Gender is mandatory')) {return;}
178
	if(!CheckField('address','Address is mandatory')) {return;}
179
	print();
180
}
181
EOD;
182
 
183
// Add Javascript code
184
$pdf->IncludeJS($js);
185
 
186
// ---------------------------------------------------------
187
 
188
//Close and output PDF document
189
$pdf->Output('example_014.pdf', 'I');
190
 
191
//============================================================+
192
// END OF FILE
193
//============================================================+