@embedpdf/engines 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/converters.cjs +149 -115
- package/dist/converters.cjs.map +1 -1
- package/dist/converters.d.ts +2 -1
- package/dist/converters.js +143 -86
- package/dist/converters.js.map +1 -1
- package/dist/index.cjs +5362 -5994
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1479 -6
- package/dist/index.js +5399 -356
- package/dist/index.js.map +1 -1
- package/dist/pdfium-direct-engine.cjs +4037 -0
- package/dist/pdfium-direct-engine.cjs.map +1 -0
- package/dist/{pdfium.d.cts → pdfium-direct-engine.d.ts} +4 -96
- package/dist/pdfium-direct-engine.js +4035 -0
- package/dist/pdfium-direct-engine.js.map +1 -0
- package/dist/pdfium-worker-engine.cjs +800 -0
- package/dist/pdfium-worker-engine.cjs.map +1 -0
- package/dist/{worker.d.cts → pdfium-worker-engine.d.ts} +36 -4
- package/dist/pdfium-worker-engine.js +798 -0
- package/dist/pdfium-worker-engine.js.map +1 -0
- package/dist/pdfium.cjs +4243 -5663
- package/dist/pdfium.cjs.map +1 -1
- package/dist/pdfium.d.ts +131 -3
- package/dist/pdfium.js +4288 -21
- package/dist/pdfium.js.map +1 -1
- package/dist/preact.cjs +39 -0
- package/dist/preact.cjs.map +1 -0
- package/dist/preact.d.ts +13 -0
- package/dist/preact.js +37 -0
- package/dist/preact.js.map +1 -0
- package/dist/react.cjs +39 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +37 -0
- package/dist/react.js.map +1 -0
- package/dist/worker.cjs +771 -1104
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.ts +30 -4
- package/dist/worker.js +786 -11
- package/dist/worker.js.map +1 -1
- package/package.json +42 -8
- package/dist/chunk-NDTYBBMQ.js +0 -4615
- package/dist/chunk-NDTYBBMQ.js.map +0 -1
- package/dist/chunk-YZLT3A2D.js +0 -1101
- package/dist/chunk-YZLT3A2D.js.map +0 -1
- package/dist/converters.d.cts +0 -69
- package/dist/index.d.cts +0 -32
- package/dist/runner-BvRtPCKL.d.cts +0 -131
- package/dist/runner-BvRtPCKL.d.ts +0 -131
package/dist/chunk-YZLT3A2D.js
DELETED
|
@@ -1,1101 +0,0 @@
|
|
|
1
|
-
// src/webworker/engine.ts
|
|
2
|
-
import {
|
|
3
|
-
Task,
|
|
4
|
-
NoopLogger,
|
|
5
|
-
PdfErrorCode
|
|
6
|
-
} from "@embedpdf/models";
|
|
7
|
-
var LOG_SOURCE = "WebWorkerEngine";
|
|
8
|
-
var LOG_CATEGORY = "Engine";
|
|
9
|
-
var WorkerTask = class extends Task {
|
|
10
|
-
/**
|
|
11
|
-
* Create a task that bind to web worker with specified message id
|
|
12
|
-
* @param worker - web worker instance
|
|
13
|
-
* @param messageId - id of message
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
constructor(worker, messageId) {
|
|
18
|
-
super();
|
|
19
|
-
this.worker = worker;
|
|
20
|
-
this.messageId = messageId;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* {@inheritDoc @embedpdf/models!Task.abort}
|
|
24
|
-
*
|
|
25
|
-
* @override
|
|
26
|
-
*/
|
|
27
|
-
abort(e) {
|
|
28
|
-
super.abort(e);
|
|
29
|
-
this.worker.postMessage({
|
|
30
|
-
type: "AbortRequest",
|
|
31
|
-
data: {
|
|
32
|
-
messageId: this.messageId
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var _WebWorkerEngine = class _WebWorkerEngine {
|
|
38
|
-
/**
|
|
39
|
-
* Create an instance of WebWorkerEngine, it will create a worker with
|
|
40
|
-
* specified url.
|
|
41
|
-
* @param worker - webworker instance, this worker needs to contains the running instance of {@link EngineRunner}
|
|
42
|
-
* @param logger - logger instance
|
|
43
|
-
*
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
constructor(worker, logger = new NoopLogger()) {
|
|
47
|
-
this.worker = worker;
|
|
48
|
-
this.logger = logger;
|
|
49
|
-
/**
|
|
50
|
-
* All the tasks that is executing
|
|
51
|
-
*/
|
|
52
|
-
this.tasks = /* @__PURE__ */ new Map();
|
|
53
|
-
/**
|
|
54
|
-
* Handle event from web worker. There are 2 kinds of event
|
|
55
|
-
* 1. ReadyResponse: web worker is ready
|
|
56
|
-
* 2. ExecuteResponse: result of execution
|
|
57
|
-
* @param evt - message event from web worker
|
|
58
|
-
* @returns
|
|
59
|
-
*
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
62
|
-
this.handle = (evt) => {
|
|
63
|
-
this.logger.debug(
|
|
64
|
-
LOG_SOURCE,
|
|
65
|
-
LOG_CATEGORY,
|
|
66
|
-
"webworker engine start handling message: ",
|
|
67
|
-
evt.data
|
|
68
|
-
);
|
|
69
|
-
try {
|
|
70
|
-
const response = evt.data;
|
|
71
|
-
const task = this.tasks.get(response.id);
|
|
72
|
-
if (!task) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
switch (response.type) {
|
|
76
|
-
case "ReadyResponse":
|
|
77
|
-
this.readyTask.resolve(true);
|
|
78
|
-
break;
|
|
79
|
-
case "ExecuteResponse":
|
|
80
|
-
{
|
|
81
|
-
switch (response.data.type) {
|
|
82
|
-
case "result":
|
|
83
|
-
task.resolve(response.data.value);
|
|
84
|
-
break;
|
|
85
|
-
case "error":
|
|
86
|
-
task.reject(response.data.value.reason);
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
this.tasks.delete(response.id);
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
} catch (e) {
|
|
94
|
-
this.logger.error(LOG_SOURCE, LOG_CATEGORY, "webworker met error when handling message: ", e);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
this.worker.addEventListener("message", this.handle);
|
|
98
|
-
this.readyTask = new WorkerTask(this.worker, _WebWorkerEngine.readyTaskId);
|
|
99
|
-
this.tasks.set(_WebWorkerEngine.readyTaskId, this.readyTask);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Generate a unique message id
|
|
103
|
-
* @returns message id
|
|
104
|
-
*
|
|
105
|
-
* @private
|
|
106
|
-
*/
|
|
107
|
-
generateRequestId(id) {
|
|
108
|
-
return `${id}.${Date.now()}.${Math.random()}`;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.initialize}
|
|
112
|
-
*
|
|
113
|
-
* @public
|
|
114
|
-
*/
|
|
115
|
-
initialize() {
|
|
116
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "initialize");
|
|
117
|
-
const requestId = this.generateRequestId("General");
|
|
118
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
119
|
-
const request = {
|
|
120
|
-
id: requestId,
|
|
121
|
-
type: "ExecuteRequest",
|
|
122
|
-
data: {
|
|
123
|
-
name: "initialize",
|
|
124
|
-
args: []
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
this.proxy(task, request);
|
|
128
|
-
return task;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.destroy}
|
|
132
|
-
*
|
|
133
|
-
* @public
|
|
134
|
-
*/
|
|
135
|
-
destroy() {
|
|
136
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "destroy");
|
|
137
|
-
const requestId = this.generateRequestId("General");
|
|
138
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
139
|
-
task.wait(
|
|
140
|
-
() => {
|
|
141
|
-
this.worker.removeEventListener("message", this.handle);
|
|
142
|
-
},
|
|
143
|
-
() => {
|
|
144
|
-
this.worker.removeEventListener("message", this.handle);
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
const request = {
|
|
148
|
-
id: requestId,
|
|
149
|
-
type: "ExecuteRequest",
|
|
150
|
-
data: {
|
|
151
|
-
name: "destroy",
|
|
152
|
-
args: []
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
this.proxy(task, request);
|
|
156
|
-
return task;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.openDocumentUrl}
|
|
160
|
-
*
|
|
161
|
-
* @public
|
|
162
|
-
*/
|
|
163
|
-
openDocumentUrl(file, options) {
|
|
164
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentUrl", file.url, options);
|
|
165
|
-
const requestId = this.generateRequestId(file.id);
|
|
166
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
167
|
-
const request = {
|
|
168
|
-
id: requestId,
|
|
169
|
-
type: "ExecuteRequest",
|
|
170
|
-
data: {
|
|
171
|
-
name: "openDocumentUrl",
|
|
172
|
-
args: [file, options]
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
this.proxy(task, request);
|
|
176
|
-
return task;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.openDocument}
|
|
180
|
-
*
|
|
181
|
-
* @public
|
|
182
|
-
*/
|
|
183
|
-
openDocumentFromBuffer(file, password) {
|
|
184
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentFromBuffer", file, password);
|
|
185
|
-
const requestId = this.generateRequestId(file.id);
|
|
186
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
187
|
-
const request = {
|
|
188
|
-
id: requestId,
|
|
189
|
-
type: "ExecuteRequest",
|
|
190
|
-
data: {
|
|
191
|
-
name: "openDocumentFromBuffer",
|
|
192
|
-
args: [file, password]
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
this.proxy(task, request);
|
|
196
|
-
return task;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.openDocumentFromLoader}
|
|
200
|
-
*
|
|
201
|
-
* @public
|
|
202
|
-
*/
|
|
203
|
-
openDocumentFromLoader(file, password) {
|
|
204
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentFromLoader", file, password);
|
|
205
|
-
const requestId = this.generateRequestId(file.id);
|
|
206
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
207
|
-
const request = {
|
|
208
|
-
id: requestId,
|
|
209
|
-
type: "ExecuteRequest",
|
|
210
|
-
data: {
|
|
211
|
-
name: "openDocumentFromLoader",
|
|
212
|
-
args: [file, password]
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
this.proxy(task, request);
|
|
216
|
-
return task;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getMetadata}
|
|
220
|
-
*
|
|
221
|
-
* @public
|
|
222
|
-
*/
|
|
223
|
-
getMetadata(doc) {
|
|
224
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getMetadata", doc);
|
|
225
|
-
const requestId = this.generateRequestId(doc.id);
|
|
226
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
227
|
-
const request = {
|
|
228
|
-
id: requestId,
|
|
229
|
-
type: "ExecuteRequest",
|
|
230
|
-
data: {
|
|
231
|
-
name: "getMetadata",
|
|
232
|
-
args: [doc]
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
this.proxy(task, request);
|
|
236
|
-
return task;
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getDocPermissions}
|
|
240
|
-
*
|
|
241
|
-
* @public
|
|
242
|
-
*/
|
|
243
|
-
getDocPermissions(doc) {
|
|
244
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getDocPermissions", doc);
|
|
245
|
-
const requestId = this.generateRequestId(doc.id);
|
|
246
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
247
|
-
const request = {
|
|
248
|
-
id: requestId,
|
|
249
|
-
type: "ExecuteRequest",
|
|
250
|
-
data: {
|
|
251
|
-
name: "getDocPermissions",
|
|
252
|
-
args: [doc]
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
this.proxy(task, request);
|
|
256
|
-
return task;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getDocUserPermissions}
|
|
260
|
-
*
|
|
261
|
-
* @public
|
|
262
|
-
*/
|
|
263
|
-
getDocUserPermissions(doc) {
|
|
264
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getDocUserPermissions", doc);
|
|
265
|
-
const requestId = this.generateRequestId(doc.id);
|
|
266
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
267
|
-
const request = {
|
|
268
|
-
id: requestId,
|
|
269
|
-
type: "ExecuteRequest",
|
|
270
|
-
data: {
|
|
271
|
-
name: "getDocUserPermissions",
|
|
272
|
-
args: [doc]
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
this.proxy(task, request);
|
|
276
|
-
return task;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getBookmarks}
|
|
280
|
-
*
|
|
281
|
-
* @public
|
|
282
|
-
*/
|
|
283
|
-
getBookmarks(doc) {
|
|
284
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getBookmarks", doc);
|
|
285
|
-
const requestId = this.generateRequestId(doc.id);
|
|
286
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
287
|
-
const request = {
|
|
288
|
-
id: requestId,
|
|
289
|
-
type: "ExecuteRequest",
|
|
290
|
-
data: {
|
|
291
|
-
name: "getBookmarks",
|
|
292
|
-
args: [doc]
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
this.proxy(task, request);
|
|
296
|
-
return task;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getSignatures}
|
|
300
|
-
*
|
|
301
|
-
* @public
|
|
302
|
-
*/
|
|
303
|
-
getSignatures(doc) {
|
|
304
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getSignatures", doc);
|
|
305
|
-
const requestId = this.generateRequestId(doc.id);
|
|
306
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
307
|
-
const request = {
|
|
308
|
-
id: requestId,
|
|
309
|
-
type: "ExecuteRequest",
|
|
310
|
-
data: {
|
|
311
|
-
name: "getSignatures",
|
|
312
|
-
args: [doc]
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
this.proxy(task, request);
|
|
316
|
-
return task;
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.renderPage}
|
|
320
|
-
*
|
|
321
|
-
* @public
|
|
322
|
-
*/
|
|
323
|
-
renderPage(doc, page, scaleFactor, rotation, dpr, options) {
|
|
324
|
-
this.logger.debug(
|
|
325
|
-
LOG_SOURCE,
|
|
326
|
-
LOG_CATEGORY,
|
|
327
|
-
"renderPage",
|
|
328
|
-
doc,
|
|
329
|
-
page,
|
|
330
|
-
scaleFactor,
|
|
331
|
-
rotation,
|
|
332
|
-
dpr,
|
|
333
|
-
options
|
|
334
|
-
);
|
|
335
|
-
const requestId = this.generateRequestId(doc.id);
|
|
336
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
337
|
-
const request = {
|
|
338
|
-
id: requestId,
|
|
339
|
-
type: "ExecuteRequest",
|
|
340
|
-
data: {
|
|
341
|
-
name: "renderPage",
|
|
342
|
-
args: [doc, page, scaleFactor, rotation, dpr, options]
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
this.proxy(task, request);
|
|
346
|
-
return task;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.renderPageRect}
|
|
350
|
-
*
|
|
351
|
-
* @public
|
|
352
|
-
*/
|
|
353
|
-
renderPageRect(doc, page, scaleFactor, rotation, dpr, rect, options) {
|
|
354
|
-
this.logger.debug(
|
|
355
|
-
LOG_SOURCE,
|
|
356
|
-
LOG_CATEGORY,
|
|
357
|
-
"renderPageRect",
|
|
358
|
-
doc,
|
|
359
|
-
page,
|
|
360
|
-
scaleFactor,
|
|
361
|
-
rotation,
|
|
362
|
-
dpr,
|
|
363
|
-
rect,
|
|
364
|
-
options
|
|
365
|
-
);
|
|
366
|
-
const requestId = this.generateRequestId(doc.id);
|
|
367
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
368
|
-
const request = {
|
|
369
|
-
id: requestId,
|
|
370
|
-
type: "ExecuteRequest",
|
|
371
|
-
data: {
|
|
372
|
-
name: "renderPageRect",
|
|
373
|
-
args: [doc, page, scaleFactor, rotation, dpr, rect, options]
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
this.proxy(task, request);
|
|
377
|
-
return task;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getAllAnnotations}
|
|
381
|
-
*
|
|
382
|
-
* @public
|
|
383
|
-
*/
|
|
384
|
-
getAllAnnotations(doc) {
|
|
385
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAllAnnotations", doc);
|
|
386
|
-
const requestId = this.generateRequestId(doc.id);
|
|
387
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
388
|
-
const request = {
|
|
389
|
-
id: requestId,
|
|
390
|
-
type: "ExecuteRequest",
|
|
391
|
-
data: {
|
|
392
|
-
name: "getAllAnnotations",
|
|
393
|
-
args: [doc]
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
this.proxy(task, request);
|
|
397
|
-
return task;
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getPageAnnotations}
|
|
401
|
-
*
|
|
402
|
-
* @public
|
|
403
|
-
*/
|
|
404
|
-
getPageAnnotations(doc, page) {
|
|
405
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getPageAnnotations", doc, page);
|
|
406
|
-
const requestId = this.generateRequestId(doc.id);
|
|
407
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
408
|
-
const request = {
|
|
409
|
-
id: requestId,
|
|
410
|
-
type: "ExecuteRequest",
|
|
411
|
-
data: {
|
|
412
|
-
name: "getPageAnnotations",
|
|
413
|
-
args: [doc, page]
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
this.proxy(task, request);
|
|
417
|
-
return task;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.createPageAnnotation}
|
|
421
|
-
*
|
|
422
|
-
* @public
|
|
423
|
-
*/
|
|
424
|
-
createPageAnnotation(doc, page, annotation) {
|
|
425
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "createPageAnnotations", doc, page, annotation);
|
|
426
|
-
const requestId = this.generateRequestId(doc.id);
|
|
427
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
428
|
-
const request = {
|
|
429
|
-
id: requestId,
|
|
430
|
-
type: "ExecuteRequest",
|
|
431
|
-
data: {
|
|
432
|
-
name: "createPageAnnotation",
|
|
433
|
-
args: [doc, page, annotation]
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
this.proxy(task, request);
|
|
437
|
-
return task;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.transformPageAnnotation}
|
|
441
|
-
*
|
|
442
|
-
* @public
|
|
443
|
-
*/
|
|
444
|
-
transformPageAnnotation(doc, page, annotation, transformation) {
|
|
445
|
-
this.logger.debug(
|
|
446
|
-
LOG_SOURCE,
|
|
447
|
-
LOG_CATEGORY,
|
|
448
|
-
"transformPageAnnotation",
|
|
449
|
-
doc,
|
|
450
|
-
page,
|
|
451
|
-
annotation,
|
|
452
|
-
transformation
|
|
453
|
-
);
|
|
454
|
-
const requestId = this.generateRequestId(doc.id);
|
|
455
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
456
|
-
const request = {
|
|
457
|
-
id: requestId,
|
|
458
|
-
type: "ExecuteRequest",
|
|
459
|
-
data: {
|
|
460
|
-
name: "transformPageAnnotation",
|
|
461
|
-
args: [doc, page, annotation, transformation]
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
this.proxy(task, request);
|
|
465
|
-
return task;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.removePageAnnotation}
|
|
469
|
-
*
|
|
470
|
-
* @public
|
|
471
|
-
*/
|
|
472
|
-
removePageAnnotation(doc, page, annotation) {
|
|
473
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "removePageAnnotations", doc, page, annotation);
|
|
474
|
-
const requestId = this.generateRequestId(doc.id);
|
|
475
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
476
|
-
const request = {
|
|
477
|
-
id: requestId,
|
|
478
|
-
type: "ExecuteRequest",
|
|
479
|
-
data: {
|
|
480
|
-
name: "removePageAnnotation",
|
|
481
|
-
args: [doc, page, annotation]
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
this.proxy(task, request);
|
|
485
|
-
return task;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getPageTextRects}
|
|
489
|
-
*
|
|
490
|
-
* @public
|
|
491
|
-
*/
|
|
492
|
-
getPageTextRects(doc, page, scaleFactor, rotation) {
|
|
493
|
-
this.logger.debug(
|
|
494
|
-
LOG_SOURCE,
|
|
495
|
-
LOG_CATEGORY,
|
|
496
|
-
"getPageTextRects",
|
|
497
|
-
doc,
|
|
498
|
-
page,
|
|
499
|
-
scaleFactor,
|
|
500
|
-
rotation
|
|
501
|
-
);
|
|
502
|
-
const requestId = this.generateRequestId(doc.id);
|
|
503
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
504
|
-
const request = {
|
|
505
|
-
id: requestId,
|
|
506
|
-
type: "ExecuteRequest",
|
|
507
|
-
data: {
|
|
508
|
-
name: "getPageTextRects",
|
|
509
|
-
args: [doc, page, scaleFactor, rotation]
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
this.proxy(task, request);
|
|
513
|
-
return task;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.renderThumbnail}
|
|
517
|
-
*
|
|
518
|
-
* @public
|
|
519
|
-
*/
|
|
520
|
-
renderThumbnail(doc, page, scaleFactor, rotation, dpr) {
|
|
521
|
-
this.logger.debug(
|
|
522
|
-
LOG_SOURCE,
|
|
523
|
-
LOG_CATEGORY,
|
|
524
|
-
"renderThumbnail",
|
|
525
|
-
doc,
|
|
526
|
-
page,
|
|
527
|
-
scaleFactor,
|
|
528
|
-
rotation,
|
|
529
|
-
dpr
|
|
530
|
-
);
|
|
531
|
-
const requestId = this.generateRequestId(doc.id);
|
|
532
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
533
|
-
const request = {
|
|
534
|
-
id: requestId,
|
|
535
|
-
type: "ExecuteRequest",
|
|
536
|
-
data: {
|
|
537
|
-
name: "renderThumbnail",
|
|
538
|
-
args: [doc, page, scaleFactor, rotation, dpr]
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
this.proxy(task, request);
|
|
542
|
-
return task;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.searchAllPages}
|
|
546
|
-
*
|
|
547
|
-
* @public
|
|
548
|
-
*/
|
|
549
|
-
searchAllPages(doc, keyword, flags = []) {
|
|
550
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "searchAllPages 123", doc, keyword, flags);
|
|
551
|
-
const requestId = this.generateRequestId(doc.id);
|
|
552
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
553
|
-
const request = {
|
|
554
|
-
id: requestId,
|
|
555
|
-
type: "ExecuteRequest",
|
|
556
|
-
data: {
|
|
557
|
-
name: "searchAllPages",
|
|
558
|
-
args: [doc, keyword, flags]
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
this.proxy(task, request);
|
|
562
|
-
return task;
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.saveAsCopy}
|
|
566
|
-
*
|
|
567
|
-
* @public
|
|
568
|
-
*/
|
|
569
|
-
saveAsCopy(doc) {
|
|
570
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "saveAsCopy", doc);
|
|
571
|
-
const requestId = this.generateRequestId(doc.id);
|
|
572
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
573
|
-
const request = {
|
|
574
|
-
id: requestId,
|
|
575
|
-
type: "ExecuteRequest",
|
|
576
|
-
data: {
|
|
577
|
-
name: "saveAsCopy",
|
|
578
|
-
args: [doc]
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
this.proxy(task, request);
|
|
582
|
-
return task;
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getAttachments}
|
|
586
|
-
*
|
|
587
|
-
* @public
|
|
588
|
-
*/
|
|
589
|
-
getAttachments(doc) {
|
|
590
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getAttachments", doc);
|
|
591
|
-
const requestId = this.generateRequestId(doc.id);
|
|
592
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
593
|
-
const request = {
|
|
594
|
-
id: requestId,
|
|
595
|
-
type: "ExecuteRequest",
|
|
596
|
-
data: {
|
|
597
|
-
name: "getAttachments",
|
|
598
|
-
args: [doc]
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
this.proxy(task, request);
|
|
602
|
-
return task;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.readAttachmentContent}
|
|
606
|
-
*
|
|
607
|
-
* @public
|
|
608
|
-
*/
|
|
609
|
-
readAttachmentContent(doc, attachment) {
|
|
610
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "readAttachmentContent", doc, attachment);
|
|
611
|
-
const requestId = this.generateRequestId(doc.id);
|
|
612
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
613
|
-
const request = {
|
|
614
|
-
id: requestId,
|
|
615
|
-
type: "ExecuteRequest",
|
|
616
|
-
data: {
|
|
617
|
-
name: "readAttachmentContent",
|
|
618
|
-
args: [doc, attachment]
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
this.proxy(task, request);
|
|
622
|
-
return task;
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.setFormFieldValue}
|
|
626
|
-
*
|
|
627
|
-
* @public
|
|
628
|
-
*/
|
|
629
|
-
setFormFieldValue(doc, page, annotation, value) {
|
|
630
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "setFormFieldValue", doc, annotation, value);
|
|
631
|
-
const requestId = this.generateRequestId(doc.id);
|
|
632
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
633
|
-
const request = {
|
|
634
|
-
id: requestId,
|
|
635
|
-
type: "ExecuteRequest",
|
|
636
|
-
data: {
|
|
637
|
-
name: "setFormFieldValue",
|
|
638
|
-
args: [doc, page, annotation, value]
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
this.proxy(task, request);
|
|
642
|
-
return task;
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.flattenPage}
|
|
646
|
-
*
|
|
647
|
-
* @public
|
|
648
|
-
*/
|
|
649
|
-
flattenPage(doc, page, flag) {
|
|
650
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "flattenPage", doc, page, flag);
|
|
651
|
-
const requestId = this.generateRequestId(doc.id);
|
|
652
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
653
|
-
const request = {
|
|
654
|
-
id: requestId,
|
|
655
|
-
type: "ExecuteRequest",
|
|
656
|
-
data: {
|
|
657
|
-
name: "flattenPage",
|
|
658
|
-
args: [doc, page, flag]
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
this.proxy(task, request);
|
|
662
|
-
return task;
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.extractPages}
|
|
666
|
-
*
|
|
667
|
-
* @public
|
|
668
|
-
*/
|
|
669
|
-
extractPages(doc, pageIndexes) {
|
|
670
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "extractPages", doc);
|
|
671
|
-
const requestId = this.generateRequestId(doc.id);
|
|
672
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
673
|
-
const request = {
|
|
674
|
-
id: requestId,
|
|
675
|
-
type: "ExecuteRequest",
|
|
676
|
-
data: {
|
|
677
|
-
name: "extractPages",
|
|
678
|
-
args: [doc, pageIndexes]
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
this.proxy(task, request);
|
|
682
|
-
return task;
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.extractText}
|
|
686
|
-
*
|
|
687
|
-
* @public
|
|
688
|
-
*/
|
|
689
|
-
extractText(doc, pageIndexes) {
|
|
690
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "extractText", doc);
|
|
691
|
-
const requestId = this.generateRequestId(doc.id);
|
|
692
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
693
|
-
const request = {
|
|
694
|
-
id: requestId,
|
|
695
|
-
type: "ExecuteRequest",
|
|
696
|
-
data: {
|
|
697
|
-
name: "extractText",
|
|
698
|
-
args: [doc, pageIndexes]
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
this.proxy(task, request);
|
|
702
|
-
return task;
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getPageGlyphs}
|
|
706
|
-
*
|
|
707
|
-
* @public
|
|
708
|
-
*/
|
|
709
|
-
getPageGlyphs(doc, page) {
|
|
710
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getPageGlyphs", doc, page);
|
|
711
|
-
const requestId = this.generateRequestId(doc.id);
|
|
712
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
713
|
-
const request = {
|
|
714
|
-
id: requestId,
|
|
715
|
-
type: "ExecuteRequest",
|
|
716
|
-
data: {
|
|
717
|
-
name: "getPageGlyphs",
|
|
718
|
-
args: [doc, page]
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
this.proxy(task, request);
|
|
722
|
-
return task;
|
|
723
|
-
}
|
|
724
|
-
/**
|
|
725
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.getPageGeometry}
|
|
726
|
-
*
|
|
727
|
-
* @public
|
|
728
|
-
*/
|
|
729
|
-
getPageGeometry(doc, page) {
|
|
730
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "getPageGeometry", doc, page);
|
|
731
|
-
const requestId = this.generateRequestId(doc.id);
|
|
732
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
733
|
-
const request = {
|
|
734
|
-
id: requestId,
|
|
735
|
-
type: "ExecuteRequest",
|
|
736
|
-
data: {
|
|
737
|
-
name: "getPageGeometry",
|
|
738
|
-
args: [doc, page]
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
this.proxy(task, request);
|
|
742
|
-
return task;
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.merge}
|
|
746
|
-
*
|
|
747
|
-
* @public
|
|
748
|
-
*/
|
|
749
|
-
merge(files) {
|
|
750
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "merge", files);
|
|
751
|
-
const fileIds = files.map((file) => file.id).join(".");
|
|
752
|
-
const requestId = this.generateRequestId(fileIds);
|
|
753
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
754
|
-
const request = {
|
|
755
|
-
id: requestId,
|
|
756
|
-
type: "ExecuteRequest",
|
|
757
|
-
data: {
|
|
758
|
-
name: "merge",
|
|
759
|
-
args: [files]
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
this.proxy(task, request);
|
|
763
|
-
return task;
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.mergePages}
|
|
767
|
-
*
|
|
768
|
-
* @public
|
|
769
|
-
*/
|
|
770
|
-
mergePages(mergeConfigs) {
|
|
771
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "mergePages", mergeConfigs);
|
|
772
|
-
const requestId = this.generateRequestId(mergeConfigs.map((config) => config.docId).join("."));
|
|
773
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
774
|
-
const request = {
|
|
775
|
-
id: requestId,
|
|
776
|
-
type: "ExecuteRequest",
|
|
777
|
-
data: {
|
|
778
|
-
name: "mergePages",
|
|
779
|
-
args: [mergeConfigs]
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
this.proxy(task, request);
|
|
783
|
-
return task;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* {@inheritDoc @embedpdf/models!PdfEngine.closeDocument}
|
|
787
|
-
*
|
|
788
|
-
* @public
|
|
789
|
-
*/
|
|
790
|
-
closeDocument(doc) {
|
|
791
|
-
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "closeDocument", doc);
|
|
792
|
-
const requestId = this.generateRequestId(doc.id);
|
|
793
|
-
const task = new WorkerTask(this.worker, requestId);
|
|
794
|
-
const request = {
|
|
795
|
-
id: requestId,
|
|
796
|
-
type: "ExecuteRequest",
|
|
797
|
-
data: {
|
|
798
|
-
name: "closeDocument",
|
|
799
|
-
args: [doc]
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
this.proxy(task, request);
|
|
803
|
-
return task;
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Send the request to webworker inside and register the task
|
|
807
|
-
* @param task - task that waiting for the response
|
|
808
|
-
* @param request - request that needs send to web worker
|
|
809
|
-
* @param transferables - transferables that need to transfer to webworker
|
|
810
|
-
* @returns
|
|
811
|
-
*
|
|
812
|
-
* @internal
|
|
813
|
-
*/
|
|
814
|
-
proxy(task, request, transferables = []) {
|
|
815
|
-
this.logger.debug(
|
|
816
|
-
LOG_SOURCE,
|
|
817
|
-
LOG_CATEGORY,
|
|
818
|
-
"send request to worker",
|
|
819
|
-
task,
|
|
820
|
-
request,
|
|
821
|
-
transferables
|
|
822
|
-
);
|
|
823
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, "Begin", request.id);
|
|
824
|
-
this.readyTask.wait(
|
|
825
|
-
() => {
|
|
826
|
-
this.worker.postMessage(request, transferables);
|
|
827
|
-
task.wait(
|
|
828
|
-
() => {
|
|
829
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, "End", request.id);
|
|
830
|
-
},
|
|
831
|
-
() => {
|
|
832
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, "End", request.id);
|
|
833
|
-
}
|
|
834
|
-
);
|
|
835
|
-
this.tasks.set(request.id, task);
|
|
836
|
-
},
|
|
837
|
-
() => {
|
|
838
|
-
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `${request.data.name}`, "End", request.id);
|
|
839
|
-
task.reject({
|
|
840
|
-
code: PdfErrorCode.Initialization,
|
|
841
|
-
message: "worker initialization failed"
|
|
842
|
-
});
|
|
843
|
-
}
|
|
844
|
-
);
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
_WebWorkerEngine.readyTaskId = "0";
|
|
848
|
-
var WebWorkerEngine = _WebWorkerEngine;
|
|
849
|
-
|
|
850
|
-
// src/webworker/runner.ts
|
|
851
|
-
import {
|
|
852
|
-
NoopLogger as NoopLogger2,
|
|
853
|
-
PdfErrorCode as PdfErrorCode2
|
|
854
|
-
} from "@embedpdf/models";
|
|
855
|
-
var LOG_SOURCE2 = "WebWorkerEngineRunner";
|
|
856
|
-
var LOG_CATEGORY2 = "Engine";
|
|
857
|
-
var EngineRunner = class {
|
|
858
|
-
/**
|
|
859
|
-
* Create instance of EngineRunnder
|
|
860
|
-
* @param logger - logger instance
|
|
861
|
-
*/
|
|
862
|
-
constructor(logger = new NoopLogger2()) {
|
|
863
|
-
this.logger = logger;
|
|
864
|
-
/**
|
|
865
|
-
* Execute the request
|
|
866
|
-
* @param request - request that represent the pdf engine call
|
|
867
|
-
* @returns
|
|
868
|
-
*
|
|
869
|
-
* @protected
|
|
870
|
-
*/
|
|
871
|
-
this.execute = (request) => {
|
|
872
|
-
this.logger.debug(LOG_SOURCE2, LOG_CATEGORY2, "runner start exeucte request");
|
|
873
|
-
if (!this.engine) {
|
|
874
|
-
const error = {
|
|
875
|
-
type: "reject",
|
|
876
|
-
reason: {
|
|
877
|
-
code: PdfErrorCode2.NotReady,
|
|
878
|
-
message: "engine has not started yet"
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
const response = {
|
|
882
|
-
id: request.id,
|
|
883
|
-
type: "ExecuteResponse",
|
|
884
|
-
data: {
|
|
885
|
-
type: "error",
|
|
886
|
-
value: error
|
|
887
|
-
}
|
|
888
|
-
};
|
|
889
|
-
this.respond(response);
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
const engine = this.engine;
|
|
893
|
-
const { name, args } = request.data;
|
|
894
|
-
if (!engine[name]) {
|
|
895
|
-
const error = {
|
|
896
|
-
type: "reject",
|
|
897
|
-
reason: {
|
|
898
|
-
code: PdfErrorCode2.NotSupport,
|
|
899
|
-
message: "engine method has not supported yet"
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
const response = {
|
|
903
|
-
id: request.id,
|
|
904
|
-
type: "ExecuteResponse",
|
|
905
|
-
data: {
|
|
906
|
-
type: "error",
|
|
907
|
-
value: error
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
this.respond(response);
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
let task;
|
|
914
|
-
switch (name) {
|
|
915
|
-
case "isSupport":
|
|
916
|
-
task = this.engine[name](...args);
|
|
917
|
-
break;
|
|
918
|
-
case "initialize":
|
|
919
|
-
task = this.engine[name](...args);
|
|
920
|
-
break;
|
|
921
|
-
case "destroy":
|
|
922
|
-
task = this.engine[name](...args);
|
|
923
|
-
break;
|
|
924
|
-
case "openDocumentUrl":
|
|
925
|
-
task = this.engine[name](...args);
|
|
926
|
-
break;
|
|
927
|
-
case "openDocumentFromBuffer":
|
|
928
|
-
task = this.engine[name](...args);
|
|
929
|
-
break;
|
|
930
|
-
case "openDocumentFromLoader":
|
|
931
|
-
task = this.engine[name](...args);
|
|
932
|
-
break;
|
|
933
|
-
case "getDocPermissions":
|
|
934
|
-
task = this.engine[name](...args);
|
|
935
|
-
break;
|
|
936
|
-
case "getDocUserPermissions":
|
|
937
|
-
task = this.engine[name](...args);
|
|
938
|
-
break;
|
|
939
|
-
case "getMetadata":
|
|
940
|
-
task = this.engine[name](...args);
|
|
941
|
-
break;
|
|
942
|
-
case "getBookmarks":
|
|
943
|
-
task = this.engine[name](...args);
|
|
944
|
-
break;
|
|
945
|
-
case "getSignatures":
|
|
946
|
-
task = this.engine[name](...args);
|
|
947
|
-
break;
|
|
948
|
-
case "renderPage":
|
|
949
|
-
task = this.engine[name](...args);
|
|
950
|
-
break;
|
|
951
|
-
case "renderPageRect":
|
|
952
|
-
task = this.engine[name](...args);
|
|
953
|
-
break;
|
|
954
|
-
case "renderThumbnail":
|
|
955
|
-
task = this.engine[name](...args);
|
|
956
|
-
break;
|
|
957
|
-
case "getAllAnnotations":
|
|
958
|
-
task = this.engine[name](...args);
|
|
959
|
-
break;
|
|
960
|
-
case "getPageAnnotations":
|
|
961
|
-
task = this.engine[name](...args);
|
|
962
|
-
break;
|
|
963
|
-
case "createPageAnnotation":
|
|
964
|
-
task = this.engine[name](...args);
|
|
965
|
-
break;
|
|
966
|
-
case "transformPageAnnotation":
|
|
967
|
-
task = this.engine[name](...args);
|
|
968
|
-
break;
|
|
969
|
-
case "removePageAnnotation":
|
|
970
|
-
task = this.engine[name](...args);
|
|
971
|
-
break;
|
|
972
|
-
case "getPageTextRects":
|
|
973
|
-
task = this.engine[name](...args);
|
|
974
|
-
break;
|
|
975
|
-
case "searchAllPages":
|
|
976
|
-
task = this.engine[name](...args);
|
|
977
|
-
break;
|
|
978
|
-
case "closeDocument":
|
|
979
|
-
task = this.engine[name](...args);
|
|
980
|
-
break;
|
|
981
|
-
case "saveAsCopy":
|
|
982
|
-
task = this.engine[name](...args);
|
|
983
|
-
break;
|
|
984
|
-
case "getAttachments":
|
|
985
|
-
task = this.engine[name](...args);
|
|
986
|
-
break;
|
|
987
|
-
case "readAttachmentContent":
|
|
988
|
-
task = this.engine[name](...args);
|
|
989
|
-
break;
|
|
990
|
-
case "setFormFieldValue":
|
|
991
|
-
task = this.engine[name](...args);
|
|
992
|
-
break;
|
|
993
|
-
case "flattenPage":
|
|
994
|
-
task = this.engine[name](...args);
|
|
995
|
-
break;
|
|
996
|
-
case "extractPages":
|
|
997
|
-
task = this.engine[name](...args);
|
|
998
|
-
break;
|
|
999
|
-
case "extractText":
|
|
1000
|
-
task = this.engine[name](...args);
|
|
1001
|
-
break;
|
|
1002
|
-
case "getPageGlyphs":
|
|
1003
|
-
task = this.engine[name](...args);
|
|
1004
|
-
break;
|
|
1005
|
-
case "getPageGeometry":
|
|
1006
|
-
task = this.engine[name](...args);
|
|
1007
|
-
break;
|
|
1008
|
-
case "merge":
|
|
1009
|
-
task = this.engine[name](...args);
|
|
1010
|
-
break;
|
|
1011
|
-
case "mergePages":
|
|
1012
|
-
task = this.engine[name](...args);
|
|
1013
|
-
break;
|
|
1014
|
-
}
|
|
1015
|
-
task.wait(
|
|
1016
|
-
(result) => {
|
|
1017
|
-
const response = {
|
|
1018
|
-
id: request.id,
|
|
1019
|
-
type: "ExecuteResponse",
|
|
1020
|
-
data: {
|
|
1021
|
-
type: "result",
|
|
1022
|
-
value: result
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
this.respond(response);
|
|
1026
|
-
},
|
|
1027
|
-
(error) => {
|
|
1028
|
-
const response = {
|
|
1029
|
-
id: request.id,
|
|
1030
|
-
type: "ExecuteResponse",
|
|
1031
|
-
data: {
|
|
1032
|
-
type: "error",
|
|
1033
|
-
value: error
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
this.respond(response);
|
|
1037
|
-
}
|
|
1038
|
-
);
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* Listening on post message
|
|
1043
|
-
*/
|
|
1044
|
-
listen() {
|
|
1045
|
-
self.onmessage = (evt) => {
|
|
1046
|
-
return this.handle(evt);
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
/**
|
|
1050
|
-
* Handle post message
|
|
1051
|
-
*/
|
|
1052
|
-
handle(evt) {
|
|
1053
|
-
this.logger.debug(LOG_SOURCE2, LOG_CATEGORY2, "webworker receive message event: ", evt.data);
|
|
1054
|
-
try {
|
|
1055
|
-
const request = evt.data;
|
|
1056
|
-
switch (request.type) {
|
|
1057
|
-
case "ExecuteRequest":
|
|
1058
|
-
this.execute(request);
|
|
1059
|
-
break;
|
|
1060
|
-
}
|
|
1061
|
-
} catch (e) {
|
|
1062
|
-
this.logger.info(
|
|
1063
|
-
LOG_SOURCE2,
|
|
1064
|
-
LOG_CATEGORY2,
|
|
1065
|
-
"webworker met error when processing message event:",
|
|
1066
|
-
e
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Send the ready response when pdf engine is ready
|
|
1072
|
-
* @returns
|
|
1073
|
-
*
|
|
1074
|
-
* @protected
|
|
1075
|
-
*/
|
|
1076
|
-
ready() {
|
|
1077
|
-
this.listen();
|
|
1078
|
-
this.respond({
|
|
1079
|
-
id: "0",
|
|
1080
|
-
type: "ReadyResponse"
|
|
1081
|
-
});
|
|
1082
|
-
this.logger.debug(LOG_SOURCE2, LOG_CATEGORY2, "runner is ready");
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Send back the response
|
|
1086
|
-
* @param response - response that needs sent back
|
|
1087
|
-
*
|
|
1088
|
-
* @protected
|
|
1089
|
-
*/
|
|
1090
|
-
respond(response) {
|
|
1091
|
-
this.logger.debug(LOG_SOURCE2, LOG_CATEGORY2, "runner respond: ", response);
|
|
1092
|
-
self.postMessage(response);
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
|
|
1096
|
-
export {
|
|
1097
|
-
WorkerTask,
|
|
1098
|
-
WebWorkerEngine,
|
|
1099
|
-
EngineRunner
|
|
1100
|
-
};
|
|
1101
|
-
//# sourceMappingURL=chunk-YZLT3A2D.js.map
|