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());
UIFont font = (UIFont) findITextParent(this, UIFont.class);
DefaultFontMapper fontMapper;
if (font == null) {
fontMapper = new DefaultFontMapper();
} else {
fontMapper = new AsianFontMapper(font.getName(), font.getEncoding());
}
Graphics2D g2 = tp.createGraphics(getWidth(), getHeight(), fontMapper);
chart.draw(g2, new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
g2.dispose();
image = new ImgTemplate(tp);
} else {