Example usage for com.itextpdf.text Document open

List of usage examples for com.itextpdf.text Document open

Introduction

In this page you can find the example usage for com.itextpdf.text Document open.

Prototype

boolean open

To view the source code for com.itextpdf.text Document open.

Click Source Link

Document

Is the document open or not?

Usage

From source file:Report1.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:

    try {/* ww  w  . j  a  v a 2  s .  c  o  m*/
        Document doc = new Document() {
        };
        PdfWriter.getInstance(doc, new FileOutputStream("table.pdf"));
        doc.open();
        PdfPTable pdfTable = new PdfPTable(jTable1.getColumnCount());
        //adding table headers
        for (int i = 0; i < jTable1.getColumnCount(); i++) {
            pdfTable.addCell(jTable1.getColumnName(i));
        }
        //extracting data from the JTable and inserting it to PdfPTable
        for (int rows = 0; rows < jTable1.getRowCount() - 1; rows++) {
            for (int cols = 0; cols < jTable1.getColumnCount(); cols++) {
                pdfTable.addCell(jTable1.getModel().getValueAt(rows, cols).toString());

            }
        }
        doc.add(pdfTable);
        doc.close();
        JOptionPane.showMessageDialog(am,
                "Report have been saved in PDF                                                ``````````````````````````````````````````````````````");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(rootPane, ex);
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(rootPane, "File Not Found");
    }

}

From source file:FurnitureArchiveFrame.java

private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed
    Document document = new Document();
    try {/*from   w  w w.  jav a2  s. co  m*/
        PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\FurnitureArchive.pdf"));
        document.open();

        PdfPTable tab = new PdfPTable(model.getColumnCount());
        for (int i = 0; i < model.getColumnCount(); i++) {
            tab.addCell(model.getColumnName(i));
        }
        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                if (model.getValueAt(i, j) != null) {
                    tab.addCell(model.getValueAt(i, j).toString());
                } else {
                    tab.addCell("-");
                }
            }
        }
        document.add(tab);

        JOptionPane.showMessageDialog(null,
                "Data saved at " + path + "'\\PDF\\FurnitureArchive.pdf' successfully", "Message",
                JOptionPane.INFORMATION_MESSAGE);
        document.close();

    } catch (FileNotFoundException | DocumentException ex) {
        //            Logger.getLogger(TimeInOutArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:TimeInOutArchiveFrame.java

private void tabletoPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDFActionPerformed
    model = (DefaultTableModel) residentlogsinfotable.getModel();
    Document document = new Document();
    try {/* www  .j a va2 s  . c  o  m*/
        PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\TimeInOutArchive.pdf"));
        document.open();

        PdfPTable tab = new PdfPTable(model.getColumnCount());
        for (int i = 0; i < model.getColumnCount(); i++) {
            tab.addCell(model.getColumnName(i));
        }
        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                if (model.getValueAt(i, j) != null) {
                    tab.addCell(model.getValueAt(i, j).toString());
                } else {
                    tab.addCell("-");
                }
            }
        }
        document.add(tab);

        JOptionPane.showMessageDialog(null,
                "Data saved at " + path + "'\\PDF\\TimeInOutArchive.pdf' successfully", "Message",
                JOptionPane.INFORMATION_MESSAGE);
        document.close();

    } catch (FileNotFoundException | DocumentException ex) {
        //            Logger.getLogger(TimeInOutArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:CrearPdf.java

CrearPdf(String[][] datos, String columnas[], String fecha, String autor, int d, String path) {

    try {/*from ww  w.  j a  v  a2 s . c  o m*/
        this.d = d;
        this.fecha = fecha;
        this.autor = autor;
        this.columnas = columnas;
        this.datos = datos;
        FILE = path;
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(FILE));
        document.open();
        addMetaData(document);
        addTitlePage(document);
        createTable(document);
        document.close();
        JOptionPane.showMessageDialog(null, "Guardado exitoso!", "Guardado exitoso!",
                JOptionPane.INFORMATION_MESSAGE);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:FullPageTable.java

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    PdfPTable table = new PdfPTable(10);

    table.setWidthPercentage(100);/* w w  w. j  a  va2s .  c o  m*/
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);

    // first row
    PdfPCell cell = new PdfPCell(new Phrase("DateRange"));
    cell.setColspan(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);

    table.addCell("Calldate");
    table.addCell("Calltime");
    table.addCell("Source");
    table.addCell("DialedNo");
    table.addCell("Extension");
    table.addCell("Trunk");
    table.addCell("Duration");
    table.addCell("Calltype");
    table.addCell("Callcost");
    table.addCell("Site");

    for (int i = 0; i < 100; i++) {
        table.addCell("date" + i);
        table.addCell("time" + i);
        table.addCell("source" + i);
        table.addCell("destination" + i);
        table.addCell("extension" + i);
        table.addCell("trunk" + i);
        table.addCell("dur" + i);
        table.addCell("toc" + i);
        table.addCell("callcost" + i);
        table.addCell("Site" + i);
    }
    document.add(table);
    document.close();
}

