From 3fcff09111ff902956fcb6894c079fd39e749c63 Mon Sep 17 00:00:00 2001 From: Patrick Domack Date: Wed, 18 Nov 2026 23:13:40 -0500 Subject: [PATCH] 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. --- src/core/document.js | 15 +++++++++------ test/pdfs/.gitignore | 1 + test/pdfs/xfa_without_dr_fonts.pdf | Bin 0 -> 1880 bytes test/test_manifest.json | 9 +++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 test/pdfs/xfa_without_dr_fonts.pdf diff --git a/src/core/document.js b/src/core/document.js index 8c3dd6f5c..7a01d94ca 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -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( diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 565bb239d..1cff29819 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -638,6 +638,7 @@ !issue20324.pdf !bug1815476.pdf !issue16021.pdf +!xfa_without_dr_fonts.pdf !bug1770750.pdf !issue19971.pdf !issue16063.pdf diff --git a/test/pdfs/xfa_without_dr_fonts.pdf b/test/pdfs/xfa_without_dr_fonts.pdf new file mode 100644 index 0000000000000000000000000000000000000000..fd0788426704a93f7c73c7b9f3e7d21dce2e2c0c GIT binary patch literal 1880 zcma)74NMbf7_Pc(oaj-TZ(=#^60}2HgfGp9> zu{xG32FkJjSrA%y19Vy-XLs6wz`0SXwnTtV-p)FCfa@hDCu#jZk{BN5LJmIxGQ>S8 zauHkw9Uu-QB#d1IDv9-A+JEaBlOxNpTXI z(F=0vB?3YK;^F!DZpZvgAov*9s?|B$~+W!De4_FMY>pC7|+pQWcj3?u$T$1 zMbK#z3Q?9!XLksYLw8&_8JbxO#5ufx$%&HRW{A+5hV_m^R;wi^Y zDm|SzHaIj;HuOr)lO2Yk@&SG*+CU8M>^&oDFunCKSRtNKfI>yw|LAyUd3N?``O7W+ z8_L>l9z6HS)|S)nSJgc3PBeFV1?Ka+eeX?gY8>gw+}PZFV_k%zV~urRfw8T-=xF6i z*Dv)%^xcufE$91pR9{IeOuuRsYhpY}1^cg?Dtce|CQnq`7p5(IyQD9bSup!pLg_Z~ zlW9MB78wnxqYt{)pBA;|R}5ywyZH-j>g62Mm-qIIsL*|F12wPDah4mqW@lwwkN%@o1y8w$YayIRk{mM_1jhuHLoByyRkWbYouMAK_c()b+n+ z|2nSV{%2de%%jDf+k1{5%3E0Y{liA~fW0Is`P8qQcAGb>Q9g51|N63`)o-53 zjYzpQ?}{h$et3Q~y>6Xy{%z~eqYDlY&l>g`d%Zs`viL=0A6v zt@;jMRzve%X0ADALrTcOZz~_IXwofR z7aR~o>fIa!*judFgIC*yLe?z+S+W5E$gZT5%%X&YRzeO)l8`@NKtO2ju+U ztsMJWi26lt&9eAo;CJpcr