#12 problem to generate pdf with tomcat

open
nobody
None
5
2007-11-19
2007-11-19
pdeville
No

Since The class PDFGraphics instanciate JFrame in getFontMetrics method there is a problem to use gnujpdf on a web server.

On linux I got message:
X11 display not available

On windows it works a moment but After severals use of the lib I got :
Out of memory no more window handle.

Here is my suggestion for getFontMetrics :

Line 1435 :
public FontMetrics getFontMetrics(Font font) {
BufferedImage image = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
// Frame dummy = new Frame();
// dummy.addNotify();
// Image image = dummy.createImage(100, 100);
if (image == null) {
System.err.println("getFontMetrics: image is null");
}
Graphics graphics = image.getGraphics();
return graphics.getFontMetrics(font);

}

I tested this and it works well.

Discussion

  • pdeville
    pdeville
    2007-11-23

    Logged In: YES
    user_id=1940456
    Originator: YES

    The code takes more times to hangs (arround 50 request to return OutOfMemoryError)

    This last change works since 3 days without problem (1000 access per hour).

    /**
    * Returns the FontMetrics for a font.
    * <p>This doesn't work correctly. Perhaps having some way of mapping
    * the base 14 fonts to our own FontMetrics implementation?
    * @param font The java.awt.Font to return the metrics for
    * @return FontMetrics for a font
    */
    public FontMetrics getFontMetrics(Font font) {

    return Toolkit.getDefaultToolkit().getFontMetrics(font);

    }

    }

    File Added: PDFGraphics.java

     
  • pdeville
    pdeville
    2007-11-23

    Final version that works

     
    Attachments