title: How to sanitise a string before printing it to PDF with PDFBox
body: <p>I am creating PDF documents from user inputs that are UTF-8.</p>
  
  <p>Beyond displaying the PDFs, the creation itself fails with <code>java.lang.IllegalArgumentException: U+039B is not available in this font's encoding: WinAnsiEncoding</code>.</p>
  
  <p>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).</p>
  
  <p>The answer <a href="https://stackoverflow.com/questions/28565501/using-pdfbox-to-write-unicode-strings-to-a-pdf">Using PDFBox to write unicode strings to a PDF</a> suggests that the text should be sanitised before it is added to the PDF.</p>
  
  <p>The issue is that I cannot find valid example to achieve this.
  All examples seem to be pointing at removed code (<code>font.setToUnicode</code>or some method in encoding to convert characters one at a time).</p>
  
  <p>So in a nutshell, I have a string I want a bullet proof method to write <strong>most of it</strong> to a PDFBox document (obviously, missing characters in the font will be replaced or not printed). </p>
  
  <p>Many thanks,
  JM  </p>