Merge pull request #21626 from calixteman/fix/pdf-editor-inherited-default-appearance

Preserve inherited text field appearances
This commit is contained in:
Tim van der Meij 2026-07-24 20:35:14 +02:00 committed by GitHub
commit 05e100c76e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 5 deletions

View File

@ -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.

View File

@ -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")