title: How to print `Non-breaking space` to a pdf using apache pdf box?
body: <pre><code>final String NBSP = new String("\u00a0");
  contentStream.showText("Konichua!" + NBSP);
  </code></pre>
  
  <p>this throws the following exception:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: U+00A0 ('nbspace') is not
    available in this font Courier encoding: WinAnsiEncoding</p>
  </blockquote>
  
  <p>I have tried it with all the 3 fonts available; TimesNewRoman, Courier &amp; Helvitica with all 3 resulting in the same exception.</p>
  
  <p>But when you look at the <strong>WIN_ANSI_ENCODING_TABLE</strong> present in the source code of apcahe pdfBox,</p>
  
  <pre><code>    {040, "space"},
      {0243, "sterling"},
       .
       .
  
      // adding some additional mappings as defined in Appendix D of the pdf spec
      {0240, "space"},
      {0255, "hyphen"}
  </code></pre>
  
  <p>we can see that the below <em>Non-breaking space</em> is defined.</p>
  
  <pre>
  DEC     OCT     HEX     BIN       Symbol     Description
  </pre>
  
  <pre>
  160    240      A0      10100000              Non-breaking space
  </pre>
  
  <p>In the pdf specification <a href="https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf" rel="nofollow noreferrer">document</a>
  the following is quoted too:</p>
  
  <blockquote>
    <p>The  SPACE  character  shall  also  be  encoded  as  312  in  MacRomanEncoding  and  as  240  in  WinAnsiEncoding
    . This duplicate code shall signify a nonbreaking space; it shall be typographically the same as (U+003A) SPACE. </p>
  </blockquote>
  
  <hr>
  
  <p>Use case: </p>
  
  <p>To increase the width of header txt columns by adding padding with NBSP, so that it is not removed when <code>string.trim()</code> is called on header columns.</p>