List of usage examples for com.itextpdf.text.pdf PdfContentByte createTemplate
public PdfTemplate createTemplate(final float width, final float height)
From source file:sim.util.media.PDFEncoder.java
License:Academic Free License
public static void generatePDF(Component component, File file) { int width = component.getWidth(); int height = component.getHeight(); try {// w ww.ja va2 s . c o m Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics g2 = tp.createGraphics(width, height, new DefaultFontMapper()); component.paint(g2); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:sim.util.media.PDFEncoder.java
License:Academic Free License
public static void generatePDF(JFreeChart chart, int width, int height, File file) { try {/*from w w w . j av a2s. c o m*/ Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, rectangle2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:sistemacontrole.MainWindow.java
public void MainClass() throws Exception { Document document = new Document(); PdfWriter writer;/* w w w.j a va 2 s . c om*/ writer = PdfWriter.getInstance(document, new FileOutputStream("my_jtable_shapes.pdf")); // writer = PdfWriter.getInstance(document, new // FileOutputStream("my_jtable_fonts.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(500, 500); Graphics2D g2; g2 = tp.createGraphicsShapes(500, 500); // g2 = tp.createGraphics(500, 500); this.tabelaDetalhes.print(g2); g2.dispose(); cb.addTemplate(tp, 30, 300); // step 5: we close the document document.close(); }
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 w w .ja v a2s.c om 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 www.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 ww w . j a v a 2 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();// www . j ava 2 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 w ww . j a v a 2 s . c om*/ 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 www . j a va2 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 www . j ava 2 s. c o m 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(); }