From source file:ResidentArchiveFrame.java

private void tabletoPDF1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tabletoPDF1ActionPerformed
    // TODO add your handling code here:
    String title = "";
    if (jTabbedPane2.getSelectedIndex() == 0) {
        model = (DefaultTableModel) residentpersonalinfotable.getModel();
        title = "PersonalInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 1) {
        model = (DefaultTableModel) residentcontactinfotable.getModel();
        title = "ContactInformation";
    } else if (jTabbedPane2.getSelectedIndex() == 2) {
        model = (DefaultTableModel) residentaddresstable.getModel();
        title = "Address";
    } else {/*from   w w  w  .  j a va  2 s.  c  om*/
        model = (DefaultTableModel) residentstatustable.getModel();
        title = "Status";
    }

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path + "\\PDF\\" + title + "ResidentArchive.pdf"));
        PdfReader pdfReader = new PdfReader("ReportGeneration.pdf");
        document.open();
        PdfPTable tab = new PdfPTable(model.getColumnCount());

        for (int i = 0; i < model.getColumnCount(); i++) {
            tab.addCell(model.getColumnName(i));
        }

        for (int i = 0; i < model.getRowCount(); i++) {
            for (int j = 0; j < model.getColumnCount(); j++) {
                if (model.getValueAt(i, j) != null) {
                    tab.addCell(model.getValueAt(i, j).toString());
                } else {
                    tab.addCell("-");
                }
            }
        }

        document.add(tab);
        pdfReader.close();
        document.close();

        JOptionPane.showMessageDialog(null,
                "Data saved at '" + path + "\\PDF\\" + title + "ResidentArchive.pdf' successfully", "Message",
                JOptionPane.INFORMATION_MESSAGE);

    } catch (FileNotFoundException ex) {
        //            Logger.getLogger(ResidentArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    } catch (DocumentException | IOException ex) {
        //            Logger.getLogger(ResidentArchiveFrame.class.getName()).log(Level.SEVERE, null, ex);
        new MessageDialog().error(this, ex.getMessage());
    }
}

From source file:imprimer.java

public void openPDF() {

    Document document = new Document(PageSize.A4);
    try {//from  w  w  w .  j a v  a  2 s .c o  m
        PdfWriter.getInstance(document, new FileOutputStream("imprimer test.pdf"));

        document.open();

        imagee(document);

        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Attestation de travail",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 3; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph p = new Paragraph(text,
                FontFactory.getFont(FontFactory.TIMES, 16, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p);

        Paragraph time = new Paragraph("                Fait  Ouarzazate le : " + tdnow,
                FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY));
        Paragraph a = new Paragraph("");
        Paragraph si = new Paragraph("                 Signature:",
                FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY));

        time.setAlignment(Paragraph.ALIGN_CENTER);
        si.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(time);
        document.add(si);
        document.add(a);
        document.close();

        System.out.println("date2");
        /* Open Pdf */
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("imprimer test.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

        System.out.println("date");

    } catch (Exception ex) {
        System.out.println("qsdqs");
    }
}

From source file:imprimer.java

public void attestation_travail_prof() {

    Document document = new Document(PageSize.A4);
    try {//from w  w  w  . j  a v a  2s .  c om
        PdfWriter.getInstance(document, new FileOutputStream("Attestation de travail Professeur.pdf"));
        document.open();

        imagee(document);
        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Attestation de travail",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 3; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph p = new Paragraph(text3,
                FontFactory.getFont(FontFactory.TIMES, 16, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p);

        Paragraph time = new Paragraph("                Fait  Ouarzazate le : " + tdnow,
                FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY));
        Paragraph a = new Paragraph("");
        Paragraph si = new Paragraph("                 Signature:",
                FontFactory.getFont(FontFactory.TIMES, 17, Font.BOLD, BaseColor.DARK_GRAY));

        time.setAlignment(Paragraph.ALIGN_CENTER);
        si.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(time);
        document.add(si);
        document.add(a);
        document.close();

        System.out.println("date2");
        /* Open Pdf */
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("Attestation de travail Professeur.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

        System.out.println("date");
    } catch (Exception ex) {

        System.out.println("qsdqs");
    }
}

From source file:imprimer.java

