Set the XFA fonts when the AcroForm has no fonts in /DR

`#loadXfaFonts` returned before `setFonts` when /DR or /DR /Font was missing,
and the layout then threw at the first text it measured. With an empty font
dictionary, pdf.js loads a substitute for each font the form uses, as it does
for a font missing from /DR.

The PDF in #13647 has no /DR either.
This commit is contained in:
Patrick Domack
2026-11-19 17:13:04 -05:00
parent fc0822a07e
commit 3fcff09111
4 changed files with 19 additions and 6 deletions
+9 -6
View File
@@ -1382,15 +1382,18 @@ class PDFDocument {
if (!acroForm) {
return;
}
const resources = await acroForm.getAsync("DR");
if (!(resources instanceof Dict)) {
return;
// Without any fonts in /DR, the XFA layout still needs a font finder:
// the fonts it uses are then all loaded as missing fonts.
let resources = await acroForm.getAsync("DR");
if (resources instanceof Dict) {
await ObjectLoader.load(resources, ["Font"], this.xref);
} else {
resources = Dict.empty;
}
await ObjectLoader.load(resources, ["Font"], this.xref);
const fontRes = resources.get("Font");
let fontRes = resources.get("Font");
if (!(fontRes instanceof Dict)) {
return;
fontRes = Dict.empty;
}
const options = Object.assign(
+1
View File
@@ -638,6 +638,7 @@
!issue20324.pdf
!bug1815476.pdf
!issue16021.pdf
!xfa_without_dr_fonts.pdf
!bug1770750.pdf
!issue19971.pdf
!issue16063.pdf
Binary file not shown.
+9
View File
@@ -8000,6 +8000,15 @@
"rounds": 1,
"type": "eq"
},
{
"id": "xfa_without_dr_fonts",
"file": "pdfs/xfa_without_dr_fonts.pdf",
"md5": "80d3a2f5eb7332010ca35d33348d4011",
"rounds": 1,
"enableXfa": true,
"type": "eq",
"about": "Pure XFA form without fonts in the AcroForm /DR."
},
{
"id": "issue3207",
"file": "pdfs/issue3207r.pdf",