My apologies if this is a well-known issue already.  But I am using Mac OSX and
just discovered it.

I got this error when trying to paint a component using the PdfGraphics2D.

apple.awt.EventQueueExceptionHandler Caught Throwable :
java.lang.IllegalArgumentException:
        null incompatible with Text-specific antialiasing enable key
java.lang.IllegalArgumentException:
        null incompatible with Text-specific antialiasing enable key
        at java.awt.RenderingHints.put(RenderingHints.java:482)
        at com.lowagie.text.pdf.PdfGraphics2D.setRenderingHint(Unknown Source)
        at apple.laf.AquaUtils.endFont(AquaUtils.java:40)
        at apple.laf.AquaLabelUI.paint(AquaLabelUI.java:32)
        at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
        at javax.swing.JComponent.paintComponent(JComponent.java:541)
        at javax.swing.JComponent.paint(JComponent.java:808)
        at javax.swing.JComponent.paintChildren(JComponent.java:647)
        at javax.swing.JComponent.paint(JComponent.java:817)
        at jeffadams.qsheet.gui.OutputUtil.writeToPDF(OutputUtil.java:49)

  Here's the code:

   public static void writeToPDF(String fileName, JComponent comp) {
        // step 1: creation of a document-object
        Document document = new Document();
        comp.setVisible(true);
        try {
            
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document,
                    new FileOutputStream(fileName));
            
            // step 3: we open the document
            document.open();
            
            // step 4: we grab the ContentByte and do some stuff with it
            
            // we create a template and a Graphics2D object that corresponds 
with it
            int w = 150;
            int h = 150;
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(w, h);
            Graphics2D g2 = tp.createGraphics(w, h);
            tp.setWidth(w);
            tp.setHeight(h);

            comp.paint(g2);

            g2.dispose();
            cb.addTemplate(tp, 50, 400);
            
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
        // step 5: we close the document
        document.close();
    }

As you can see it's mostly just a copy of the example, only I replaced the
manual drawing of a pear with a call to component.paint().

So, I downloaded the source code and "fixed" the problem.  I saw a message
somewhere (here: http://www.junlu.com/msg/70735.html ) that said that this was 
due
to an underlying problem in OSX (or OSX's java implementation).  Since that
doesn't seem like the kind of thing that I can plan on having fixed any
time soon, I modified the itext code to eat the exception.


First I had to fix "compile.xml" to change the reference to
"../META-INF/MANIFEST.MF" to instead reference
"${itext.src}/META-INF/MANIFEST.MF".

Other than that, I just ran:
ant download
ant compile
ant jar

Somehow all the working dirs were pointing to ".." from where I was
executing ant (so it made ../src, ../build).  Not really a problem,
but an oddity.

I wrapped "setRenderingHint" and "setRenderingHints" in PdfGraphics2D.java
with try/catch blocks that caught IllegalArgumentException and ignored it.

Hope this is valuable to someone.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to