I am trying to add a Line Chart to Pdf file in android using itext and AFreeChart. I have done this in java using itextpdf and JFreeChart. But i am stuck at the part where graph is added to pdf. Please help.
I don't know how to bind the canvas to PdfTemplate, or is there a different way of doing this, any suggestions are appreciated.
This is my android code
AFreeChart chart = ChartFactory.createLineChart("R","Unit1","unit2",dataset,
PlotOrientation.HORIZONTAL,true,false,false);
PdfContentByte cb = pdfWriter.getDirectContent();
PdfTemplate tp = cb.createTemplate(100,200);
Canvas canvas = new Canvas();
RectShape rectShape = new RectShape(0,0,100,200);
chart.draw(canvas,rectShape);
cb.addTemplate(tp,280,35);
This is my Java code
PdfContentByte cb = pdfWriter.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
chart.draw(g2d, r2d);
The graph is not being plotted in the pdf at all.