PDA

View Full Version : how to display long text



Anonymous
04-01-2002, 05:39 PM
I am trying to generate a report in which one of the fields can contain arbitrarily long text (anywhere from blank to several sentences). Is there a way to get the text to line wrap within that column (similar to an html table cell), pushing the next line item down? Right now I am using a string-field to display the column, but no matter what I set the width too, long text just runs over the next column or columns. Any ideas?

Anonymous
04-02-2002, 02:41 PM
So I have spent some more time investigating this and it looks like the MutlilineTextElement was originally created to handle this issue, but its interface is bit deprecated. It is still relying on:

public void draw(Graphics2D g2, float x, float y);

which never gets called. I am assuming this is the old draw method signature. Now it needs to override:

public void draw(OutputTarget target, Band band, float bandX, float bandY);

The problem is tricky because now you have lost the Graphics2D, so you no longer have a surefire way to get the FontMetrics (and hence the line width to break the lines). (The PDFWriter appears to have no Graphics object, so this is probably where this api change came in). I supposed you could fall back on Toolkit.getFontMetrics or Font.getLineMetrics, but its not going to be perfect.

If the problem is indeed the lack of a Graphics object in the itext package, I did a little research and found this project on sourceforge:

http://gnujpdf.sourceforge.net/

The intro states:

"What GNUjpdf offers is a familiar API: java.awt.Graphics. All operations that draw to a PDF file in this package do so through a subclass of Graphics, so that one set of methods that operate on the abstract Graphics class can process AWT graphics. Your document can be viewed in an applet or swing application, then printed using PrintJob.getGraphics(), and then converted to PDF using PDFJob.getGraphics()."

I haven't used this package, so I'm not sure how great it is, but it may be worth cheching into.

--jim

Anonymous
04-02-2002, 03:12 PM
Hi Jim,

The MultilineTextElement is supposed to work, but I still need to do some work on it. The class was contributed by Thomas Morgner, along with a lot of other great stuff, and as I was integrating things I made changes, broke the MultilineTextElement and never actually fixed it before releasing 0.7.0. It will be fixed.

I'll check out the link you suggest - it would be great if JFreeReport could generate PDF via a Graphics2D object, as that would be very little work at this end. At the same time, iText is a really good library, so maybe writing the bridging code is worth it.

Regards,

DG.

Anonymous
04-03-2002, 06:11 PM
>it would be great if JFreeReport could generate PDF via a Graphics2D
>object, as that would be very little work at this end. At the same time,
>iText is a really good library, so maybe writing the bridging code is worth it.


So I picked up the gauntlet. I emailed you the beginning of an implementation of Graphics2D for the iText library.

Anonymous
04-04-2002, 03:44 AM
Hi Jim,

Thanks...I think your code looks promising.

Regards,

DG.