Hello again, Fair enough that there is no Cyrillic characters in the normal fonts. But I am sure I am not alone in wanting to generate pdfs with Cyrillic characters. So what is a good approach to doing so? Any suggestions? I am not very keen on distributing fonts for legal reasons. My whole application is localized to Russian and shows Cyrillic characters without any problem. So the question is, could I ask Swing/AWT for the font and use that font? Or is there a better way to get around this?
any help is greatly appreciated! regards Daniel >The first example won't work because the built in fonts don't have any >Cyrillic characters. The second example is the correct way to do it but >you should also embedd the font if you want the PDF to work everywhere. >About the path to the font it's a programming/configuration problem that >you have to solve and that has nothing to do with iText. Note that you >can also put fonts inside jars. > >Paulo > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On > > Behalf Of Daniel > > Sent: Friday, September 21, 2007 12:12 PM > > To: itext-questions@lists.sourceforge.net > > Subject: [iText-questions] Font problems > > > > 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,Colo > > r.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,Colo > > r.BLACK); > > > > Paragraph header2 = new Paragraph( > > russiantext, fnt); > > > > header.setAlignment(Element.ALIGN_CENTER); > > doc.add(header2); > > > > doc.close(); > > }catch(Exception e){ > > e.printStackTrace(); > > } > > } > > } > > >Aviso Legal: > >Esta mensagem é destinada exclusivamente ao destinatário. Pode conter >informação confidencial ou legalmente protegida. A incorrecta transmissão >desta mensagem não significa a perca de confidencialidade. Se esta >mensagem for recebida por engano, por favor envie-a de volta para o >remetente e apague-a do seu sistema de imediato. É proibido a qualquer >pessoa que não o destinatário de usar, revelar ou distribuir qualquer >parte desta mensagem. > > > >Disclaimer: > >This message is destined exclusively to the intended receiver. It may >contain confidential or legally protected information. The incorrect >transmission of this message does not mean the loss of its >confidentiality. If this message is received by mistake, please send it >back to the sender and delete it from your system immediately. It is >forbidden to any person who is not the intended receiver to use, >distribute or copy any part of this message. > > > >------------------------------------------------------------------------- >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/ ------------------------------------------------------------------------- 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/