1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.GenericScripting = void 0;
|
28 | exports.docPropertiesLookup = docPropertiesLookup;
|
29 |
|
30 | var _pdf = require("../pdf");
|
31 |
|
32 | async function docPropertiesLookup(pdfDocument) {
|
33 | const url = "",
|
34 | baseUrl = url.split("#")[0];
|
35 | let {
|
36 | info,
|
37 | metadata,
|
38 | contentDispositionFilename,
|
39 | contentLength
|
40 | } = await pdfDocument.getMetadata();
|
41 |
|
42 | if (!contentLength) {
|
43 | const {
|
44 | length
|
45 | } = await pdfDocument.getDownloadInfo();
|
46 | contentLength = length;
|
47 | }
|
48 |
|
49 | return { ...info,
|
50 | baseURL: baseUrl,
|
51 | filesize: contentLength,
|
52 | filename: contentDispositionFilename || (0, _pdf.getPdfFilenameFromUrl)(url),
|
53 | metadata: metadata?.getRaw(),
|
54 | authors: metadata?.get("dc:creator"),
|
55 | numPages: pdfDocument.numPages,
|
56 | URL: url
|
57 | };
|
58 | }
|
59 |
|
60 | class GenericScripting {
|
61 | constructor(sandboxBundleSrc) {
|
62 | this._ready = (0, _pdf.loadScript)(sandboxBundleSrc, true).then(() => {
|
63 | return window.pdfjsSandbox.QuickJSSandbox();
|
64 | });
|
65 | }
|
66 |
|
67 | async createSandbox(data) {
|
68 | const sandbox = await this._ready;
|
69 | sandbox.create(data);
|
70 | }
|
71 |
|
72 | async dispatchEventInSandbox(event) {
|
73 | const sandbox = await this._ready;
|
74 | setTimeout(() => sandbox.dispatchEvent(event), 0);
|
75 | }
|
76 |
|
77 | async destroySandbox() {
|
78 | const sandbox = await this._ready;
|
79 | sandbox.nukeSandbox();
|
80 | }
|
81 |
|
82 | }
|
83 |
|
84 | exports.GenericScripting = GenericScripting; |
\ | No newline at end of file |