UNPKG

2.22 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * JavaScript code in this page
4 *
5 * Copyright 2022 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * JavaScript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.GenericScripting = void 0;
28exports.docPropertiesLookup = docPropertiesLookup;
29
30var _pdf = require("../pdf");
31
32async 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
60class 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
84exports.GenericScripting = GenericScripting;
\No newline at end of file