List of usage examples for com.lowagie.text.pdf DefaultFontMapper DefaultFontMapper
DefaultFontMapper
From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java
License:Open Source License
public void plot() throws Exception { JFreeChart chart = createChart(wrappers); File fileName = new File(Options.getOutputFolder(), this.fileName + ".pdf"); File svgFile = new File(Options.getOutputFolder(), this.fileName + ".svg"); PlotUtil.saveChartAsPDF(fileName, chart, width, height, new DefaultFontMapper()); PlotUtil.saveChartAsSVG(svgFile, chart, width, height); }
From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomTimePlot.java
License:Open Source License
@Override public void plot() throws Exception { JFreeChart chart = createChart(wrappers); File fileName = new File(Options.getOutputFolder(), this.fileName + ".pdf"); File svgFile = new File(Options.getOutputFolder(), this.fileName + ".svg"); PlotUtil.saveChartAsPDF(fileName, chart, width, height, new DefaultFontMapper()); PlotUtil.saveChartAsSVG(svgFile, chart, width, height); }
From source file:de.dfki.owlsmx.gui.util.Converter.java
License:Open Source License
public static void convertToPdf(JFreeChart chart, int width, int height, String filename) { // step 1 Document document = new Document(new Rectangle(width, height)); try {//from ww w . ja va 2 s. co m // step 2 PdfWriter writer; writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 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); } catch (DocumentException de) { } catch (FileNotFoundException e) { } // step 5 document.close(); }
From source file:de.xirp.chart.ChartUtil.java
License:Open Source License
/** * Exports the given chart as PDF in the specified size. The * export is written to the given path./*from w w w . jav a 2 s . c om*/ * * @param chart * The chart to export. * @param width * The desired width of the PDF. * @param height * The desired height of the PDF. * @param path * The path to write the PDF to. * @see org.jfree.chart.JFreeChart */ private static void exportPDF(JFreeChart chart, int width, int height, String path) { Document document = new Document(new Rectangle(width, height)); try { PdfWriter writer; writer = PdfWriter.getInstance(document, new FileOutputStream(path)); 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); } catch (Exception e) { logClass.error("Error: " + e.getMessage() //$NON-NLS-1$ + Constants.LINE_SEPARATOR, e); } document.close(); }
From source file:dr.app.tracer.analysis.TemporalAnalysisFrame.java
License:Open Source License
public final void doExportPDF() { FileDialog dialog = new FileDialog(this, "Export PDF Image...", FileDialog.SAVE); dialog.setVisible(true);//from w ww .j a va 2 s . c o m if (dialog.getFile() != null) { File file = new File(dialog.getDirectory(), dialog.getFile()); Rectangle2D bounds = temporalAnalysisPlotPanel.getExportableComponent().getBounds(); Document document = new Document( new com.lowagie.text.Rectangle((float) bounds.getWidth(), (float) bounds.getHeight())); try { // step 2 PdfWriter writer; writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate((float) bounds.getWidth(), (float) bounds.getHeight()); Graphics2D g2d = tp.createGraphics((float) bounds.getWidth(), (float) bounds.getHeight(), new DefaultFontMapper()); temporalAnalysisPlotPanel.getExportableComponent().print(g2d); g2d.dispose(); cb.addTemplate(tp, 0, 0); } catch (DocumentException de) { JOptionPane.showMessageDialog(this, "Error writing PDF file: " + de, "Export PDF Error", JOptionPane.ERROR_MESSAGE); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "Error writing PDF file: " + e, "Export PDF Error", JOptionPane.ERROR_MESSAGE); } document.close(); } }
From source file:dr.app.tracer.application.TracerFrame.java
License:Open Source License
public final void doExportPDF() { FileDialog dialog = new FileDialog(this, "Export PDF Image...", FileDialog.SAVE); dialog.setVisible(true);//from ww w .j a v a 2 s . c o m if (dialog.getFile() != null) { File file = new File(dialog.getDirectory(), dialog.getFile()); Rectangle2D bounds = tracePanel.getExportableComponent().getBounds(); Document document = new Document( new com.lowagie.text.Rectangle((float) bounds.getWidth(), (float) bounds.getHeight())); try { // step 2 PdfWriter writer; writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate((float) bounds.getWidth(), (float) bounds.getHeight()); Graphics2D g2d = tp.createGraphics((float) bounds.getWidth(), (float) bounds.getHeight(), new DefaultFontMapper()); tracePanel.getExportableComponent().print(g2d); g2d.dispose(); cb.addTemplate(tp, 0, 0); } catch (DocumentException de) { JOptionPane.showMessageDialog(this, "Error writing PDF file: " + de, "Export PDF Error", JOptionPane.ERROR_MESSAGE); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "Error writing PDF file: " + e, "Export PDF Error", JOptionPane.ERROR_MESSAGE); } document.close(); } }
From source file:ec.display.chart.StatisticsChartPaneTab.java
License:Academic Free License
/** * This method initializes jButton //from w w w . j a v a2 s.com * * @return javax.swing.JButton */ private JButton getPrintButton() { if (printButton == null) { printButton = new JButton(); printButton.setText("Export to PDF..."); final JFreeChart chart = chartPane.getChart(); printButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try { int width = chartPane.getWidth(); int height = chartPane.getHeight(); FileDialog fileDialog = new FileDialog(new Frame(), "Export...", FileDialog.SAVE); fileDialog.setDirectory(System.getProperty("user.dir")); fileDialog.setFile("*.pdf"); fileDialog.setVisible(true); String fileName = fileDialog.getFile(); if (fileName != null) { if (!fileName.endsWith(".pdf")) { fileName = fileName + ".pdf"; } File f = new File(fileDialog.getDirectory(), fileName); Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f)); document.addAuthor("ECJ Console"); 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 ex) { ex.printStackTrace(); } } }); } return printButton; }
From source file:edu.gmu.cs.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 {/*from w w w . j a v a2s. co 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:edu.gmu.cs.sim.util.media.PDFEncoder.java
License:Academic Free License
public static void generatePDF(JFreeChart chart, int width, int height, File file) { try {/*w w w .j a 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); 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:edu.ucsf.rbvi.clusterMaker2.internal.treeview.dendroview.GraphicsExportPanel.java
License:Open Source License
private void pdfSave(String format) { com.lowagie.text.Rectangle pageSize = PageSize.LETTER; Document document = new Document(pageSize); try {/*from w w w.j a v a 2 s . c o m*/ OutputStream output = new BufferedOutputStream(new FileOutputStream(getFile())); PdfWriter writer = PdfWriter.getInstance(document, output); document.open(); PdfContentByte cb = writer.getDirectContent(); Graphics2D g = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight(), new DefaultFontMapper()); double imageScale = Math.min(pageSize.getWidth() / ((double) estimateWidth() + getBorderPixels()), pageSize.getHeight() / ((double) estimateHeight() + getBorderPixels())); g.scale(imageScale, imageScale); drawAll(g, 1.0); g.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(this, new JTextArea("Dendrogram export had problem " + e)); // logger.error("Exception " + e); // e.printStackTrace(); } document.close(); }