title: Using Java PDFBox library to write Russian PDF
body: <p>I am using a Java library called <strong>PDFBox</strong> trying to write text to a PDF. It works perfect for English text, but when i tried to write Russian text inside the PDF the letters appeared so strange. It seems the problem is in the font used, but i am not so sure about that, so i hope if anyone could guide me through this. Here is the important code lines :</p>
  
  <pre><code>PDTrueTypeFont font = PDTrueTypeFont.loadTTF( pdfFile, new File( "fonts/VREMACCI.TTF" ) );  // Windows Russian font imported to write the Russian text.
  font.setEncoding( new WinAnsiEncoding() );  // Define the Encoding used in writing.
  // Some code here to open the PDF &amp; define a new page.
  contentStream.drawString( "отделом компьютерной" ); // Write the Russian text.
  </code></pre>
  
  <p>The WinAnsiEncoding source code is : <a href="http://www.java2s.com/Open-Source/Java-Document/PDF/PDFBox-0.7.3/org/pdfbox/encoding/WinAnsiEncoding.java.htm" rel="nofollow noreferrer">Click here</a></p>
  
  <p><strong>--------------------- Edit on 18 November 2009</strong></p>
  
  <p>After some investigation, i am now sure it is an Encoding problem, this could be solved by defining my own Encoding using the helpful PDFBox class called <em>DictionaryEncoding</em>.</p>
  
  <p>I am not sure how to use it, but here is what i have tried until now :</p>
  
  <pre><code>COSDictionary cosDic = new COSDictionary();
  cosDic.setString( COSName.getPDFName("Ercyrillic"), "0420 " ); // Russian letter.
  font.setEncoding( new DictionaryEncoding( cosDic ) );
  </code></pre>
  
  <p>This does not work, as it seems i am filling the dictionary in a wrong way, when i write a PDF page using this it appears blank.</p>
  
  <p>The DictionaryEncoding source code is : <a href="http://www.java2s.com/Open-Source/Java-Document/PDF/PDFBox-0.7.3/org/pdfbox/encoding/DictionaryEncoding.java.htm" rel="nofollow noreferrer">Click here</a></p>