title: iText + HTMLWorker - How to change default font?
body: <p>I have to create a PDF file from a HTML source. Currently, I'm coping with problem concerning special (polish) characters in the output file, precisely with their lack.</p>
  
  <p>HTML source:  </p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table width="100%" border="0.5" align="center" cellpadding="0" style="border-collapse:collapse; border:1px solid black; font-family:Arial, Helvetica, sans-serif; font-size:16px"&gt;
    &lt;tr&gt;
      &lt;td align="center" &gt;&lt;b&gt;Test: ąęłóćńśŁÓŃĆŻŹąśżźłęó&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Java source:</p>
  
  <pre><code>Document document = new Document(PageSize.A4, 38, 38, 50, 38);  
  PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("iTextExample.pdf"));  
  document.open();  
  HTMLWorker htmlWorker = new HTMLWorker(document);  
  htmlWorker.parse(new StringReader(readFileAsString("index.html")));  
  document.close();
  
  
  public static String readFileAsString(String filePath) throws IOException {
      DataInputStream dis = new DataInputStream(new FileInputStream(filePath));
      try {
          long len = new File(filePath).length();
          if (len &gt; Integer.MAX_VALUE) {
              throw new IOException("File " + filePath + " too large, was " + len + " bytes.");
          }
          byte[] bytes = new byte[(int) len];
          dis.readFully(bytes);
          return new String(bytes, "UTF-8");
      } finally {
          dis.close();
      }
  }
  </code></pre>
  
  <p>My question is: <strong>how to change default font (Helvetica) to eg. Arial Bold in whole PDF document?</strong></p>
  
  <p>I've tested many examples connected with StyleSheet and none of them worked. I have to change a default font, because there's no polish characters - that's the solution I hope is going to work.</p>
  
  <p><strong>Edit:</strong>  </p>
  
  <pre><code>class defaultFontProvider extends FontFactoryImp {
  
      private String _default;
  
      public defaultFontProvider(String def) {
          _default = def;
      }
  
      public Font getFont(String fontName, String encoding, boolean embedded, float size, int style, BaseColor color, boolean cached) {
          if (fontName == null || size == 0) {
              fontName = _default;
          }
  
          return super.getFont(fontName, encoding, embedded, size, style, color, cached);
      }
  }
  </code></pre>
  
  <p>The code above embeds <code>arial.ttf</code> which is OK, but how do I make it the default font (instead of Helvetica) for the whole document.</p>
  
  <p>Then..</p>
  
  <pre><code>Map&lt;String,Object&gt; providers = new HashMap&lt;String, Object&gt;();
  
  defaultFontProvider dfp = new defaultFontProvider("arial.ttf");
  
  providers.put(HTMLWorker.FONT_PROVIDER, dfp);
  
  HTMLWorker htmlWorker = new HTMLWorker(document);
  htmlWorker.setProviders(providers);
  </code></pre>