I'm trying to use xhtmlprinter (flying saucer) to print the html part of a email. It almost works but on the page the imageable area of the paper is not used so the contents are clipped.
Im using this code, which is modeled after the XHTMLPrintable in the simple package, to print the page.
Graphics2D g2 = (Graphics2D) g;
if (g2r == null) {
g2r = new Graphics2DRenderer();
g2r.getSharedContext().setPrint(true);
g2r.getSharedContext().setInteractive(false);
g2r.getSharedContext().setDPI(72f);
g2r.getSharedContext().getTextRenderer().setSmoothingThreshold(0);
g2r.getSharedContext().getTextRenderer().setSmoothingLevel(TextRenderer.HIGH);
g2r.setDocument(doc, "");
g2r.getSharedContext().setReplacedElementFactory(new XHTMLReplacedElementFactory());
g2r.layout(g2, null);
g2r.getPanel().assignPagePrintPositions(g2);
}
/**
* Hack to fix border on the left side. TODO: Check right side
*/
g2.translate(pf.getImageableX(), pf.getImageableY());
if (page >= g2r.getPanel().getRootLayer().getPages().size()) {
return Printable.NO_SUCH_PAGE;
}
g2r.getPanel().paintPage(g2, page);
The doc is my parsed Document. The XHTMLReplacementElementFactory is a simple implementation of the interface that does nothing. I already got the left and top borders working by using the g2.translate.
Two questions: Why doesn't xhtmlrenderer use the imageable area of the Graphics2D? How can I set the width so that there is no clipping?