I have 2 JFree Charts and I would like to put one on each page of PDF.
How could I edit this code?
public void createPdf(String filename) throws IOException, DocumentException, SQLException {
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
// step 3
document.open();
// step 4
PdfContentByte cb = writer.getDirectContent();
float width = PageSize.A4.getWidth();
float height = PageSize.A4.getHeight() / 2;
// Pie chart
PdfTemplate pie = cb.createTemplate(width, height);
Graphics2D g2d1 = new PdfGraphics2D(pie, width, height);
Rectangle2D r2d1 = new Rectangle2D.Double(0, 0, width, height);
getPieChart().draw(g2d1, r2d1);
g2d1.dispose();
cb.addTemplate(pie, 0, height);
// Bar chart
PdfTemplate bar = cb.createTemplate(width, height);
Graphics2D g2d2 = new PdfGraphics2D(bar, width, height);
Rectangle2D r2d2 = new Rectangle2D.Double(0, 0, width, height);
getBarChart().draw(g2d2, r2d2);
g2d2.dispose();
cb.addTemplate(bar, 0, 0);
// step 5
document.close();
}
Thanks everyone.