-2

here is my problem.

When my webapp prints a text that i'm escaping with StringEscapeUtils library, if the text contains 'ÁÉÍÓÚ' in the PDF result missing those letters, only if they are uppercase.

for example: 'LOS MÉDICOS ESTÁN EN EL TURNO DE DÍA' The result: 'LOS MDICOS ESTN EN EL TURNO DE DA'

For some reason its ignoring the uppercase char with accent

Do you know any way to escape uppercase text using StringEscapeUtils??

Thanks

1 Answers1

0

May I suggest a different library - I wrote my own Open Source library that contains several Utils. One of them is encoding string to unicode sequence and decoding unicode sequence back to regualr String. For example a String "Hello World" will be converted into

"\u0048\u0065\u006c\u006c\u006f\u0020
\u0057\u006f\u0072\u006c\u0064"


and may be restored back. In your case I ran the following code:

String s = "LOS MÉDICOS ESTÁN EN EL TURNO DE DÍA";
System.out.println("Original String: " + s);
s = StringUnicodeEncoderDecoder.encodeStringToUnicodeSequence(s);
System.out.println("Encoded String: " + s);
s = StringUnicodeEncoderDecoder.decodeUnicodeSequenceToString(s);
System.out.println("Decoded String: " + s);

And received result as expected (no symbols missing):

Original String: LOS MÉDICOS ESTÁN EN EL TURNO DE DÍA
Encoded String: \u004c\u004f\u0053\u0020\u004d\u00c9\u0044\u0049\u0043\u004f\u0053\u0020\u0045\u0053\u0054\u00c1\u004e\u0020\u0045\u004e\u0020\u0045\u004c\u0020\u0054\u0055\u0052\u004e\u004f\u0020\u0044\u0045\u0020\u0044\u00cd\u0041
Decoded String: LOS MÉDICOS ESTÁN EN EL TURNO DE DÍA

In some cases involving symbols from characterset different from ISO-8859-1 I found that sending Unicode sequence instead of character sequence often resolves a lot of problems such as symbols replaced with '?' or giberish. The reason is that each Unicode sequence '\UXXXX' is uniquely mapped tp a symbol and can not be misstranslated. This is sort of workaround as the real problem usually resolved by properly cnfiguring character set or encoding settings, but in many cases such conversion helped me to diagnose the problem and then resolve it. But like I said, you could just convert your string to Unicode sequence and send it to your webapp. It should work. Here is the link to an article that describes the MgntUtils Open source library: Open Source Java library with stack trace filtering, Silent String parsing Unicode converter and Version comparison. The article at the very beginning explains where to get the library and how to use it. It is available as maven artifact from maven central and also on github. So you can get it as an artifact to include in your project or/and get the sources and Javadoc as well. In the article search for "String Unicode converter" paragraph to see an explanation about StringUnicodeEncoderDecoder

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36