title: Arabic caracters in html to pdf using iText
body: <p>I've gone through avery iText topic related to arabic caracters on stackoverflow already, but didn't find an answer for this one.
  I need to convert an html file in to pdf, but this html contains both english and arabic caracters.
  Displaying the html in Notepadd++ or in any browser, there is no problem, I can see arabic caracters properly, but when I use the following program to convert into pdf, I can't figure out a way to display arabic caracters, I only get "?" instead :</p>
  
  <pre><code>import java.io.ByteArrayInputStream;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.nio.charset.Charset;
  import org.apache.commons.io.IOUtils;
  import com.itextpdf.text.Document;
  import com.itextpdf.text.FontFactory;
  import com.itextpdf.text.pdf.BaseFont;
  import com.itextpdf.text.pdf.PdfWriter;
  import com.itextpdf.tool.xml.XMLWorkerHelper;
  
  
  public class Test2 {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          try {
              FileInputStream in = new FileInputStream(new File(
                      "C:\\Test\\test_arabic.html"));
              String k = IOUtils.toString(in, Charset.forName("UTF-8"));
              OutputStream file = new FileOutputStream(new File("C:\\Test\\Test.pdf"));
              Document document = new Document();
              PdfWriter writer = PdfWriter.getInstance(document, file);
              InputStream htmlIn = new ByteArrayInputStream(k.getBytes());
              document.open();
              XMLWorkerHelper helper = XMLWorkerHelper.getInstance();
              FontFactory.getFontImp().registerDirectory("C:\\Windows\\Fonts");
              FontFactory.getFontImp().defaultEncoding = BaseFont.IDENTITY_H;
              helper.parseXHtml(writer, document, htmlIn, in, Charset.forName("UTF-8"),
                      FontFactory.getFontImp());
              document.close();
              file.close();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Here is my sample html file :</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
    &lt;meta name="language" content="ar-SA" /&gt;
    &lt;title&gt;My arabic html&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;font size="1"&gt;
  
  &lt;table width="700" style='font-family:Verdana; font-size:20px; color:blue'&gt;
    &lt;tr&gt;
      &lt;td align="left"&gt;ADVICE&lt;/td&gt;
      &lt;td dir="rtl" lang="ar-SA"&gt;&lt;p align='right' style='font-family:Traditional Arabic;'&gt; إشعار &lt;/p&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;table width="700" style='font-size:16px; color:white; background-color:gray'&gt;
    &lt;tr&gt;
      &lt;td align="left"&gt;Foreign Exchange&lt;/td&gt;
      &lt;td dir="rtl" lang="ar-SA"&gt;&lt;p align='right' style='font-family:Traditional Arabic;'&gt; تبادل العملات الأجنبية &lt;/p&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/font&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Does anyone know how to do that ? 
  I also tried converting my html into a Bytes array using w3c document and iTextRender, but no success.</p>
  
  <p><strong>Edit</strong> :  I now use the code provided by Vahidn (thanks a lot again)
  Little complement because I'm still struggling with the alignment now.
  It seems that the align="left" does not work with arabic and runDirection RTL.
  Here is my sample html :</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
        &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt;
        &lt;meta name="language" content="ar-SA" /&gt;
        &lt;title&gt;Confirmation Notice&lt;/title&gt;
     &lt;/head&gt;
     &lt;body&gt;
        &lt;font size="1"&gt;
           &lt;table width="700" style="font-family:Verdana; font-size:20px; color:white; background-color:blue"&gt;
              &lt;tr&gt;
                 &lt;td width="350" align="right"&gt;ADVICE&lt;/td&gt;
                 &lt;td width="350" align="left" dir="rtl" lang="ar-SA"&gt;
                    &lt;p style="font-family:traditional arabic;"&gt;
                       &lt;b&gt;إشعار&lt;/b&gt;
                    &lt;/p&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td width="350" align="right"&gt;Islamic Return Account&lt;/td&gt;
                 &lt;td width="350" dir="rtl" lang="ar-SA" align="left"&gt;
                    &lt;p style="font-family:traditional arabic;"&gt;
                       &lt;b&gt;حساب العائد الإسلامي&lt;/b&gt;
                    &lt;/p&gt;
                 &lt;/td&gt;
              &lt;/tr&gt;
           &lt;/table&gt;
      &lt;/font&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>But it never aligns on the left the arabic column. align center works though...
  Any idea ?</p>
  
  <p>Thanks a lot</p>
  
  <p>Thanks for your help</p>