Handling ToUnicode Mapping Errors in PDF Text Editing (fpdf_edit_text.cpp) – Specifically for Missing CharCode of Space Character (Unicode 32) in Fully Embedded Microsoft YaHei Font, Seeking Official Recommended Solutions.

63 views
Skip to first unread message

李寻欢

unread,
Jun 16, 2025, 11:15:23 PMJun 16
to pdfium
When handling the ToUnicode writing error in fpdf_edit_text.cpp, I noticed that for the fully embedded Microsoft YaHei font, the space character (Unicode 32) cannot be mapped to a corresponding CharCode. My current workaround is to manually add a dedicated entry for the space character to the ToUnicode stream. Could the official team suggest a more elegant or standard solution? Your assistance would be greatly appreciated!

Lei Zhang

unread,
Jun 18, 2025, 2:36:31 PMJun 18
to 李寻欢, pdfium
Hi,

1) There's no fpdf_edit_text.cpp, I believe you meant fpdf_edittext.cpp?

2) fpdf_edittext.cpp is over 1000 lines long. What function are you
referring to?

3) It sounds like you are dealing with a particular PDF that has some
embedded font. Can you share the PDF for reference?

On Mon, Jun 16, 2025 at 8:15 PM 李寻欢 <20021...@gmail.com> wrote:
>
> When handling the ToUnicode writing error in fpdf_edit_text.cpp, I noticed that for the fully embedded Microsoft YaHei font, the space character (Unicode 32) cannot be mapped to a corresponding CharCode. My current workaround is to manually add a dedicated entry for the space character to the ToUnicode stream. Could the official team suggest a more elegant or standard solution? Your assistance would be greatly appreciated!
>
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/pdfium/3df4baf5-0a5d-4661-837e-fca479a0271cn%40googlegroups.com.

吴吴

unread,
Jul 8, 2025, 1:35:43 AMJul 8
to pdfium
I also encountered this problem by using the FPDFText_LoadFont() API to load Microsoft Yahei font. The font_type is FPDF-FONTTRUETYPE and cid is true. Setting the space character is invalid because Chinese characters need to be drawn, so the font_type is FPDF-FONTTRUETYPE

吴吴

unread,
Jul 8, 2025, 1:39:54 AMJul 8
to pdfium
For example, I need to use this text   "我爱 中国"  ,   This space character is invalid, pTextObj ->GetFont() ->CharCodeFromUnicode (wc) returns a value of 0
f629ebfd-90cf-496a-bba5-f0c118638c4e.png
在2025年6月19日星期四 UTC+8 02:36:31<Lei Zhang> 写道:
Reply all
Reply to author
Forward
0 new messages