PDFBOX : U+000A ('controlLF') 在此字体中不可用 Helvetica 编码: WinAnsiEncoding

2022-09-03 09:49:20

尝试使用Java和库打印PDF页面时,我收到以下错误:org.apache.pdfbox

PDFBOX : U+000A ('controlLF') 在此字体中不可用 Helvetica 编码: WinAnsiEncoding


答案 1

[问题]您尝试显示的字符串包含换行符。

[解决方案]将字符串替换为新字符串并删除换行符:

text = text.replace("\n", "").replace("\r", "");

答案 2

为这篇文章选择的答案有效,如果您知道是\n或\r字符导致了您的问题,则可以从字符串中替换\n和\r的所有实例。我发现有很多不同的字符会产生此错误。以下是我发现的那些示例:

U+2010 ('hyphentwo') is not available in this font Helvetica encoding: WinAnsiEncoding
U+2033 ('second') is not available in this font Helvetica encoding: WinAnsiEncoding
U+00A0 ('nbspace') is not available in this font Helvetica encoding: WinAnsiEncoding
U+FFFD ('.notdef') is not available in this font Helvetica encoding: WinAnsiEncoding
U+03BC ('mugreek') is not available in this font Helvetica encoding: WinAnsiEncoding
U+039C ('Mu') is not available in this font Helvetica encoding: WinAnsiEncoding
U+2212 ('minus') is not available in this font Helvetica encoding: WinAnsiEncoding
U+0141 ('Lslash') is not available in this font Helvetica encoding: WinAnsiEncoding
U+2103 ('centigrade') is not available in this font Helvetica encoding: WinAnsiEncoding
U+25AA ('H18543') is not available in this font Helvetica encoding: WinAnsiEncoding

就我而言,我只是选择删除字体中未包含的任何特殊字符。我使用了此页面中的解决方案:

https://cmsdk.com/java/remove-illegal-characters-from-string-with-pdfbox.html


推荐