Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFBOX : U+000A ('controlLF') is not available in this font Helvetica encoding: WinAnsiEncoding

Tags:

java

pdfbox

When trying to print a PDF page using Java and the org.apache.pdfbox library, I get this error:

PDFBOX : U+000A ('controlLF') is not available in this font Helvetica encoding: WinAnsiEncoding

like image 507
ibercode Avatar asked Oct 09 '17 10:10

ibercode


2 Answers

[PROBLEM] The String you are trying to display contains a newline character.

[SOLUTION] Replace the String with a new one and remove the newline:

text = text.replace("\n", "").replace("\r", "");
like image 178
ibercode Avatar answered Sep 22 '22 19:09

ibercode


The answer selected for this post works, replacing all instances of \n and \r from your string, if you know that it's a \n or \r character that's causing your problem. I've discovered that there are lots of different characters that will produce this error. Here's a sampling of those that I've found:

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

In my case, I've simply chosen to remove any special character that's not included in my font. I used the solution from this page:

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

like image 20
Stephen Avatar answered Sep 21 '22 19:09

Stephen