> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of John Kostaras
> Sent: Friday, November 04, 2005 9:36 AM
> To: [email protected]
> Subject: [iText-questions] Greek fonts once more...
> 
> Hi,
> 
> sorry for posting an issue that seems to have been
> discussed quite a lot, but cannot tell which from the
> replies in the archives do work or not. You could also
> see the examples if you change to Greek(ISO) or
> Greek(Windows) encodings in your email client or
> browser.
> 
> Questions:
> 
> 1. Why CP1253 is not defined in
> com.lowagie.text.pdf.BaseFont class in the standard
> releases of iText so someone needs to add the
> following line:
> 
> /** A possible encoding. */    
> public static final String CP1253 = "Cp1253";
> 
> to this file and ant-build iText in order to be able
> to use Greek fonts? :-)
> 

It's just a String. We can't have all encings as constants.

> 2. What is the correct way to print Greek characters?
> 
> DefaultFontMapper mapper = new DefaultFontMapper();
> FontFactory.registerDirectories();
> mapper.insertDirectory("c:\\windows\\fonts"); 
> document.add(new Paragraph("ÃåéÜ óïõ êüóìå!"));
>

Won't work. The default font is Helvetica and there's no Greek chars there.
 
> or
> 
> BaseFont bfArial =
> BaseFont.createFont("c:\\winnt\\fonts\\arial.ttf",
> BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
> Font font = new Font(bfArial, 18);
> document.add(new Paragraph("ÃåéÜ óïõ êüóìå!"));
> 

Almost work. You define the font but don't use it?

> Which is the correct for itext version 1.3 and on?
> 
> But, with either of these methods, Greek letters with
> accents never appear, e.g. Ü, ü etc. are not rendered
> in the pdf.
>

Of course not, see above.
 
> 3. Greek letters are not rendered if printed through
> Graphics or Graphics2D:
> 
> DefaultFontMapper mapper = new DefaultFontMapper();
> FontFactory.registerDirectories();
> mapper.insertDirectory("c:\\windows\\fonts");

You need here:

DefaultFontMapper.BaseFontParameters pp = mapper.getBaseFontParameters("Arial");
if (pp!=null) {
    pp.encoding = BaseFont.IDENTITY_H;
}

> PdfContentByte cb = writer.getDirectContent();
> PdfTemplate tp = cb.createTemplate(w, h);
> Graphics g = tp.createGraphics(w, h, mapper);
> tp.setWidth(w);
> tp.setHeight(h);
> 
> java.awt.Font thisFont = new java.awt.Font("Arial",
> java.awt.Font.PLAIN, 18);
> g.setFont(thisFont);
> String pear = "Á÷ëÜäé!";
> FontMetrics metrics = g.getFontMetrics();
> int width = metrics.stringWidth(pear);
> g.drawString(pear, (w - width) / 2, 20);
> g.dispose();
> cb.addTemplate(tp, 0, 0);
> 
> Please note that I 'm using Arial which does contain
> Greek characters.
> 
> Thanks in advance for your replies.
> 
> Best regards,
> 
> John.


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to