1

I am experiencing a weird error in PdfBox 2.0.20 (+Boxable 1.5) when using NumberFormat to get the € symbol on one machine. On other machines it works with no issues though.

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();

This works fine on 3+ machines for more than 2 years now. On a new pc I get an error on the last line when the height gets accessed:

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

The error message is weird to me. I did not use the U+00A0 symbol and I think the issue is related to the € symbol. When I use Locale.US on the new pc, it uses $ and the error disappears. I want to be able to use the german currency though.

Tigerware
  • 3,196
  • 2
  • 23
  • 39
  • The `BaseTable` and `Row` classes are not from pdfbox but some other library used on top of it. Please mention that library and its version. – mkl Jun 16 '20 at 05:17
  • 1
    Other than that I'm surprised that there non breaking space is claimed not to be in WinAnsiEncoding because it is. – mkl Jun 16 '20 at 05:19
  • You are right. I am using boxable as well to create a table layout in pdfbox. – Tigerware Jun 16 '20 at 05:28
  • The euro symbol is 0200 (0x80) in WinAnsiEncoding, not 0240 (0xA0). – Tilman Hausherr Jun 16 '20 at 07:51
  • Probably there is a nbspace between the amount and the unit? – mkl Jun 16 '20 at 12:11
  • @BluE what output do you get from `System.out.println(Arrays.toString(currencyFormatter.format(9.99).getBytes()));`? – Tilman Hausherr Jun 16 '20 at 12:31
  • @TilmanHausherr I get different results depending on the locale. Locale.GERMANY: `[57, 44, 57, 57, -62, -96, -30, -126, -84]` Locale.GERMAN: `[57, 44, 57, 57, -62, -96, -62, -92]` Locale.US: `[36, 57, 46, 57, 57]` – Tigerware Jun 16 '20 at 14:43
  • 1
    `[-62, -96]` is the non-breaking space; `[-30, -126, -84]` is € (EURO); `[-62, -92]` is ¤ (some generic currency symbol - https://en.wikipedia.org/wiki/Currency_sign_(typography) ). Thus, as conjectured above, there is a nbspace between the amount and the unit. Nonetheless, the actual issue is why the non breaking space is claimed not to be in WinAnsiEncoding. – mkl Jun 16 '20 at 16:00
  • 1
    Will do, https://issues.apache.org/jira/browse/PDFBOX-4891 . In the meantime, please replace it with space as a workaround. – Tilman Hausherr Jun 16 '20 at 17:04
  • https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.21-SNAPSHOT/ – Tilman Hausherr Jun 17 '20 at 06:37

1 Answers1

1

Updating pdfBox to 2.0.22 fixed the problem.

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

Tigerware
  • 3,196
  • 2
  • 23
  • 39
  • @TilmanHausherr: I thought it did fix it, but I am getting the error again now with pdfbox 2.0.21 (with java 14). – Tigerware Nov 08 '20 at 18:48
  • The the 2.0.22 snapshot https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.22-SNAPSHOT/ make sure to delete old versions from your classpath – Tilman Hausherr Nov 09 '20 at 08:57
  • I'm not sure how to use that with maven yet. I might wait for the official release. – Tigerware Nov 09 '20 at 12:38
  • In maven, you put 2.0.22-SNAPSHOT, and you may have to add the apache repository in your pom.xml file. – Tilman Hausherr Nov 09 '20 at 12:50