UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class);
if (doc != null) {
PdfWriter writer = (PdfWriter) doc.getWriter();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(getWidth(), getHeight());
Graphics2D g2 = tp.createGraphics(getWidth(), getHeight(), new DefaultFontMapper());
chart.draw(g2, new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
g2.dispose();
image = new ImgTemplate(tp);
} else {