1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { getPdfFilenameFromUrl, loadScript } from "pdfjs-lib";
- async function docPropertiesLookup(pdfDocument) {
- const url = "",
- baseUrl = url.split("#")[0];
-
- let { info, metadata, contentDispositionFilename, contentLength } =
- await pdfDocument.getMetadata();
- if (!contentLength) {
- const { length } = await pdfDocument.getDownloadInfo();
- contentLength = length;
- }
- return {
- ...info,
- baseURL: baseUrl,
- filesize: contentLength,
- filename: contentDispositionFilename || getPdfFilenameFromUrl(url),
- metadata: metadata?.getRaw(),
- authors: metadata?.get("dc:creator"),
- numPages: pdfDocument.numPages,
- URL: url,
- };
- }
- class GenericScripting {
- constructor(sandboxBundleSrc) {
- this._ready = loadScript(
- sandboxBundleSrc,
- true
- ).then(() => {
- return window.pdfjsSandbox.QuickJSSandbox();
- });
- }
- async createSandbox(data) {
- const sandbox = await this._ready;
- sandbox.create(data);
- }
- async dispatchEventInSandbox(event) {
- const sandbox = await this._ready;
- setTimeout(() => sandbox.dispatchEvent(event), 0);
- }
- async destroySandbox() {
- const sandbox = await this._ready;
- sandbox.nukeSandbox();
- }
- }
- export { docPropertiesLookup, GenericScripting };
|