diff --git a/src/core/document.js b/src/core/document.js index 1744066d1d625..2d74009d7b42a 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -20,6 +20,7 @@ import { info, InvalidPDFException, isArrayEqual, + objectSize, PageActionEventType, RenderingIntentFlag, shadow, @@ -1775,6 +1776,13 @@ class PDFDocument { if (!(field instanceof Dict)) { return; } + let subtype = await field.getAsync("Subtype"); + subtype = subtype instanceof Name ? subtype.name : null; + // Skip unrelated annotation types (see issue 19281). + switch (subtype) { + case "Link": + return; + } if (field.has("T")) { const partName = stringToPDFString(await field.getAsync("T")); name = name === "" ? partName : `${name}.${partName}`; @@ -1890,9 +1898,12 @@ class PDFDocument { }) ); } - await Promise.all(allPromises); - return { allFields, orphanFields }; + + return { + allFields: objectSize(allFields) > 0 ? allFields : null, + orphanFields, + }; }); return shadow(this, "fieldObjects", promise); @@ -1915,7 +1926,7 @@ class PDFDocument { if (catalogJsActions) { return true; } - if (fieldObjects) { + if (fieldObjects?.allFields) { return Object.values(fieldObjects.allFields).some(fieldObject => fieldObject.some(object => object.actions !== null) ); diff --git a/test/pdfs/issue19281.pdf.link b/test/pdfs/issue19281.pdf.link new file mode 100644 index 0000000000000..1aeac656d4208 --- /dev/null +++ b/test/pdfs/issue19281.pdf.link @@ -0,0 +1 @@ +https://github.com/user-attachments/files/18304780/Antarctica-Grid.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 6dd3446ed4cfc..1a274fb5b7511 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -11239,5 +11239,13 @@ "link": true, "disableFontFace": true, "type": "eq" + }, + { + "id": "issue19281", + "file": "pdfs/issue19281.pdf", + "md5": "c5db558965e4189cc6db2720cdaa3e55", + "rounds": 1, + "link": true, + "type": "other" } ] diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 2abced6f3dfa7..4cf594cd78bf4 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -1713,6 +1713,20 @@ describe("api", function () { await loadingTask.destroy(); }); + it("gets fieldObjects and skipping LinkAnnotations", async function () { + if (isNodeJS) { + pending("Linked test-cases are not supported in Node.js."); + } + + const loadingTask = getDocument(buildGetDocumentParams("issue19281.pdf")); + const pdfDoc = await loadingTask.promise; + const fieldObjects = await pdfDoc.getFieldObjects(); + + expect(fieldObjects).toEqual(null); + + await loadingTask.destroy(); + }); + it("gets non-existent calculationOrder", async function () { const calculationOrder = await pdfDocument.getCalculationOrderIds(); expect(calculationOrder).toEqual(null);