use of com.itextpdf.text.pdf.DefaultFontMapper in project Java-Matrix-Benchmark by lessthanoptimal.
the class UtilPlotPdf method saveAsPdf.
public static void saveAsPdf(JFreeChart chart, String FILENAME, int width, int height) {
File parent = new File(new File(FILENAME).getParent());
if (!parent.exists()) {
if (!parent.mkdirs())
throw new RuntimeException("Can't make directory path");
}
Document document = new Document(new Rectangle(width, height));
try {
FileOutputStream file = new FileOutputStream(FILENAME);
PdfWriter writer = PdfWriter.getInstance(document, file);
document.open();
PdfContentByte cb = writer.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);
g2d.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
g2d.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.itextpdf.text.pdf.DefaultFontMapper in project Java-Matrix-Benchmark by lessthanoptimal.
the class UtilPlotPdf method saveAsPdf.
public static void saveAsPdf(LegendTitle legend, String FILENAME, int width, int height) {
Document document = new Document(new Rectangle(width, height));
try {
FileOutputStream file = new FileOutputStream(FILENAME);
PdfWriter writer = PdfWriter.getInstance(document, file);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
legend.draw(g2d, r2d);
g2d.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
g2d.dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations