diff --git a/src/core/editor/pdf_editor.js b/src/core/editor/pdf_editor.js index baaacca04..f07ddc714 100644 --- a/src/core/editor/pdf_editor.js +++ b/src/core/editor/pdf_editor.js @@ -2239,11 +2239,7 @@ class PDFEditor { if (data.parentRef) { newKid.set("Parent", data.parentRef); } - if ( - acroFormDefaultAppearance && - isName(newKid.get("FT"), "Tx") && - !newKid.has("DA") - ) { + if (acroFormDefaultAppearance && !newKid.has("DA")) { // Fix the DA later since we need to have all the fields tree. daToFix.push(newKid); } @@ -2261,6 +2257,10 @@ class PDFEditor { } for (const field of daToFix) { + const fieldType = getInheritableProperty({ dict: field, key: "FT" }); + if (!isName(fieldType, "Tx")) { + continue; + } const da = getInheritableProperty({ dict: field, key: "DA" }); if (!da) { // No DA in a parent field, we can set the default one. diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 0201f169b..2fd069643 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -7729,6 +7729,39 @@ small scripts as well as for`); await loadingTask.destroy(); }); + it("preserves conflicting DAs for inherited text fields", async function () { + const makePdf = (fontName, fieldName) => + assemblePdf([ + "1 0 obj\n<< /Type /Catalog /Pages 2 0 R " + + "/AcroForm 6 0 R >>\nendobj\n", + "2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n", + "3 0 obj\n<< /Type /Page /Parent 2 0 R " + + "/MediaBox [0 0 100 100] /Annots [4 0 R] >>\nendobj\n", + "4 0 obj\n<< /Type /Annot /Subtype /Widget /Rect [0 0 20 10] " + + "/Parent 5 0 R >>\nendobj\n", + `5 0 obj\n<< /FT /Tx /T (${fieldName}) ` + + "/Kids [4 0 R] >>\nendobj\n", + `6 0 obj\n<< /Fields [5 0 R] ` + + `/DA (/${fontName} 10 Tf) >>\nendobj\n`, + ]); + + let loadingTask = getDocument({ data: makePdf("F1", "first") }); + let pdfDoc = await loadingTask.promise; + const data = await pdfDoc.extractPages([ + { document: null }, + { document: makePdf("F2", "second") }, + ]); + await loadingTask.destroy(); + + loadingTask = getDocument({ data }); + pdfDoc = await loadingTask.promise; + const first = await (await pdfDoc.getPage(1)).getAnnotations(); + const second = await (await pdfDoc.getPage(2)).getAnnotations(); + expect(first[0].defaultAppearanceData.fontName).toEqual("F1"); + expect(second[0].defaultAppearanceData.fontName).toEqual("F2"); + await loadingTask.destroy(); + }); + it("extract page 2 and check AcroForm Fields T entries", async function () { let loadingTask = getDocument( buildGetDocumentParams("form_two_pages.pdf")