NumberFormat 语言环境导致 PdfBox / Boxable 出错

NumberFormat locale leads to error in PdfBox / Boxable

我在 PdfBox 2.0.20 (+Boxable 1.5) 中使用 NumberFormat 在一台机器上获取 € 符号时遇到奇怪的错误。不过在其他机器上它可以正常工作。

NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
BaseTable table = new BaseTable(...);
Row<PDPage> row = table.createRow(10f);
row.createCell(20, currencyFormatter.format(9.99));
float rowHeight = row.getHeight();

这已经在 3 台以上的机器上正常工作了 2 年多了。在新电脑上访问高度时,最后一行出现错误:

java.lang.IllegalArgumentException: U+00A0 ('nbspace') is not available in this font Helvetica encoding: WinAnsiEncoding

错误消息对我来说很奇怪。我没有使用 U+00A0 符号,我认为问题与 € 符号有关。 当我在新电脑上使用 Locale.US 时,它使用 $ 并且错误消失了。不过我希望能够使用德国货币。

将 pdfBox 更新到 2.0.22 解决了这个问题。

https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox/2.0.22