ugly font display when using the paint method for PDF writing --------------------------------------------------------------
Instead of using the Document.add(..) mechanism I'd like to write into a PDF file with the help of the paint() method. The paint method is called with a javax.swing.text.JTextComponent Object (called tComponent). Here is my code to write the PDF file: // Create a iText Document for writing com.lowagie.text.Document document = new com.lowagie.text.Document(); // Create a PdfWriter PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("my.pdf)); // Open the document document.open(); // To map the awt fonts with pdf fonts I need a mapper DefaultFontMapper fm = new DefaultFontMapper(); // Set the c:\windows\fonts path for example fm.insertDirectory(sun.awt.font.NativeFontWrapper.getFontPath(true)); int w = 500; int h = 764; int x = 50; int y = 1; PdfContentByte cb = writer.getDirectContent(); // Get a PdfTemplate PdfTemplate tp = cb.createTemplate(w, h); tp.setWidth(w); tp.setHeight(h); // Get a Graphics2D context Graphics2D g2 = cb.createGraphics(w, h, fm); // Paint the components into Graphics2D tComponent.paint(g2); // Finish the PDF-Document g2.dispose(); cb.addTemplate(tp,x,y); // Close the document document.close(); ... My JTextComponent contains text and objects of a class that has got its own paint method to display Strings: String text; ... public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setFont(font); Object antiAlias = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_AN TIALIAS_ON ); g2d.drawString(text,8,22); } And here is my problem: the text directly written from JTextComponent into the PDF file looks fine, but the Strings written from the second class looks ugly like a bitmap. Can someone help me? Alexander ------------------------------------------------------- This SF.net email is sponsored by: ValueWeb: Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions