Hello,

i'm still having difficulties with the font mapping. I extended the DefaultFontMapper:

.
.
.

DefFontMapper mapper = new DefFontMapper();
mapper.insertDirectory("c:/windows/fonts");
Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);

.
.
.


private class DefFontMapper extends DefaultFontMapper{
                
                        public BaseFont awtToPdf(java.awt.Font font){
                        //Method 1
Font f = new Font(Font.getFamilyIndex(font.getFamily()),font.getSize(),font.getStyle());
                        
                        //Method 2
                        /* Font f = new Font();
                        f.setStyle(Font.BOLD); */

                        if (f.getBaseFont() == null){
                                System.out.println("x " + f);
                                return super.awtToPdf(font);
                        }
                        return f.getBaseFont();
                        
                 }
                
but f.getBaseFont() always returns null.
Did I forget something, or is this a complete wrong way to handle the font mapping?


Thanks in advance
Bruno

bruno schrieb:
Bruno Polder wrote:

Hello Bruno,

i could give it a try, but i'm not very familiar with Graphics in Java. Do you know where i can find some examples?

It's very simple. See http://article.gmane.org/gmane.comp.java.lib.itext.general/20679
If you want the short version:
http://itextdocs.lowagie.com/tutorial/directcontent/graphics2D/
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(w, h);
Graphics2D g2 = tp.createGraphics(w, h, new DefaultFontMapper());
myTextPane.paint(g2);
g2.dispose();

The difficult parts concern the font mapping
and the fact that you must not forget to invoke dispose();

See also this example:
http://itextdocs.lowagie.com/examples/com/lowagie/examples/objects/tables/alternatives/JTable2Pdf.java
br,
Bruno


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to