List of usage examples for com.itextpdf.awt DefaultFontMapper DefaultFontMapper
DefaultFontMapper
From source file:userinterface.graph.Graph.java
License:Open Source License
/** * Exports the given chart to a pdf format file * @param file the file that has to be saved in pdf format * @param chart the chart that needs to be exported into pdf *///from w ww . j a v a 2 s .co m public static void exportToPDF(File file, JFreeChart chart) { PdfWriter out = null; com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4.rotate()); int width = 800, height = 500; try { out = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); PdfContentByte contentByte = out.getDirectContent(); PdfTemplate template = contentByte.createTemplate(width, height); @SuppressWarnings("deprecation") Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } catch (Exception e) { JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return; } document.close(); }
From source file:userinterface.graph.Graph3D.java
License:Open Source License
/** * Exports the 3d graph as a pdf/*from ww w . j a v a 2 s. c o m*/ * * @param file The pdf file to which the data should be written * @param panel The chart panel that has to be exported */ public static void exportToPDF(File file, Chart3DPanel panel) { PdfWriter out = null; Document document = new com.itextpdf.text.Document(PageSize.A4.rotate()); int width = 800, height = 500; try { out = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); PdfContentByte contentByte = out.getDirectContent(); PdfTemplate template = contentByte.createTemplate(width, height); @SuppressWarnings("deprecation") Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height); panel.getChart().draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } catch (Exception e) { // in case any error occurs tell the user what the error is (sometimes useful if there is a problem of writing rights) JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); return; } document.close(); }
From source file:WeeklyReport.Sections.Bookings.java
public Image bookingsByPODImage(PdfWriter writer) throws BadElementException { JFreeChart chart = new Bookings().bookingsByPODChart(); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(600f, 400f); Graphics2D graphics2d = template.createGraphics(600f, 400f, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Float(10f, 0, 500f, 400f); chart.draw(graphics2d, rectangle2d); graphics2d.dispose();//from w w w.j a va2 s . c om Image chartImage = Image.getInstance(template); return chartImage; }
From source file:WeeklyReport.Sections.Bookings.java
public Image bookingsByTradelaneImage(PdfWriter writer) throws BadElementException { JFreeChart chart = new Bookings().bookingsByTradelaneChart(); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(600f, 400f); Graphics2D graphics2d = template.createGraphics(600f, 400f, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Float(10f, 0, 500f, 400f); chart.draw(graphics2d, rectangle2d); graphics2d.dispose();/* w ww .ja va2 s . c o m*/ Image chartImage = Image.getInstance(template); return chartImage; }
From source file:WeeklyReport.Sections.Commodities.java
public Image commodityChartImage(PdfWriter writer) throws BadElementException { JFreeChart chart = commodityChart(); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(525f, 475f); Graphics2D graphics2d = template.createGraphics(525f, 475f, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Float(0, 0, 525f, 475f); chart.draw(graphics2d, rectangle2d); graphics2d.dispose();/*from www . j a v a2s. c o m*/ Image chartImage = Image.getInstance(template); return chartImage; }
From source file:WeeklyReport.Sections.Declines.java
public Image declinesByReasonImage(PdfWriter writer) throws BadElementException { JFreeChart chart = declinesByReasonChart(); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(600f, 400f); Graphics2D graphics2d = template.createGraphics(600f, 400f, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Float(10f, 0, 500f, 400f); chart.draw(graphics2d, rectangle2d); graphics2d.dispose();/*from w w w.ja va2 s .c om*/ Image chartImage = Image.getInstance(template); return chartImage; }
From source file:WeeklyReport.Sections.Declines.java
public Image declinesByCommodityImage(PdfWriter writer) throws BadElementException { JFreeChart chart = new Declines().declinesByCommodityClassChart(); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createAppearance(600f, 400f); Graphics2D graphics2d = template.createGraphics(600f, 400f, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Float(10f, 0, 500f, 400f); chart.draw(graphics2d, rectangle2d); graphics2d.dispose();/*from ww w .jav a 2 s .c o m*/ Image chartImage = Image.getInstance(template); return chartImage; }
From source file:WeeklyReport.WeeklyPDF.java
public static void writeChartToPDF(JFreeChart chart, int width, int height, String fileName) { PdfWriter writer = null;//from w w w .j ava 2 s . c om Document document = new Document(); try { writer = PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); document.add(new Paragraph("Here is the recommendation")); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(width, height); Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2d = new Rectangle2D.Double(5, -100, width, height); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } catch (FileNotFoundException | DocumentException ex) { ex.getMessage(); } document.close(); }