From 7f9dac9015a1391ad4c92c31d981cc26ab367c06 Mon Sep 17 00:00:00 2001 From: Zhao Dengfeng <2370187+zhaodengfeng@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:25:42 +0800 Subject: [PATCH] Don't fail getTextContent when the first text in a stream has a zero font size (issue 22381) The text state is cloned before any `Tf` is applied, so its font is `null` and its font size is `0`. When the first text shown uses a zero font size, the font size comparison in `buildTextContentItem` is equal, and the font name comparison then reads `name` from that `null` font. With the default `ignoreErrors`, all of the text on the page was dropped. --- src/core/evaluator.js | 4 ++-- test/pdfs/.gitignore | 1 + test/pdfs/issue22381.pdf | Bin 0 -> 613 bytes test/test_manifest.json | 7 +++++++ test/unit/api_spec.js | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/issue22381.pdf diff --git a/src/core/evaluator.js b/src/core/evaluator.js index d974b75a593c0..b5e2dd96cdbef 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -2982,8 +2982,8 @@ class PartialEvaluator { currentTextState !== textState && (currentTextState.fontSize !== textState.fontSize || (currentTextState.fontName !== textState.fontName && - (currentTextState.font.name !== textState.font.name || - currentTextState.font.vertical !== textState.font.vertical))) + (currentTextState.font?.name !== textState.font?.name || + currentTextState.font?.vertical !== textState.font?.vertical))) ) { flushTextContentItem(); currentTextState = textState.clone(); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 6db7cfe8b5073..3313b4d784e02 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -189,6 +189,7 @@ !bug1337429.pdf !bug1606566.pdf !bug2086012.pdf +!issue22381.pdf !issue5564_reduced.pdf !canvas.pdf !bug1132849.pdf diff --git a/test/pdfs/issue22381.pdf b/test/pdfs/issue22381.pdf new file mode 100644 index 0000000000000000000000000000000000000000..b395bb90d435a4acb4c65bcb5988564a822aa099 GIT binary patch literal 613 zcmZWnO-}+b5WV+T%!LFG+AaGLNC*cMVxmR@8!yB|VFxH#w`N-m`sFTb>s_XMvv_gmI3j@AOICbG;fa19?CTtVy9C}9o3J5 zm=#HfKawpxO>+=6XltAIt@<+-Tfc*3!0wzcQGbYWN>e$EbOYU;$ucZ%Al<_xZA-m~ zYheNjkuvDM8D~~Gg2$t8sgzMOuStu|wX$`*m36r|tbCO=g9_wWJFF{@n17)+Ykd*j zvBZrCAQ8c7K@!Jd3>!FO1E{J{oUyong(*dzcwO*%5uN-W7Sb_Km@l=-v8-On!u%j4 ZbR*XC1vjt5d0qO-XA}ma)0w