I am creating PDF documents from user inputs that are UTF-8.
Beyond displaying the PDFs, the creation itself fails with java.lang.IllegalArgumentException: U+039B is not available in this font's encoding: WinAnsiEncoding.
Most answers here point to "using a font with better UTF-8 support", but as I have no control over user inputs, this UTF-8 support is never going to be good enough and I need a bullet proof solution (as in print something rather than error out).
The answer Using PDFBox to write unicode strings to a PDF suggests that the text should be sanitised before it is added to the PDF.
The issue is that I cannot find valid example to achieve this.
All examples seem to be pointing at removed code (font.setToUnicodeor some method in encoding to convert characters one at a time).
So in a nutshell, I have a string I want a bullet proof method to write most of it to a PDFBox document (obviously, missing characters in the font will be replaced or not printed).
Many thanks, JM