views:

357

answers:

1

We have embedded JasperReports into our application to generate reports, but I've been rather dissatisfied with the way that the JEditorPaneHtmlMarkupProcessor handles writing arbitrary XHTML. For example, I needed to output a bulleted list at one point, which it does, but because it converts it to actual bullet characters and newlines, a bullet with fairly long text results in the text wrapping to align with the bullet, not with the first letter of the text.

Because of this and similar problems, I thought I might try rendering XHTML content as a graphic (using the flyingsaucer XHTML renderer). This gives me much better control over how it looks, but there's still one problem. According to The Definitive Guide to JasperReports, "All positioning and sizing in JasperReports templates and generated documents is performed using the default Java resolution of 72 dpi." It appears that the individual letters to be rendered are required to be positioned at integral coordinates. At 72 dpi, this is no big deal, since it amounts to sub-pixel positioning errors at worst, not of any significant consequence. However, when rendering to PDF, JasperReports blows it up to 300 dpi, resulting in the horizontal positions of some letters being off by multiple pixels at times.

Is there some way to get better rendering of arbitrary XHTML, or is there some way to make JasperReports perform its positioning and sizing at 300 dpi instead of 72?

A: 

I ultimately solved this by using a renderer which did not insist on integral character positions: the JEditorPane from Swing:

JEditorPane pane = new JEditorPane();
pane.setBorder(null);
pane.setSize(w, h);
pane.setContentType("text/html");
pane.setEditable(false);
pane.setText(html);
pane.paint(g2);
Robert J. Walker