diff --git a/src/core/document.js b/src/core/document.js index 194a8887f..86a1ac031 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1104,8 +1104,8 @@ class PDFDocument { }); } - parse(recoveryMode) { - this.xref.parse(recoveryMode); + async parse(recoveryMode) { + await this.xref.parse(recoveryMode); this.catalog = new Catalog(this.pdfManager, this.xref); this.xfaFactory = null; } diff --git a/src/core/xref.js b/src/core/xref.js index c67faddf7..dc85e88e3 100644 --- a/src/core/xref.js +++ b/src/core/xref.js @@ -30,7 +30,6 @@ import { XRefParseException, } from "./core_utils.js"; import { BaseStream } from "./base_stream.js"; -import { CipherTransformFactory } from "./crypto.js"; class XRef { #cacheMap = new Map(); @@ -116,7 +115,7 @@ class XRef { this.startXRefQueue = [startXRef]; } - parse(recoveryMode = false) { + async parse(recoveryMode = false) { this.#parsedWithRecovery = recoveryMode; let trailerDict; if (!recoveryMode) { @@ -140,6 +139,9 @@ class XRef { if (encrypt instanceof Dict) { const ids = trailerDict.get("ID"); const fileId = ids?.length ? ids[0] : ""; + const { CipherTransformFactory } = await import( + /* webpackChunkName: "crypto" */ "./crypto.js" + ); // The 'Encrypt' dictionary itself should not be encrypted, and by // setting `suppressEncryption` we can prevent an infinite loop inside // of `XRef_fetchUncompressed` if the dictionary contains indirect diff --git a/test/unit/cff_parser_spec.js b/test/unit/cff_parser_spec.js index 1476da5d5..589f3df23 100644 --- a/test/unit/cff_parser_spec.js +++ b/test/unit/cff_parser_spec.js @@ -381,7 +381,7 @@ describe("CFFParser", function () { }; const pdfDocument = new PDFDocument(pdfManager, new Stream(data)); pdfDocument.parseStartXRef(); - pdfDocument.xref.parse(); + await pdfDocument.xref.parse(); // Object 8 is the `/FontFile3` (`/CIDFontType0C`) stream in the fixture. const fontProgram = pdfDocument.xref.fetch(Ref.get(8, 0)).getBytes();