public void conje() {
    Document document = new Document(PageSize.A4);
    try {/* www  .  j a v a2  s  .  co  m*/
        PdfWriter.getInstance(document, new FileOutputStream("conjee.pdf"));

        document.open();
        imagee(document);
        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Dcision de cong",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph p = new Paragraph(text2,
                FontFactory.getFont(FontFactory.TIMES, 14, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p);
        Paragraph p3 = new Paragraph("DECIDE :",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));
        p3.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p3);
        Paragraph p4 = new Paragraph("ARTICLE I Un cong dun .",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p4);
        Paragraph p5 = new Paragraph(
                "           Est accord    :    \n" + "           C.I.N           :    \n"
                        + "           GRADE           :    \n" + "           Pour la priode :   ",
                FontFactory.getFont(FontFactory.TIMES, 15, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p5);
        Paragraph p6 = new Paragraph("ARTICLE II",
                FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p6);
        Paragraph p7 = new Paragraph(
                "Lintress(e) est autoris  quitter le territoire national durant la priode indique ci-dessus",
                FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p7);
        Paragraph p8 = new Paragraph("ARTICLE III",
                FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p8);
        Paragraph p9 = new Paragraph(
                "Lintress(e) est tenu daviser le service du personnel de sa reprise de travail aprs expiration du  cong sus-vis.",
                FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p9);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph time = new Paragraph(
                "             Cachet et signature                                        Fait  Ouarzazate le :"
                        + tdnow + "\n" + "\n",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));

        Paragraph si = new Paragraph("Signature du demandeur",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));
        time.setAlignment(Paragraph.ALIGN_LEFT);
        si.setAlignment(Paragraph.ALIGN_RIGHT);
        document.add(time);
        document.add(si);
        document.close();

        System.out.println("date2");
        /* Open Pdf */
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("conjee.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

        System.out.println("date");
    } catch (Exception ex) {

        System.out.println("qsdqs");
    }
}

From source file:imprimer.java

public void conje_exp() {
    Document document = new Document(PageSize.A4);
    try {//w  ww .j  a  v  a2s.c o m
        PdfWriter.getInstance(document, new FileOutputStream("conjee_exp.pdf"));

        document.open();
        imagee(document);
        SimpleDateFormat td = new SimpleDateFormat("dd-MM-yyyy");
        java.util.Date now = new java.util.Date();
        String tdnow = td.format(now);
        Paragraph pa = new Paragraph("Dcision de cong",
                FontFactory.getFont(FontFactory.TIMES, 30, Font.UNDERLINE, BaseColor.DARK_GRAY));
        pa.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(pa);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph p = new Paragraph(text2,
                FontFactory.getFont(FontFactory.TIMES, 14, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p);
        Paragraph p3 = new Paragraph("DECIDE :",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));
        p3.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p3);
        Paragraph p4 = new Paragraph("ARTICLE I",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p4);
        Paragraph p5 = new Paragraph(
                "           Un cong Exceptionnel dune dure de jours\n"
                        + "           Est accord    :    \n" + "           C.I.N           :    \n"
                        + "           GRADE           :    \n" + "           Pour la priode :   ",
                FontFactory.getFont(FontFactory.TIMES, 15, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p5);
        Paragraph p6 = new Paragraph("ARTICLE II",
                FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p6);
        Paragraph p7 = new Paragraph(
                "Lintress(e) est autoris  quitter le territoire national durant la priode indique ci-dessus",
                FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p7);
        Paragraph p8 = new Paragraph("ARTICLE III",
                FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLDITALIC, BaseColor.DARK_GRAY));
        document.add(p8);
        Paragraph p9 = new Paragraph(
                "Lintress(e) est tenu daviser le service du personnel de sa reprise de travail aprs expiration du  cong sus-vis.",
                FontFactory.getFont(FontFactory.TIMES, 18, Font.NORMAL, BaseColor.DARK_GRAY));
        document.add(p9);
        for (int i = 0; i < 4; i++) {
            document.add(new Paragraph(" "));
        }

        Paragraph time = new Paragraph(
                "             Cachet et signature                                        Fait  Ouarzazate le :"
                        + tdnow + "\n" + "\n",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));

        Paragraph si = new Paragraph("Signature du demandeur",
                FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, BaseColor.DARK_GRAY));
        time.setAlignment(Paragraph.ALIGN_LEFT);
        si.setAlignment(Paragraph.ALIGN_RIGHT);
        document.add(time);
        document.add(si);
        document.close();

        System.out.println("date2");
        /* Open Pdf */
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            desktop.open(new File("conjee_exp.pdf"));
        } else {
            System.out.println("Open is not supported");
        }

        System.out.println("date");
    } catch (Exception ex) {

        System.out.println("qsdqs");
    }
}