Hello all, I am using iText (currently using version 1.3 but I have tried 2.0.4 and it did not solve the problem) to generate pdfs from my program. Now my user base want to be able to generate pdfs in Russian with the Cyrillic alphabet. The problem I have is that when I set the encoding to "Cp1251" iText seems to "stack" the characters on top of each other, making it of course not readable. In other words it seems to render the characters in one place. A sentence about one page in width ends up being about one third of a page in length.
I'll paste some code, complete code at the end of the post String russiantext; //a string literal with unicode escapes for the russian chars. //example one, does not work Paragraph header = new Paragraph( russiantext, FontFactory.getFont(FontFactory.TIMES,"Cp1251" ,20, com.lowagie.text.Font.BOLD, ,Color.BLACK)); header.setAlignment(Element.ALIGN_CENTER); doc.add(header); //example two works. BaseFont bsfnt = BaseFont.createFont("c:\\WINNT\\fonts\\times.ttf","Cp1251",false); com.lowagie.text.Font fnt= new com.lowagie.text.Font(bsfnt,20,com.lowagie.text.Font.BOLD,Color.BLACK); Paragraph header2 = new Paragraph( russiantext, fnt); header.setAlignment(Element.ALIGN_CENTER); doc.add(header2); The first exmaple stacks the characters on top of each other. The second one works. but as you can see it uses an absolute path to the font, and therefore it will work on my machine, but not on other machines with just a slightly different setup. Any suggestions on how to solve this would be excellent! I am at loss, I have tried google, but either there is no solution, or I am not using good keywords, so if you google and find a good page, please either link the page or give me the keywords! thanks in advance regards Daniel Compilable code that highlights the problem: import com.lowagie.text.*; import com.lowagie.text.Document; import com.lowagie.text.Element; import com.lowagie.text.pdf.*; import java.io.*; import java.awt.*; public class TestRussian{ public static void main(String[] args){ main(); } public static void main() { try{ String russiantext="\u041D\u0435 \u043F\u043E\u043A\u0430\u0437\u044B\u0432\u0430\u0442\u044C \u044D\u0442\u043E \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u0435 \u0441\u043D\u043E\u0432\u0430"; Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc,new FileOutputStream("test.pdf")); doc.open(); //example one, does not work Paragraph header = new Paragraph( russiantext,FontFactory.getFont(FontFactory.TIMES,"Cp1251" ,20, com.lowagie.text.Font.BOLD, new Color(0, 0, 0))); header.setAlignment(Element.ALIGN_CENTER); doc.add(header); //example two works. BaseFont bsfnt = BaseFont.createFont("c:\\WINNT\\fonts\\times.ttf","Cp1251",false); com.lowagie.text.Font fnt= new com.lowagie.text.Font(bsfnt,20,com.lowagie.text.Font.BOLD,Color.BLACK); Paragraph header2 = new Paragraph( russiantext, fnt); header.setAlignment(Element.ALIGN_CENTER); doc.add(header2); doc.close(); }catch(Exception e){ e.printStackTrace(); } } } ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/