Example usage for com.itextpdf.text.pdf PdfContentByte createGraphicsShapes

List of usage examples for com.itextpdf.text.pdf PdfContentByte createGraphicsShapes

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte createGraphicsShapes.

Prototype

public java.awt.Graphics2D createGraphicsShapes(final float width, final float height) 

Source Link

Document

Gets a Graphics2D to write on.

Usage

From source file:mymoney.Multi_cal.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
    getContentPane().setLayout(new BorderLayout());
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    JFileChooser cho = new JFileChooser();
    cho.showSaveDialog(null);//from w  ww . j a va  2s.  c o  m
    File f = cho.getSelectedFile();
    String filename = f.getAbsolutePath();
    com.itextpdf.text.Document document = new com.itextpdf.text.Document();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        PdfTemplate pdfTemplate = cb.createTemplate(jTable1.getWidth(), jTable1.getHeight());

        Graphics2D g2 = cb.createGraphicsShapes(800, 500);
        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 800, 500);
        jTable1.print(g2);
        g2.setClip(oldClip);
        g2.dispose();
        cb.restoreState();
        JOptionPane.showMessageDialog(null, "Data Exported to pdf");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error");
    }
    document.close();

    // TODO add your handling code here:
}

From source file:mymoney.view.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    getContentPane().setLayout(new BorderLayout());
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    JFileChooser cho = new JFileChooser();
    cho.showSaveDialog(null);/* ww  w.  ja va2  s . co m*/
    File f = cho.getSelectedFile();
    String filename = f.getAbsolutePath();
    com.itextpdf.text.Document document = new com.itextpdf.text.Document();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        PdfTemplate pdfTemplate = cb.createTemplate(jTable1.getWidth(), jTable1.getHeight());

        Graphics2D g2 = cb.createGraphicsShapes(800, 500);
        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 800, 500);
        jTable1.print(g2);
        g2.setClip(oldClip);
        g2.dispose();
        cb.restoreState();
        JOptionPane.showMessageDialog(null, "Data Exported to pdf");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error");
    }
    document.close();

    // TODO add your handling code here:
}

From source file:mymoney.view.java

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
    getContentPane().setLayout(new BorderLayout());
    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
    JFileChooser cho = new JFileChooser();
    cho.showSaveDialog(null);//from www . ja  v  a2s. c om
    File f = cho.getSelectedFile();
    String filename = f.getAbsolutePath();
    com.itextpdf.text.Document document = new com.itextpdf.text.Document();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        PdfTemplate pdfTemplate = cb.createTemplate(jTable2.getWidth(), jTable2.getHeight());

        Graphics2D g2 = cb.createGraphicsShapes(800, 500);
        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 800, 500);
        jTable2.print(g2);
        g2.setClip(oldClip);
        g2.dispose();
        cb.restoreState();
        JOptionPane.showMessageDialog(null, "Data Exported to pdf");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error");
    }
    document.close(); // TODO add your handling code here:
}