2

My LOG

exception is java.lang.IllegalArgumentException: U+0009 ('controlHT') is not available in this font Helvetica (generic: ArialMT) encoding: WinAnsiEncoding] with root cause java.lang.IllegalArgumentException: U+0009 ('controlHT') is not available in this font Helvetica (generic: ArialMT) encoding: WinAnsiEncoding

MARWAN AMEEN
  • 429
  • 5
  • 11
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Matt Mar 23 '17 at 04:04
  • You simply try to draw a character for which the font does not contain a glyph. In your case it is a control character, the horizontal tab, for which hardly any font has a glyph. – mkl Mar 23 '17 at 05:24
  • https://pdfbox.apache.org/2.0/faq.html#fontencoding – Tilman Hausherr Mar 23 '17 at 06:40
  • Why does the title mention a NullPointerException, but the body an IllegalArgumentException? – Tilman Hausherr Mar 23 '17 at 07:07
  • @marwn It is good you removed the NPE from the title, but could you also react to the other comments here? After all they do explain why your exception happens. Did that information already allow you to fix the issue or do you still have problems? – mkl Mar 27 '17 at 14:06
  • @mkl thanks lot for your feed back, and comments. Anyway as you stated above it might be the horizontal tab what cause the issue, i am trying to test that as i got busy last week, i have not got the chance to test. – MARWAN AMEEN Mar 28 '17 at 01:52
  • string.replaceAll("\t", " ") worked fine for me .. thanks lot again .. – MARWAN AMEEN Mar 28 '17 at 02:21
  • I'll make that an actual answer (in contrast to a mere comment as above) which you can accept so the question will appear answered. – mkl Mar 28 '17 at 04:17

1 Answers1

9

The exception message

U+0009 ('controlHT') is not available in this font Helvetica (generic: ArialMT) encoding: WinAnsiEncoding

means that the string you draw contains a character for which the font (in particular in its selected encoding) provides no glyph drawing instructions.

It even indicates which character is the culprit: "U+0009 ('controlHT')", i.e. a control character, the horizontal tab. Indeed, control characters have to be avoided as hardly any font will contain glyphs for them.

As you already have confirmed in the comments to your question

string.replaceAll("\t", " ") worked fine for me

So horizontal tabs seem to have been the only problem characters.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • so far horizontal tabs what cause the problems, yet i do not know if string.replaceAll("\t", " ") is the idle solution as i have to check every string i am drawing in the pdf.. – MARWAN AMEEN Mar 29 '17 at 02:27
  • @marwn Well, it would be easier if you could make sure that the source you retrieve those strings from only supplies strings with drawable characters. As you have not indicated where you get them from, though, I hardly can guess how to do that exactly. – mkl Mar 29 '17 at 04:17
  • my string sources are retrieved from database, mostly the were inserted from a form .. – MARWAN AMEEN Mar 29 '17 at 05:40
  • Then I would advice sanitizing already the form input. Control characters should not be written into database fields meant for a use as yours. – mkl Mar 29 '17 at 07:50