-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_worker.html
679 lines (665 loc) · 40.6 KB
/
example_worker.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<title>Aspose.PDF for JavaScript via C++</title>
</head>
<body style="background-color:#2871e6;font-family:Arial;margin:auto">
<div id="ASPOSE" style="overflow:auto">
<div style="float:left;margin-left:8px;margin-top:8px">
<img src="favicon.ico" alt="ASPOSE" width="32px" height="32px"/>
</div>
<div style="float:left;margin-left:8px;margin-top:8px">
<label id="AsposeTitle" style="color:white;font:bold 32px Arial">Aspose.PDF for JavaScript via C++</label>
</div>
<div style="border-top: 48px solid #000"></div>
</div>
<div style="margin-left:8px;margin-right:8px;margin-top:8px;margin-bottom:8px">
<progress id="working" style="width:100%;accent-color:#6ed924"></progress>
<br>
<label style="color:white" for="selectOperation">Select operation: </label>
<select id="selectOperation" value="AsposePdfExtractText" disabled onChange="changeOperation(event);">
<optgroup label="Convert from PDF">
<option value="AsposePdfPagesToJpg">Convert a PDF-file to JPG</option>
<option value="AsposePdfPagesToPng">Convert a PDF-file to PNG</option>
<option value="AsposePdfPagesToTiff">Convert a PDF-file to TIFF</option>
<option value="AsposePdfPagesToBmp">Convert a PDF-file to BMP</option>
<option value="AsposePdfPagesToDICOM">Convert a PDF-file to DICOM</option>
<option value="AsposePdfPagesToSvg">Convert a PDF-file to SVG</option>
<option value="AsposePdfPagesToSvgZip">Convert a PDF-file to SVG(zip)</option>
<option value="AsposePdfPagesToPDF">Convert a PDF-file to PDF (separate pages)</option>
<option value="AsposePdfToTeX">Convert a PDF-file to TeX</option>
<option value="AsposePdfToXps">Convert a PDF-file to Xps</option>
<option value="AsposePdfTablesToCSV">Convert a PDF-file to CSV (extract tables)</option>
<option value="AsposePdfToTxt">Convert a PDF-file to Txt</option>
<option value="AsposePdfConvertToGrayscale">Convert a PDF-file to grayscale</option>
<option value="AsposePdfConvertToPDFA">Convert a PDF-file to PDF/A</option>
<option value="AsposePdfAConvertToPDF">Convert a PDF/A-file to PDF</option>
<option value="AsposePdfToDocX">Convert a PDF-file to DocX</option>
<option value="AsposePdfToXlsX">Convert a PDF-file to XlsX</option>
<option value="AsposePdfToEPUB">Convert a PDF-file to ePub</option>
<option value="AsposePdfToDoc">Convert a PDF-file to Doc</option>
<option value="AsposePdfToPptX">Convert a PDF-file to PptX</option>
<option value="AsposePdfExtractText" selected>Extract text from a PDF-file</option>
<option value="AsposePdfExtractImage">Extract image from a PDF-file</option>
<option value="AsposePdfExportFdf">Export from a PDF-file with AcroForm to FDF</option>
<option value="AsposePdfExportXfdf">Export from a PDF-file with AcroForm to XFDF</option>
<option value="AsposePdfExportXml">Export from a PDF-file with AcroForm to XML</option>
<optgroup label="Convert to PDF">
<option value="AsposePdfFromTxt">Convert a TXT-file to PDF</option>
<option value="AsposePdfFromImage">Convert a Image-file to PDF</option>
<optgroup label="Organize PDF">
<option value="AsposePdfOptimize">Optimize a PDF-file</option>
<option value="AsposePdfMerge2Files">Merge two PDF-files</option>
<option value="AsposePdfSplit2Files">Split to two PDF-files</option>
<option value="AsposePdfRotateAllPages">Rotate PDF-pages</option>
<option value="AsposePdfDeletePages">Delete pages from a PDF-file</option>
<option value="AsposePdfAddStamp">Add stamp to a PDF-file</option>
<option value="AsposePdfAddImage">Add an image to end a PDF-file</option>
<option value="AsposePdfAddPageNum">Add page number to a PDF-file</option>
<option value="AsposePdfAddBackgroundImage">Add background image to a PDF-file</option>
<option value="AsposePdfAddTextHeaderFooter">Add text in Header/Footer of a PDF-file</option>
<option value="AsposePdfRepair">Repair a PDF-file</option>
<option value="AsposePdfOptimizeResource">Optimize resources of PDF-file</option>
<option value="AsposePdfSetBackgroundColor">Set the background color for the PDF-file</option>
<option value="AsposePdfDeleteAnnotations">Delete annotations from a PDF-file</option>
<option value="AsposePdfDeleteBookmarks">Delete bookmarks from a PDF-file</option>
<option value="AsposePdfDeleteAttachments">Delete attachments from a PDF-file</option>
<option value="AsposePdfDeleteImages">Delete images from a PDF-file</option>
<option value="AsposePdfDeleteJavaScripts">Delete JavaScripts from a PDF-file</option>
<option value="AsposePdfAddAttachment">Add attachment to a PDF-file</option>
<option value="AsposePdfGetAttachment">Get attachment from a PDF-file</option>
<option value="AsposePdfReplaceText">Replace text in a PDF-file</option>
<option value="AsposePdfFindText">Find text in a PDF-file</option>
<option value="AsposePdfReplaceFont">Replace font in a PDF-file</option>
<option value="AsposePdfValidatePDFA">Validate PDF/A compatibility a PDF-file</option>
<option value="AsposePdfFindHiddenText">Find hidden text in a PDF-file</option>
<option value="AsposePdfDeleteHiddenText">Delete hidden text from a PDF-file</option>
<option value="AsposePdfAddWatermark">Add watermark to a PDF-file</option>
<option value="AsposePdfDeleteWatermarks">Delete watermarks from a PDF-file</option>
<option value="AsposePdfMergeLayers">Merge layers a PDF-file</option>
<optgroup label="Metadata PDF">
<option value="AsposePdfSetInfo">Set info (metadata) in a PDF-file</option>
<option value="AsposePdfGetInfo">Get info (metadata) from a PDF-file</option>
<option value="AsposePdfGetAllFonts">Get list fonts from a PDF-file</option>
<option value="AsposePdfRemoveMetadata">Remove metadata from a PDF-file</option>
<option value="AsposePdfGetWordsCharactersCount">Get words and characters count in a PDF-file</option>
<option value="AsposePdfGetPagesLayers">Get list layers from a PDF-file</option>
<optgroup label="Security PDF">
<option value="AsposePdfEncrypt">Encrypt a PDF-file</option>
<option value="AsposePdfDecrypt">Decrypt a PDF-file</option>
<option value="AsposePdfSignPKCS7">Sign a PDF-file with digital signatures</option>
<option value="AsposePdfChangePassword">Change passwords of the PDF-file</option>
</select>
<input type="file" id="fileOperation" accept="application/pdf" disabled onChange="ffileOperation(event);">
<br>
<pre id="output" style="width:100%;background-color:#fbeeee;border-radius:4px"></pre>
<br>
<div id="fileDownload" style="width:100%;background-color:#eff9e8;border-radius:4px"></div>
</div>
</body>
<script type="text/javascript">
// Create Web Worker
const AsposePDFWebWorker = new Worker("AsposePDFforJS.js");
AsposePDFWebWorker.onerror = function (evt) { console.log(`Error from Web Worker: ${evt.message}`); }
AsposePDFWebWorker.onmessage = function (evt) {
if (evt.data == 'ready') {
document.getElementById('output').textContent = 'loaded!';
// uploading additional files to Web Worker (AsposePdfPrepare must be used):
// option #1
// 'Aspose.jpg' already loaded, see settings in 'settings.json'
// option #2
const UploadFileToWebWorker = (base64, filename) => fetch(base64).then(res => res.arrayBuffer()).then(buffer => fileProcess('AsposePdfPrepare', new File([new Uint8Array(buffer)], filename)));
// key PKCS7 for test, converted to Base64, with "Pa$$w0rd2023" password
const test_pfx = "data:application/octet-stream;base64,MIIEcQIBAzCCBDcGCSqGSIb3DQEHAaCCBCgEggQkMIIEIDCCAj8GCSqGSIb3DQEHBqCCAjAwggIsAgEAMIICJQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQI4tjRHb+OMLsCAggAgIIB+OAPdXDmh+6qTyjHkumo2euCw4EvRZ8qSha/AAWYespZs8mA9dInLWM33HeDqktHEcZoPf/CCWqQopRA6RPFAYIn9ioR8s3Phd3LmoMPb52SKJMvWjRGRppLyo4gCNZfv37duV8+mKTSyDW1wrtHsZnvLlUHmy8+OcG8zsAAX6YwHTMkafllpRKkB0kmO1boSvHEp5IPsU8u50VpF21OXYNV7D5c4W2O1GrV0a5HD6OyObHJjj+ufPF7nh+qEuPN/b8hm14y+sZPoVSRvwtH+O8VVDxnJWX+y+jGhChLxiYUYRnhBMW6X+cZW9bcpXZIkFdQdPWA1/opOdTguHlXQF1R+JNnUUOtopwX103undyPGl5JGXvLrr6iH2aO1GY1p2Asd1exaQdfwFQynCxlZrKaCc2JBs5Jem5/wWN6rfq+n15tsYvk2gTP+U/icla8wp1NsqqTGOe0dAJNH3kDOwxKVb5gU+fOYbFWI/6iZ3Tdl41W66rE4Gxj937oYJE1KUK3SlxJtL0uK5c3ZN9yMJYdpc9k2HQ1VOssuUKrmpuOcyJhpF4XosHxMyQxPFFVA/TNggb3Dv3cr2Qei+JqF4n4KAqYCY5u0O+y6+R9Ig0L5zCL/n9cWyPyYqqvEH4ICxqUoH05qCJIMdiNlc5w1PYUXKaSRSzK0TCCAdkGCSqGSIb3DQEHAaCCAcoEggHGMIIBwjCCAb4GCyqGSIb3DQEMCgECoIIBhjCCAYIwHAYKKoZIhvcNAQwBAzAOBAgWFTAixF9bPAICCAAEggFgwC4A+R9X2xdbdfz0IKw2f7pe3iJdgLKJPYiUDV2cGfQnM4UuQKu9qIZ3lAzBtQcF09Wy6pwwU63nVHiGZ6y9PunZZ3tIM24I0Ii1Q5PrphvT4z7yXPqI+sv53AhzwpTJ2XHJQRf53PX7V8ujv3k8lfBQ6gYxfFMkrTdZlfiWeoWZSlFMKUzmaRfBFVit5BRUNEgZrySfZxyxULpo+KzQ/b5K0Z69x6Gvj/j21gEkGTEDWhmjECjsPCP+sWDMyB1xOxHimJgmLtSHc7hpdE/xuRBVELxhlFI1lYj3fbWbnMNzeLG+OBaoktbpr9kbsWRM568vLxdV7XZYkaoGEd+SEUTR+Yxyak/DHspkO/o4apjOh24U6GCqfqPl4ucxTMvOiYpobrxPub/sqQPXB0NEsqNPjcYdsT1y1YkYMxO0b1heh8TWat6SYk1dLi1wdV0iGf8LTImqzzUobZNBfrybjzElMCMGCSqGSIb3DQEJFTEWBBRBGCVJ5N72ukaNrJUetg4Rp0/41DAxMCEwCQYFKw4DAhoFAAQU8VT/8VxDX7Sx3p05TO3BNne5YXYECJhmeDAQpwBNAgIIAA==";
UploadFileToWebWorker(test_pfx, 'test.pfx');
// sign picture, signatureAppearance, converted to Base64
const sign_png ="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAIAAAAlV+npAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAT6SURBVGhD7ZptTFtVGIBbyqUrbddALRA/gtuYEzs2J5sRBQPZcEUgAwvBDQxOUZP5ScwSl/jDfzPxx4wfi3M4rYNVAkwWZygy4w/RkoyxzVkZg4nMNBaQkVKgdP3At56TI8y2XPWe23MTnx/AfeHXk/c8vTcX+eLioux/+JGAv0uTQDDQ7xzAF/SRtqz9Pa8XWcp6x+z4mjISPoadg6crW2vhB02Suqu2Iz8zD83pIdXN+mV6bO+pfSpd6KFSbVDlKWkxi7BfkpQFqapuq/cpp4vrklO2ObfvSUa+bMM9+C/oIElZkCrH3Ln7diSFDBPh6/QJ5KvcWtPu6PzzT6ggPVmQqiOD76/dGkzJuY5HQPqEqUHJaf27O56i50tigYdUbTlSsNo4ual8AY+WwHn0tiaf38NZzceqjBV4KhxS2iySqnsfWI1Hy/Frpx597NZAKAj7NTJ1FU+FQ0qyXuzavyxVkXBNzMHXuk01Wfp1aCIgkpH12aV2y3DTzalajuJ62kCve2Na9rslb+GRoEhDFpypZ754yZAVWFPgxaNInP9uRuHVQrA0Sg0eCYoEZC34FyBVcGcQLVWIa3b15Egi7NTG9HvwSGgkIKux+8CQ92LsVM0M6of75DVr6p7cEn4AogTrsnim6qzNt05ppJQqAtOy/lGq2qo/pZQqAruyZn2zla21PFN1tPyduw134RE12JUFd1VXfQ4+qapf3/B4ThUe0YRRWZ+cb2kdbeaTqg2qzYd2HsQjyrAo68fxn2CteKfKsopbhUeUYU4WpAqe7PinisZjTTSoy4I1gbtKfMEDPqmavpQqZqoIdGW1Ozq3HS0sPr4L9gWPYsInVQmTaQNnboiZKgJFWWAKDtRCwNd7ra+kxbyiL56putAndqoItGQhU5zWb96bsbmQO+f+PrYvnndVo9+qxE8VgYosYsrUoPRlXrmjcMr4cEJsX3Cn7gyOrJiqn/sV4qeKILyspab82ik0zMidARHIl8szjoaED85+dOrXNmZTRRBYVkRTCBCx9ZGwryJL6VJfF377obH7AMupIggpq/liazRTCJ0x7GvMP0R8wamsbquXq718UnW88sO4pIogmCxYkCc+fzYQChYUGyKaQtzki3+qnst+viK7DI/ihJCvwt62H4YDpdKFdr6wGODCLw6i4Xak9n91Q+2/ZY77HVIV4wBCqnqa543qXPvTZxIViXgaJ4Q8hq/k7YP6et0J3e/JuQUdnkYC7ReY4pMqpS8FUhV3U4DwL1nJfkUrF8E7bNDo5cHUqAcQUgUH8ITJGvcDiKDyRjrGZyJ/IFVwrwCpOmR6E4/iDa3X9//RF1OpIgh/U4qoMlZYzcf8Hs7W5OM8ejzlDVOpItCSBfxrX+iu6uNdh+9MycQjNqAoC1jqC04WnsaEnbuqvyPGvxydHrJBv4Iqz/Y9ybL0qJ99AJupItDdLETZBlNXbQc82X19Yl42Hmu/2EwVQQxZQH5m3oq+yAMga6kiiCQLiO0LperlnFdhDfGIPcRo1lJ6x+wlLeZwv3YnyzJwv1CqcnUPflP/JZsHECHeZiH+2i/rvG/UgIaQKniohs9Nlk0BYm8W4vLklSJLqVvhur8wxemadl6WnSw7aVpfjH/NKvGRBSBfrtnwSXwtv/HgjjfQnGXiJgtAvrJS1zKeKkI8ZQHgS5Okvl13G75mmzjLkhIy2R/qB+VUhKQ5zAAAAABJRU5ErkJggg==";
UploadFileToWebWorker(sign_png, 'sign.png');
// attachment: text, converted to Base64
const text_txt ="data:text/plain;base64,V2VsY29tZSB0byBBc3Bvc2UuUERGIGZvciBKYXZhU2NyaXB0IHZpYSBDKys=";
UploadFileToWebWorker(text_txt,'text.txt');
//Get info about Product - Ask Web Worker
AsposePDFWebWorker.postMessage({ "operation": "AsposePdfAbout", "params": [] }, []);
}
else {
const json = evt.data.json;
const operation = evt.data.operation;
const params = evt.data.params;
if (json.errorCode == 0) {
if (operation !== 'AsposePdfPrepare') document.getElementById('output').textContent = "completed!";
document.getElementById('fileDownload').innerHTML = "";
// peculiar properties
switch (operation) {
case 'AsposePdfAbout':
document.getElementById('AsposeTitle').innerHTML = json.producer;
document.getElementById('output').textContent = "Product : " + json.product
+ "\nFamily : " + json.family
+ "\nVersion : " + json.version
+ "\nRelease date : " + json.releasedate
+ "\nProducer : " + json.producer
+ "\nIs licensed : " + json.islicensed;
break;
case 'AsposePdfPrepare':
// if 'optdata' is Array
// perform 'operation' on the first element of 'optdata'
// and pass the remaining elements
// if 'optdata' length is 1 then need to perform the final operation
// after set 'additional_data'
if (Array.isArray(json.optdata) && (json.optdata.length > 0)) {
const next_operation = json.optdata[0].operation;
const next_file = json.optdata[0].file;
const additional_data = new Map([
['AsposePdfMerge2Files', {"fileName2": json.fileNameResult}]
]);
fileProcess(next_operation, next_file, (json.optdata.length > 1) ? json.optdata.slice(1) : additional_data.get(next_operation));
}
break;
case 'AsposePdfExtractText':
document.getElementById('output').textContent = json.extractText;
break;
case 'AsposePdfGetWordsCharactersCount':
document.getElementById('output').textContent = "Words count : " + json.words + "\nCharacters count : " + json.characters;
break;
case 'AsposePdfGetAllFonts':
let listFonts = 'Fonts:';
json.fonts.forEach(({fontName}) => listFonts += `\n${fontName}`);
document.getElementById('output').textContent = listFonts;
break;
case 'AsposePdfGetPagesLayers':
document.getElementById('output').textContent = 'Layers:\n' + json.pagesLayers.map((layer, index) => `page #${index + 1}: ${layer.join('; ')}`).join('\n');
break;
case 'AsposePdfFindText':
case 'AsposePdfFindHiddenText':
let listFragments= 'textFragments:';
json.textFragments.forEach(({text, xIndent, yIndent, fontName, fontSize}) => listFragments+= `\ntext: ${text}, xIndent: ${xIndent}, yIndent: ${yIndent}, fontName: ${fontName}, fontSize: ${fontSize}`);
document.getElementById('output').textContent = listFragments;
break;
case 'AsposePdfGetInfo':
document.getElementById('output').textContent = "Title : " + json.title
+ "\nCreator : " + json.creator
+ "\nAuthor : " + json.author
+ "\nSubject : " + json.subject
+ "\nKeywords : " + json.keywords
+ "\nCreation Date : " + json.creation
+ "\nModify Date : " + json.mod
+ "\nPDF format : " + json.format
+ "\nPDF version : " + json.version
+ "\nPDF is PDF/A : " + json.ispdfa
+ "\nPDF is PDF/UA : " + json.ispdfua
+ "\nPDF is linearized : " + json.islinearized
+ "\nPDF is encrypted : " + json.isencrypted
+ "\nPDF permission : " + json.permission
+ "\nPDF page size : " + json.size
+ "\nPage count : " + json.pagecount
+ "\nAnnotation count : " + json.annotationcount
+ "\nBookmark count : " + json.bookmarkcount
+ "\nAttachment count : " + json.attachmentcount
+ "\nMetadata count : " + json.metadatacount
+ "\nJavaScript count : " + json.javascriptcount
+ "\nImage count : " + json.imagecount;
break;
case 'AsposePdfPagesToJpg':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/jpeg", params[fileIndex]);
break;
case 'AsposePdfPagesToPng':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/png", params[fileIndex]);
break;
case 'AsposePdfPagesToSvg':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/svg", params[fileIndex]);
break;
case 'AsposePdfPagesToSvgZip':
DownloadFile(json.fileNameResult, "application/zip", params[0]);
break;
case 'AsposePdfPagesToTiff':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/tiff", params[fileIndex]);
break;
case 'AsposePdfPagesToBmp':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/bmp", params[fileIndex]);
break;
case 'AsposePdfPagesToDICOM':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "application/dicom", params[fileIndex]);
break;
case 'AsposePdfSplit2Files':
DownloadFile(json.fileNameResult1, "application/pdf", params[0]);
DownloadFile(json.fileNameResult2, "application/pdf", params[1]);
break;
case 'AsposePdfConvertToPDFA':
DownloadFile(json.fileNameResult, "application/pdf", params[0]);
DownloadFile(json.fileNameLogResult, "application/xml", params[1]);
break;
case 'AsposePdfToDocX':
DownloadFile(json.fileNameResult, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", params[0]);
break;
case 'AsposePdfToXlsX':
DownloadFile(json.fileNameResult, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", params[0]);
break;
case 'AsposePdfToTeX':
DownloadFile(json.fileNameResult, "application/x-tex", params[0]);
break;
case 'AsposePdfToXps':
DownloadFile(json.fileNameResult, "application/vnd.ms-xpsdocument", params[0]);
break;
case 'AsposePdfToTxt':
DownloadFile(json.fileNameResult, "text/plain", params[0]);
break;
case 'AsposePdfTablesToCSV':
document.getElementById('output').textContent = "Files(tables) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "text/csv", params[fileIndex]);
break;
case 'AsposePdfExtractImage':
document.getElementById('output').textContent = "Files(images) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "image/jpeg", params[fileIndex]);
break;
case 'AsposePdfGetAttachment':
document.getElementById('output').textContent = "Files(attachment) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "", params[fileIndex]);
break;
case 'AsposePdfToEPUB':
DownloadFile(json.fileNameResult, "application/epub+zip", params[0]);
break;
case 'AsposePdfToDoc':
DownloadFile(json.fileNameResult, "application/msword", params[0]);
break;
case 'AsposePdfToPptX':
DownloadFile(json.fileNameResult, "application/vnd.openxmlformats-officedocument.presentationml.presentation", params[0]);
break;
case 'AsposePdfExportFdf':
DownloadFile(json.fileNameResult, "application/vnd.fdf", params[0]);
break;
case 'AsposePdfExportXfdf':
DownloadFile(json.fileNameResult, "application/vnd.adobe.xfdf", params[0]);
break;
case 'AsposePdfExportXml':
case 'AsposePdfValidatePDFA':
DownloadFile(json.fileNameResult, "application/xml", params[0]);
break;
case 'AsposePdfPagesToPDF':
document.getElementById('output').textContent = "Files(pages) count: " + json.filesCount.toString();
for (let fileIndex = 0; fileIndex < json.filesCount; fileIndex++)
DownloadFile(json.filesNameResult[fileIndex], "application/pdf", params[fileIndex]);
break;
default:
// AsposePdfAConvertToPDF, AsposePdfAddBackgroundImage, AsposePdfAddImage, AsposePdfAddPageNum,
// AsposePdfAddStamp, AsposePdfAddTextHeaderFooter, AsposePdfConvertToGrayscale, AsposePdfDecrypt,
// AsposePdfDeletePages, AsposePdfEncrypt, AsposePdfMerge2Files, AsposePdfOptimize,
// AsposePdfRotateAllPages, AsposePdfSetInfo, AsposePdfSignPKCS7,
// AsposePdfRemoveMetadata, AsposePdfChangePassword, AsposePdfOptimizeResource,
// AsposePdfSetBackgroundColor, AsposePdfDeleteAnnotations, AsposePdfDeleteBookmarks,
// AsposePdfDeleteAttachments, AsposePdfDeleteImages, AsposePdfDeleteJavaScripts,
// AsposePdfFromTxt, AsposePdfAddAttachment, AsposePdfReplaceText, AsposePdfFromImage,
// AsposePdfReplaceFont, AsposePdfDeleteHiddenText, AsposePdfAddWatermark, AsposePdfDeleteWatermarks
// AsposePdfMergeLayers
DownloadFile(json.fileNameResult, "application/pdf", params[0]);
}
}
else document.getElementById('output').textContent = `Error: ${json.errorText}`;
}
SetProgress();
}
//
const fileProcess = function (operation, ffile, optdata) {
const file_reader = new FileReader();
file_reader.onload = (event) => {
SetProgress("Processing:");
// params for function
let params = [];
let transfer = [];
// peculiar properties for operation
switch (operation) {
case 'AsposePdfAbout':
break;
case 'AsposePdfPrepare':
transfer = [event.target.result];
params = [event.target.result, ffile.name, optdata];
break;
case 'AsposePdfExtractText':
case 'AsposePdfGetInfo':
case 'AsposePdfGetAllFonts':
case 'AsposePdfGetWordsCharactersCount':
case 'AsposePdfGetPagesLayers':
transfer = [event.target.result];
params = [event.target.result, ffile.name];
break;
case 'AsposePdfToDocX':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.docx`];
break;
case 'AsposePdfToXlsX':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.xlsx`];
break;
case 'AsposePdfToTeX':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.tex`];
break;
case 'AsposePdfToXps':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.xps`];
break;
case 'AsposePdfToTxt':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.txt`];
break;
case 'AsposePdfToEPUB':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.epub`];
break;
case 'AsposePdfToDoc':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.doc`];
break;
case 'AsposePdfToPptX':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.pptx`];
break;
case 'AsposePdfAddTextHeaderFooter':
const header = 'Aspose.PDF for JavaScript via C++';
const footer = 'ASPOSE';
transfer = [event.target.result];
params = [event.target.result, ffile.name, header, footer, `Result${operation}.pdf`];
break;
case 'AsposePdfDecrypt':
const password = 'owner';
transfer = [event.target.result];
params = [event.target.result, ffile.name, password, `Result${operation}.pdf`];
break;
case 'AsposePdfEncrypt':
const password_user = 'user';
const password_owner = 'owner';
const permissions = 'Module.Permissions.PrintDocument';
const algorithm = 'Module.CryptoAlgorithm.RC4x40';
transfer = [event.target.result];
params = [event.target.result, ffile.name, password_user, password_owner, permissions, algorithm, `Result${operation}.pdf`];
break;
case 'AsposePdfSetInfo':
transfer = [event.target.result];
// PDF info:
const title = 'Setting PDF Document Information';
const creator = ''; //if not need to set value, use: undefined or ""/'' (empty string)
const author = 'Aspose';
const subject = undefined;
const keywords = 'Aspose.Pdf, DOM, API';
const creation = undefined; //create date
const mod = '2008/12/21 12:15:12'; //modify date
params = [event.target.result, ffile.name, title, creator, author, subject, keywords, creation, mod, `Result${operation}.pdf`];
break;
case 'AsposePdfSplit2Files':
const pageToSplit = 1;
transfer = [event.target.result];
params = [event.target.result, ffile.name, pageToSplit, `Result${operation}.pdf`, `Result${operation}-last.pdf`];
break;
case 'AsposePdfDeletePages':
//const numPages = "1-3"; //string, include number pages with interval: "7, 20, 22, 30-32, 33, 36-40, 46"
//const numPages = [1,3]; //array, array of number pages
const numPages = 1; //number, number page
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.pdf`, numPages];
break;
case 'AsposePdfPagesToJpg':
case 'AsposePdfExtractImage':
const resolution_jpg = 150; //resolution in dpi
const template_jpg = `Result${operation}{0:D2}.jpg`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_jpg, resolution_jpg];
break;
case 'AsposePdfPagesToPng':
const resolution_png = 100; //resolution in dpi
const template_png = `Result${operation}{0:D2}.png`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_png, resolution_png];
break;
case 'AsposePdfPagesToSvg':
const template_svg = `Result${operation}.svg`; //result filename
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_svg];
break;
case 'AsposePdfPagesToSvgZip':
const template_svg_zip = `Result${operation}.zip`; //result filename
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_svg_zip];
break;
case 'AsposePdfPagesToTiff':
const resolution_tiff = 100; //resolution in dpi
const template_tiff = `Result${operation}{0:D2}.tiff`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_tiff, resolution_tiff];
break;
case 'AsposePdfPagesToBmp':
const resolution_bmp = 100; //resolution in dpi
const template_bmp = `Result${operation}{0:D2}.bmp`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_bmp, resolution_bmp];
break;
case 'AsposePdfPagesToDICOM':
const resolution_DICOM = 100; //resolution in dpi
const template_DICOM = `Result${operation}{0:D2}.dcm`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_DICOM, resolution_DICOM];
break;
case 'AsposePdfRotateAllPages':
const rotation = 'Module.Rotation.on270';
transfer = [event.target.result];
params = [event.target.result, ffile.name, rotation, `Result${operation}.pdf`];
break;
case 'AsposePdfConvertToPDFA':
const pdfFormat = 'Module.PdfFormat.PDF_A_1A';
transfer = [event.target.result];
params = [event.target.result, ffile.name, pdfFormat, `Result${operation}.pdf`, `Result${operation}.xml`];
break;
case 'AsposePdfAddBackgroundImage':
const fileBackgroundImage = '/Aspose.jpg'; //see option #1 uploading additional files
transfer = [event.target.result];
params = [event.target.result, ffile.name, fileBackgroundImage, `Result${operation}.pdf`];
break;
case 'AsposePdfAddImage':
const fileImage = '/Aspose.jpg'; //see option #1 uploading additional files
transfer = [event.target.result];
params = [event.target.result, ffile.name, fileImage, `Result${operation}.pdf`];
break;
case 'AsposePdfAddStamp':
const fileNameStamp = '/Aspose.jpg'; //see option #1 uploading additional files
const setBackground = 0;
const setXIndent_ = 5;
const setYIndent_ = 5;
const setHeight_ = 40;
const setWidth_ = 40;
const rotation_ = 'Module.Rotation.on270';
const setOpacity = 0.5;
transfer = [event.target.result];
params = [event.target.result, ffile.name, fileNameStamp, setBackground, setXIndent_, setYIndent_, setHeight_, setWidth_, rotation_, setOpacity, `Result${operation}.pdf`];
break;
case 'AsposePdfSignPKCS7':
const pageNum = 1;
const fileSign = '/test.pfx'; //see option #2 uploading additional files
const pswSign = 'Pa$$w0rd2023';
const setXIndent = 100;
const setYIndent = 100;
const setHeight = 200;
const setWidth = 100;
const reason = 'Reason';
const contact = '[email protected]';
const location = 'Location';
const isVisible = 1;
const signatureAppearance = '/sign.png'; //see option #2 uploading additional files
transfer = [event.target.result];
params = [event.target.result, ffile.name, pageNum, fileSign, pswSign, setXIndent, setYIndent, setHeight, setWidth, reason, contact, location, isVisible, signatureAppearance, `Result${operation}.pdf`];
break;
case 'AsposePdfMerge2Files':
transfer = [event.target.result];
params = [event.target.result, undefined, ffile.name, (optdata === undefined) ? ffile.name : optdata.fileName2, `Result${operation}.pdf`];
break;
case 'AsposePdfTablesToCSV':
const delimiter_csv = "\t"; //TAB as comma-separated value
const template_csv = `Result${operation}{0:D2}.csv`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_csv, delimiter_csv];
break;
case 'AsposePdfSetBackgroundColor':
const backgroundColor = '#4682B4'; //color in hexadecimal format (a hex triplet)
transfer = [event.target.result];
params = [event.target.result, ffile.name, backgroundColor, `Result${operation}.pdf`];
break;
case 'AsposePdfChangePassword':
const ownerPassword = 'owner'; //Owner password.
const newUserPassword = 'newuser'; //New user password.
const newOwnerPassword = 'newowner'; //New owner password.
transfer = [event.target.result];
params = [event.target.result, ffile.name, ownerPassword, newUserPassword, newOwnerPassword, `Result${operation}.pdf`];
break;
case 'AsposePdfAddAttachment':
const fileAttachment = '/text.txt'; //see option #2 uploading additional files
const fileDescription = 'Attachment "text.txt"';
transfer = [event.target.result];
params = [event.target.result, ffile.name, fileAttachment, fileDescription, `Result${operation}.pdf`];
break;
case 'AsposePdfGetAttachment':
const template_attachment = `Result${operation}_{0}`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_attachment];
break;
case 'AsposePdfExportFdf':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.fdf`];
break;
case 'AsposePdfExportXfdf':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.xfdf`];
break;
case 'AsposePdfExportXml':
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.xml`];
break;
case 'AsposePdfReplaceText':
const findText = 'Aspose';
const replaceText = 'ASPOSE';
transfer = [event.target.result];
params = [event.target.result, ffile.name, findText, replaceText, `Result${operation}.pdf`];
break;
case 'AsposePdfFindText':
const searchText = 'Aspose';
transfer = [event.target.result];
params = [event.target.result, ffile.name, searchText];
break;
case 'AsposePdfFromImage':
const pageSize = 'Module.PdfPageSize.A3';
const margin = 40;
const isLandscape = true;
transfer = [event.target.result];
params = [event.target.result, ffile.name, pageSize, margin, isLandscape, `Result${operation}.pdf`];
break;
case 'AsposePdfReplaceFont':
const findFont = 'Helvetica';
const replaceFont = 'Times';
transfer = [event.target.result];
params = [event.target.result, ffile.name, findFont, replaceFont, `Result${operation}.pdf`];
break;
case 'AsposePdfPagesToPDF':
const template_pdf = `Result${operation}{0:D2}.pdf`; //result filename template
transfer = [event.target.result];
params = [event.target.result, ffile.name, template_pdf];
break;
case 'AsposePdfValidatePDFA':
const pdfFormatValidate = 'Module.PdfFormat.PDF_A_1A';
transfer = [event.target.result];
params = [event.target.result, ffile.name, pdfFormatValidate, `Result${operation}.xml`];
break;
case 'AsposePdfAddWatermark':
const text = "Aspose PDF";
const fontName = "Arial";
const fontSize = 32;
const foregroundColor = "#010101";
const xPosition = 100;
const yPosition = 100;
const rotation2 = 45;
const isBackground2 = 1;
const opacity2 = 0.5;
transfer = [event.target.result];
params = [event.target.result, ffile.name, text, fontName, fontSize, foregroundColor, xPosition, yPosition, rotation2, isBackground2, opacity2, `Result${operation}.pdf`];
break;
case 'AsposePdfMergeLayers':
transfer = [event.target.result];
params = [event.target.result, ffile.name, "MergedLayer", `Result${operation}.pdf`];
break;
default:
// AsposePdfOptimize, AsposePdfAddPageNum, AsposePdfConvertToGrayscale, AsposePdfAConvertToPDF,
// AsposePdfRemoveMetadata, AsposePdfRepair, AsposePdfOptimizeResource, AsposePdfDeleteAnnotations,
// AsposePdfDeleteBookmarks, AsposePdfDeleteAttachments, AsposePdfDeleteImages, AsposePdfDeleteJavaScripts,
// AsposePdfFromTxt, AsposePdfFindHiddenText, AsposePdfDeleteHiddenText, AsposePdfDeleteWatermarks
transfer = [event.target.result];
params = [event.target.result, ffile.name, `Result${operation}.pdf`];
}
// Ask Web Worker
return AsposePDFWebWorker.postMessage({ "operation": operation, "params": params }, transfer);
};
file_reader.readAsArrayBuffer(ffile);
}
//
const ffileOperation = function (evt) {
const operation = document.getElementById('selectOperation').value;
const files_arr = [{"operation": operation, "file": evt.target.files[0]}];
// for the rest of the files, if they exist, need to perform AsposePdfPrepare
for (let i = 1; i < evt.target.files.length; i++) files_arr.unshift({"operation": 'AsposePdfPrepare', "file": evt.target.files[i]});
// processing
fileProcess(files_arr[0].operation, files_arr[0].file, files_arr.length > 1 ? files_arr.slice(1) : undefined)
}
//
const changeOperation = function (event) {
// for AsposePdfMerge2Files need 'multiple'
if (document.getElementById('selectOperation').value == 'AsposePdfMerge2Files')
document.getElementById('fileOperation').setAttribute("multiple", '')
else
document.getElementById('fileOperation').removeAttribute("multiple");
switch (document.getElementById('selectOperation').value) {
case 'AsposePdfFromTxt':
document.getElementById('fileOperation').setAttribute("accept", 'text/plain')
break;
case 'AsposePdfFromImage':
document.getElementById('fileOperation').setAttribute("accept", 'image/*')
break;
default:
document.getElementById('fileOperation').setAttribute("accept", 'application/pdf')
}
document.getElementById('fileOperation').value = '';
}
const SetProgress = function (labelName = '') {
if (labelName == '') {
document.getElementById('working').setAttribute("hidden", '');
document.getElementById('fileOperation').removeAttribute("disabled");
document.getElementById('selectOperation').removeAttribute("disabled");
}
else {
document.getElementById('output').textContent = labelName;
document.getElementById('working').removeAttribute("hidden");
document.getElementById('fileOperation').setAttribute("disabled", '');
document.getElementById('selectOperation').setAttribute("disabled", '');
}
}
const DownloadFile = function (filename, mime, content) {
mime = mime || "application/octet-stream";
var link = document.createElement("a");
link.href = URL.createObjectURL(new Blob([content], {type: mime}));
link.download = filename;
link.textContent = filename;
link.title = "Click here to download the file";
document.getElementById('fileDownload').appendChild(link);
document.getElementById('fileDownload').appendChild(document.createElement("br"));
}
</script>
</html>