1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
| <?php
include_once('fpdf/fpdf.php');
include_once('fpdi/fpdi.php');
if(isset($_POST['your-phone']) AND strlen($_POST['capcha']) == 0)
{
$to="***@gmail.com";
$title="Накаладная с сайта";
//Запись в переменные из формы
send_pdf($data);
?>
<strong>Данные отправлены.</strong>
<?
}
else
{
?>
<script src="/public/themes/default/js/baloon/js/baloon.js" language="JavaScript" type="text/javascript"></script>
<link href="/public/themes/default/js/baloon/css/baloon.css" rel="stylesheet" type="text/css" />
<form action="" method="post" >
... сама форма...
<input type="submit" value="Отправить данные" class="wpcf7-submit" />
</div>
<?
}
function send_pdf($data){
$file_counter = "blank_counter.dat";
// Читаем текущее значение счетчика
if (file_exists($file_counter)) {
$fp = fopen($file_counter, "r");
$counter = fread($fp, filesize($file_counter));
fclose($fp);
} else {
$counter = 0;
}
// Увеличиваем счетчик на единицу
$counter++;
// Сохраняем обновленное значение счетчика
$fp = fopen($file_counter, "w");
fwrite($fp, $counter);
fclose($fp);
// Добавим значение счетчика к коду
$code='M0000'.$counter;
$pdfname='M0000'.$counter;
/*echo '<pre>';
var_dump($data);
echo '</pre>';*/
// initiate FPDI
$pdf = new FPDI();
$pdf->AddFont('Arial-BoldMT','B','arial_bold.php');
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile(***.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
...Вставка данных в pdf...
//Code128(60, 30, 'M00005051', 20, 20);
$x=157;
$y=10;
$ext=true;
$cks = false;
$w = 0.27;
$h = 7.9;
$wide = true;
//Display code
$pdf->SetFont('Courier', '',6);
$pdf->Text($x, $y+$h-8, $code);
if($ext)
{
//Extended encoding
$code = encode_code39_ext($code);
}
else
{
//Convert to upper case
$code = strtoupper($code);
//Check validity
if(!preg_match('|^[0-9A-Z. $/+%-]*$|', $code))
$pdf->Error('Invalid barcode value: '.$code);
}
//Compute checksum
if ($cks)
$code .= $pdf->checksum_code39($code);
//Add start and stop characters
$code = '*'.$code.'*';
//Conversion tables
$narrow_encoding = array (
'0' => '101001101101', '1' => '110100101011', '2' => '101100101011',
'3' => '110110010101', '4' => '101001101011', '5' => '110100110101',
'6' => '101100110101', '7' => '101001011011', '8' => '110100101101',
'9' => '101100101101', 'A' => '110101001011', 'B' => '101101001011',
'C' => '110110100101', 'D' => '101011001011', 'E' => '110101100101',
'F' => '101101100101', 'G' => '101010011011', 'H' => '110101001101',
'I' => '101101001101', 'J' => '101011001101', 'K' => '110101010011',
'L' => '101101010011', 'M' => '110110101001', 'N' => '101011010011',
'O' => '110101101001', 'P' => '101101101001', 'Q' => '101010110011',
'R' => '110101011001', 'S' => '101101011001', 'T' => '101011011001',
'U' => '110010101011', 'V' => '100110101011', 'W' => '110011010101',
'X' => '100101101011', 'Y' => '110010110101', 'Z' => '100110110101',
'-' => '100101011011', '.' => '110010101101', ' ' => '100110101101',
'*' => '100101101101', '$' => '100100100101', '/' => '100100101001',
'+' => '100101001001', '%' => '101001001001' );
$wide_encoding = array (
'0' => '101000111011101', '1' => '111010001010111', '2' => '101110001010111',
'3' => '111011100010101', '4' => '101000111010111', '5' => '111010001110101',
'6' => '101110001110101', '7' => '101000101110111', '8' => '111010001011101',
'9' => '101110001011101', 'A' => '111010100010111', 'B' => '101110100010111',
'C' => '111011101000101', 'D' => '101011100010111', 'E' => '111010111000101',
'F' => '101110111000101', 'G' => '101010001110111', 'H' => '111010100011101',
'I' => '101110100011101', 'J' => '101011100011101', 'K' => '111010101000111',
'L' => '101110101000111', 'M' => '111011101010001', 'N' => '101011101000111',
'O' => '111010111010001', 'P' => '101110111010001', 'Q' => '101010111000111',
'R' => '111010101110001', 'S' => '101110101110001', 'T' => '101011101110001',
'U' => '111000101010111', 'V' => '100011101010111', 'W' => '111000111010101',
'X' => '100010111010111', 'Y' => '111000101110101', 'Z' => '100011101110101',
'-' => '100010101110111', '.' => '111000101011101', ' ' => '100011101011101',
'*' => '100010111011101', '$' => '100010001000101', '/' => '100010001010001',
'+' => '100010100010001', '%' => '101000100010001');
$encoding = $wide ? $wide_encoding : $narrow_encoding;
//Inter-character spacing
$gap = ($w > 0.29) ? '00' : '0';
//Convert to bars
$encode = '';
for ($i = 0; $i< strlen($code); $i++)
$encode .= $encoding[$code{$i}].$gap;
//Draw bars
//draw_code39($encode, $x, $y, $w, $h);
//Draw bars
for($i=0; $i<strlen($encode); $i++)
{
if($encode{$i} == '1')
{
$pdf->Rect($x+$i*$w, $y, $w, $h, 'F');
}
}
//$pdf->Output();
// email stuff (change data below)
$to = "***@inbox.ru";
$from = "***@mail.ru";
$subject = "накладная";
$message = "<p>Файл в приложении.</p>";
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// attachment name
$filename = $pdfname.".pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "Электронная накладная.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"UTF-8\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
// send message
mail($to, $subject, $body, $headers);
}
function checksum_code39($code) {
//Compute the modulo 43 checksum
$chars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
$sum = 0;
for ($i=0 ; $i<strlen($code); $i++) {
$a = array_keys($chars, $code{$i});
$sum += $a[0];
}
$r = $sum % 43;
return $chars[$r];
}
function encode_code39_ext($code) {
//Encode characters in extended mode
$encode = array(
chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C',
chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G',
chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '?K',
chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O',
chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S',
chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W',
chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A',
chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E',
chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C',
chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G',
chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K',
chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O',
chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F',
chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J',
chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K',
chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O',
chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C',
chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G',
chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K',
chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O',
chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S',
chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W',
chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P',
chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
$code_ext = '';
for ($i = 0 ; $i<strlen($code); $i++) {
if (ord($code{$i}) > 127)
$pdf->Error('Invalid character: '.$code{$i});
$code_ext .= $encode[$code{$i}];
}
return $code_ext;
}
//$pdf->Rect(0, 0, 1, 1, 'F');
function enc($text)
{
return iconv("utf-8", "windows-1251", $text);
}
?> |