Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

From source file:vistas.reportes.procesos.rptFaltas.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/* w  w  w  .  ja  v  a  2  s. co m*/
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE FALTAS", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelFechaInicio = new Chunk("FECHA INICIO: ", font);
    Chunk labelFechaFin = new Chunk("FECHA FIN: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreFechaInicio = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreFechaFin = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaFin, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelFechaInicio, nombreFechaInicio)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelFechaFin, nombreFechaFin)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptFaltas().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:vistas.reportes.procesos.rptTardanzaTotal.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();//  www .j av a 2s  . c  o m
    Image cabecera = Image.getInstance("img/cabecera.png");
    cabecera.setAlignment(1);
    documento.add(cabecera);
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONSOLIDADO DE TARDANZA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("MES: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerNombreMes(fechaInicio).toUpperCase(),
            new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.TIMES_ROMAN, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptTardanzaTotal().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:wagwaan.reports.ActiveSuppliersPdf.java

public void generatePdf() {

    try {/*from   w  w  w .  ja  v a2 s. com*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));
                ReportUtil.addCenteredTitlePage(docPdf, connectDB);

                String date = null;
                try {
                    java.sql.Statement st3 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");

                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Active Suppliers- Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10);

                    int headerwidths[] = { 4, 6, 20, 11, 11, 10, 10, 10, 10, 9 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(5);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Active Suppliers");
                    table.addCell(phrase);
                    //                        table.getDefaultCell().setColspan(4);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);

                    phrase = new Phrase("#", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Suplier ID", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier Names", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Address", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Phone No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Email", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Bank Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Account No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Branch Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Reg. Date", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        /*Statement s=connectDB.createStatement();
                        ResultSet r=s.executeQuery("SELECT  sum(ord.price*quantity_received) total  FROM st_receiving_issuing REV, stock_orders ord, stock_items itm "
                            + "where receiving_no='"+issue+"' and itm.item_code=ord.item_code and itm.item_code=rev.item_code");*/

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select supplier_id, supplier_names, address, phone_no, email_address, bank_name, account_no, "
                                        + "branch_name, date_registered from stock_suppliers where active=true order by 1, 2");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.BlackListedSuppPdf.java

public void generatePdf() {

    try {/*from w  w w .  j av a2s . c o  m*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                String date = null;
                try {
                    java.sql.Statement st3 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("BlackListed Suppliers- Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10);

                    int headerwidths[] = { 4, 6, 20, 11, 11, 10, 10, 10, 10, 9 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(5);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("BlackListed Suppliers");
                    table.addCell(phrase);
                    //                        table.getDefaultCell().setColspan(4);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);

                    phrase = new Phrase("#", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Suplier ID", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier Names", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Address", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Phone No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Email", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Bank Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Account No", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Branch Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Reg. Date", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        /*Statement s=connectDB.createStatement();
                        ResultSet r=s.executeQuery("SELECT  sum(ord.price*quantity_received) total  FROM st_receiving_issuing REV, stock_orders ord, stock_items itm "
                            + "where receiving_no='"+issue+"' and itm.item_code=ord.item_code and itm.item_code=rev.item_code");*/

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select supplier_id, supplier_names, address, phone_no, email_address, bank_name, account_no, "
                                        + "branch_name, date_registered from stock_suppliers where active=false order by 1, 2");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(ActiveSuppliersPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.OrdersPdf.java

public void generatePdf() {

    try {/* w w w. j  av a  2 s .c o m*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Orders List - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                try {
                    ReportUtil.addCenteredTitlePage(docPdf, connectDB);

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(10);

                    int headerwidths[] = { 5, 10, 13, 10, 13, 10, 10, 10, 10, 10 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(5);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Items Ordered");
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    String order_nuos = null;

                    Statement sta = connectDB.createStatement();
                    ResultSet rst = sta
                            .executeQuery("select order_id from stock_orders where order_id='" + orders + "'");
                    while (rst.next()) {
                        order_nuos = rst.getString(1);
                    }

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setColspan(10);
                    phrase = new Phrase(order_nuos, pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.LEFT | PdfCell.BOTTOM | PdfCell.RIGHT);
                    phrase = new Phrase("Count", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Code", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Quantity", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Price", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Date Ordered", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Expected Delivery", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Ordered By", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Total", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        Statement s = connectDB.createStatement();
                        ResultSet r = s.executeQuery(
                                "SELECT  sum(price*quantity_ordered)  FROM stock_orders where order_id='"
                                        + orders + "' ");

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "SELECT ord.item_code, itm.item_name, quantity_ordered, price, date_ordered, expected_supply_date, "
                                        + "s.supplier_names, ordered_by, ord.price*ord.quantity_ordered  FROM stock_orders ord, stock_items itm, stock_suppliers s where order_id='"
                                        + orders + "' "
                                        + "and ord.item_code=itm.item_code and s.supplier_id=ord.supplier_id");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);

                            count++;
                        }
                        table.getDefaultCell().setColspan(10);
                        phrase = new Phrase(" ");
                        table.addCell(phrase);

                        String gt = null;
                        while (r.next()) {
                            gt = dbObject.getDBObject(r.getObject(1), "-");
                        }
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //                            table.getDefaultCell().setColspan(8);
                        phrase = new Phrase("GRAND TOTAL: " + gt, pFontHeader1);
                        table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(2);
                        //                            table.addCell(new Phrase(""));
                        System.err.println("grand total");
                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                } catch (SQLException ex) {
                    Logger.getLogger(OrdersPdf.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.StaffRegPdf.java

public void generatePdf() {

    try {/*from   w w w. j  a v a  2 s.c o m*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                    //                        com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                    //                        headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
                    //                        headerFoter.setRight(5);
                    //                        docPdf.setHeader(headerFoter);

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Staff Register - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(8);

                    int headerwidths[] = { 7, 10, 20, 13, 13, 13, 11, 13 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(4);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Staff Register");
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    //                        String order_nuos=null;
                    //                        
                    //                        Statement sta=connectDB.createStatement();
                    //                        ResultSet rst=sta.executeQuery("select order_id from stock_orders where order_id='"+orders+"'");
                    //                        while(rst.next()){
                    //                        order_nuos=rst.getString(1);
                    //                        }

                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("#", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Staff ID", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Names", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("ID NO.", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Phone No.", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Designation", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Gender", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("Department", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "SELECT staff_id, first_name||' '|| middle_name||' '|| last_name as names, national_id, phone_no, designation, "
                                        + "gender, dep.department_name  FROM staff_registration staff, departments dep where employment_date between '"
                                        + beginDate + "' and '" + endDate + "' "
                                        + "and  dep.department_id=staff.department_id");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(StaffRegPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(StaffRegPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.StocksIssuingPdf.java

public void generatePdf() {

    try {/*from   w  ww.j  av a2s.c om*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                    //                        com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                    //                        headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
                    //                        headerFoter.setRight(5);
                    //                        docPdf.setHeader(headerFoter);

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Issuing List - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(8);

                    int headerwidths[] = { 10, 12, 20, 10, 15, 12, 10, 11 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(4);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Items Issued");
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(4);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    String receive_nuos = null;

                    Statement sta = connectDB.createStatement();
                    ResultSet rst = sta.executeQuery(
                            "select issue_no from st_receiving_issuing where issue_no='" + issue + "'");
                    while (rst.next()) {
                        receive_nuos = rst.getString(1);
                    }
                    table.getDefaultCell().setColspan(8);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                    phrase = new Phrase(receive_nuos, pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);
                    phrase = new Phrase("Count", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Code", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Qty_issued", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Receiving Department", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Received By", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Issued By", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Issue Date", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        /*Statement s=connectDB.createStatement();
                        ResultSet r=s.executeQuery("SELECT  sum(ord.price*quantity_received) total  FROM st_receiving_issuing REV, stock_orders ord, stock_items itm "
                            + "where receiving_no='"+issue+"' and itm.item_code=ord.item_code and itm.item_code=rev.item_code");*/

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select st.item_code, item_name, quantity_issued, receiving_dept, receiver, issuer, issuing_date from st_receiving_issuing st,"
                                        + " stock_items itm where issue_no='" + issue
                                        + "'and itm.item_code=st.item_code");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            count++;
                        }
                        /*table.getDefaultCell().setColspan(12);
                        phrase=new Phrase(" ");
                        table.addCell(phrase);
                                
                        String gt=null;
                        while(r.next()){
                        gt=dbObject.getDBObject(r.getObject(1), "-");
                        }
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        phrase=new Phrase("GRAND TOTAL: "+gt, pFontHeader1);
                        table.addCell(phrase);
                        System.err.println("grand total");
                        */
                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                } catch (SQLException ex) {
                    Logger.getLogger(OrdersPdf.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(StocksIssuingPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(StocksIssuingPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.StocksReceivingPdf.java

public void generatePdf() {

    try {//from  w w  w .  j  a v  a  2  s . com

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                    //                        com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                    //                        headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
                    //                        headerFoter.setRight(5);
                    //                        docPdf.setHeader(headerFoter);

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Receiving List - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(12);

                    int headerwidths[] = { 6, 8, 8, 10, 9, 7, 9, 7, 9, 9, 9, 9 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(6);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Items Received");
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    String receive_nuos = null;

                    Statement sta = connectDB.createStatement();
                    ResultSet rst = sta
                            .executeQuery("select receiving_no from st_receiving_issuing where receiving_no='"
                                    + receive + "'");
                    while (rst.next()) {
                        receive_nuos = rst.getString(1);
                    }
                    table.getDefaultCell().setColspan(12);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                    phrase = new Phrase(receive_nuos, pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);
                    phrase = new Phrase("Count", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Code", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Qty_ordered", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Qty_received", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Price", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Total", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Supplier", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Date Ordered", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Receive Date", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Order ID", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Received By", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        Statement s = connectDB.createStatement();
                        ResultSet r = s.executeQuery(
                                "SELECT  buying_price, quantity_Received, sum(itm.buying_price*quantity_received) total  FROM st_receiving_issuing REV, "
                                        + "stock_items itm where receiving_no='" + receive
                                        + "' and itm.item_code=rev.item_code group by 1, 2");

                        java.sql.Statement st = connectDB.createStatement();

                        java.sql.ResultSet rset = st.executeQuery(
                                "select rec.item_code, itm.item_name, ord.quantity_ordered, quantity_received, buying_price, "
                                        + "quantity_received*buying_price as total, sup.supplier_names, date_ordered, receiving_date, rec.order_id, receiver from st_receiving_issuing rec, "
                                        + "stock_items itm, stock_orders ord, stock_suppliers sup where rec.item_code=itm.item_code and ord.item_code=rec.item_code "
                                        + "and ord.order_id=rec.order_id and sup.supplier_id=rec.supplier_id and receiving_no='"
                                        + receive + "'");
                        int count = 1;
                        while (rset.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                            table.addCell(phrase);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                            table.addCell(phrase);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(9), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(10), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(rset.getObject(11), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }
                        table.getDefaultCell().setColspan(12);
                        phrase = new Phrase(" ");
                        table.addCell(phrase);

                        String gt = null;
                        while (r.next()) {
                            gt = dbObject.getDBObject(r.getObject(3), "-");
                        }
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        phrase = new Phrase("GRAND TOTAL: " + gt, pFontHeader1);
                        table.addCell(phrase);
                        System.err.println("grand total");
                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                } catch (SQLException ex) {
                    Logger.getLogger(OrdersPdf.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(StocksReceivingPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(StocksReceivingPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.StocksRequestPdf.java

public void generatePdf() {

    try {/*from  w  w w.ja  v a2  s  . c  o  m*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st3 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                    //                        com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                    //                        headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
                    //                        headerFoter.setRight(5);
                    //                        docPdf.setHeader(headerFoter);

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Receiving List - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                ReportUtil.addCenteredTitlePage(docPdf, connectDB);
                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(8);

                    int headerwidths[] = { 11, 11, 20, 11, 11, 16, 10, 10 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(8);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("ITEMS REQUESTED");
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(8);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    String receive_nuos = null;

                    Statement sta = connectDB.createStatement();
                    ResultSet rst = sta.executeQuery(
                            "select request_no from stock_request where request_no='" + receive + "'");
                    while (rst.next()) {
                        receive_nuos = rst.getString(1);
                    }
                    table.getDefaultCell().setColspan(8);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                    phrase = new Phrase(receive_nuos, pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell()
                            .setBorder(PdfCell.TOP | PdfCell.BOTTOM | PdfCell.LEFT | PdfCell.RIGHT);
                    phrase = new Phrase("##", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Code", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Item Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Quantity", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Request Date", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Expected Date", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Department Name", pFontHeader);
                    table.addCell(phrase);

                    phrase = new Phrase("Requisitioner", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    try {
                        Statement s = connectDB.createStatement();
                        ResultSet r = s.executeQuery(
                                "SELECT R.ITEM_CODE, ITEM_NAME, quantity_requested, REQUEST_DATE, EXPECTED_DATE,  "
                                        + "REQUESTING_DEPT, CURRENT_USR FROM STOCK_REQUEST R, STOCK_ITEMS I, DEPARTMENTS D WHERE I.ITEM_CODE=R.ITEM_CODE "
                                        + "AND REQUEST_NO='" + receive_nuos
                                        + "' AND REQUESTING_DEPT=D.DEPARTMENT_ID");

                        int count = 1;
                        while (r.next()) {

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            table.getDefaultCell().setColspan(1);
                            numberSeq += 1;

                            phrase = new Phrase("" + count + "   ", pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(1), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(2), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(3), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(4), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(5), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(6), "-"), pFontHeader1);
                            table.addCell(phrase);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(dbObject.getDBObject(r.getObject(7), "-"), pFontHeader1);
                            table.addCell(phrase);
                            count++;
                        }

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                } catch (SQLException ex) {
                    Logger.getLogger(StocksRequestPdf.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(StocksRequestPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(StocksRequestPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}

From source file:wagwaan.reports.SupplierInvPdf.java

public void generatePdf() {

    try {//from w w w .  j  ava 2s  .  c om

        java.io.File tempFile = java.io.File.createTempFile("REP" + label.getDateLable() + "_", ".pdf");

        tempFile.deleteOnExit();

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

        try {

            try {

                com.lowagie.text.pdf.PdfWriter.getInstance(docPdf, new java.io.FileOutputStream(tempFile));

                String date = null;
                try {
                    java.sql.Statement st4 = connectDB.createStatement();

                    java.sql.ResultSet rset4 = st4.executeQuery("SELECT date(now()) as Date");
                    while (rset4.next())
                        date = rset4.getObject(1).toString();

                } catch (java.sql.SQLException SqlExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

                }

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase("Supplier's Payment - Page: "), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();
                ReportUtil.addCenteredTitlePage(docPdf, connectDB);

                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(8);

                    int headerwidths[] = { 10, 10, 22, 10, 12, 12, 12, 12 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));
                    table.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table.getDefaultCell().setColspan(4);

                    Phrase phrase;

                    java.text.DateFormat dateFormat = java.text.DateFormat
                            .getDateInstance(java.text.DateFormat.MEDIUM);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Invoice Specifics");
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase = new Phrase("Printed On  :" + date, pFontHeader);
                    table.addCell(phrase);

                    Statement str = connectDB.createStatement();
                    ResultSet r = str.executeQuery(
                            "SELECT distinct(c.account_no), SUPPLIER_NAMES FROM STOCK_SUPPLIERS, creditors_ledger c "
                                    + "WHERE SUPPLIER_ID=c.account_no and invoice_no='" + invoice_no + "'");
                    String acno = null, names = null;
                    while (r.next()) {
                        acno = r.getString(1);
                        names = r.getString(2);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("ACCOUNT NO:  " + dbObject.getDBObject(r.getString(1), "-"),
                                pFontHeader1);
                        table.addCell(phrase);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("SUPPLIER NAMES:  " + dbObject.getDBObject(r.getString(2), "-"),
                                pFontHeader1);
                        table.addCell(phrase);
                    }

                    table.getDefaultCell().setColspan(8);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    phrase = new Phrase("INVOICE NO: " + invoice_no, pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    String receiving_no = null;
                    try {
                        Statement s = connectDB.createStatement();
                        ResultSet rr = s.executeQuery(
                                "SELECT DISTINCT(RECEIVING_NO) FROM CREDITORs_LEDGER WHERE INVOICE_NO='"
                                        + invoice_no + "'");

                        while (rr.next()) {
                            receiving_no = rr.getString(1);

                            table.getDefaultCell().setColspan(8);
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(receiving_no, pFontHeader);
                            table.addCell(phrase);

                            table.getDefaultCell().setColspan(1);
                            table.getDefaultCell()
                                    .setBorder(PdfCell.TOP | PdfCell.LEFT | PdfCell.BOTTOM | PdfCell.RIGHT);
                            phrase = new Phrase("Count", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Item Code", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Item Name", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Quantity", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Price", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Total", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Amount Paid", pFontHeader);
                            table.addCell(phrase);

                            phrase = new Phrase("Balance", pFontHeader);
                            table.addCell(phrase);

                            java.sql.Statement st = connectDB.createStatement();
                            java.sql.ResultSet rset = st.executeQuery(
                                    "SELECT DISTINCT(C.ITEM_CODE), ITEM_NAME, BUYING_PRICE, QUANTITY_RECEIVED, "
                                            + "(BUYING_PRICE*QUANTITY_RECEIVED) AS TOTAL, SUM(DEBIT), (BUYING_PRICE*QUANTITY_RECEIVED)-SUM(DEBIT) AS BALANCE "
                                            + "FROM STOCK_ORDERS O, STOCK_ITEMS I, ST_RECEIVING_ISSUING R, CREDITORS_LEDGER C WHERE O.ITEM_CODE=I.ITEM_CODE "
                                            + "AND I.ITEM_CODE=C.ITEM_CODE AND R.RECEIVING_NO=C.RECEIVING_NO AND C.RECEIVING_NO='"
                                            + receiving_no + "' "
                                            + "AND O.ORDER_ID=R.ORDER_ID GROUP BY 1, 2, 3, 4, 5");
                            int count = 1;
                            while (rset.next()) {

                                table.getDefaultCell().setColspan(1);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                                phrase = new Phrase("" + count + "   ", pFontHeader1);
                                table.addCell(phrase);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                                table.addCell(phrase);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                                table.addCell(phrase);
                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"), pFontHeader1);
                                table.addCell(phrase);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);

                                table.addCell(phrase);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(5), "-"), pFontHeader1);
                                table.addCell(phrase);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(6), "-"), pFontHeader1);
                                table.addCell(phrase);

                                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                                phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                                table.addCell(phrase);

                                count++;
                            }
                        }

                        table.getDefaultCell().setColspan(8);
                        phrase = new Phrase(" ");
                        table.addCell(phrase);
                        phrase = new Phrase(" ");
                        table.addCell(phrase);

                        double bal = 0.0;
                        //                             double bals=-bal;
                        Statement finale = connectDB.createStatement();
                        ResultSet f = finale.executeQuery(
                                "SELECT SUM(CREDIT)-SUM(DEBIT) FROM CREDITORS_LEDGER WHERE ACCOUNT_NO='" + acno
                                        + "'");

                        while (f.next()) {
                            bal = f.getDouble(1);
                        }
                        double bals = -bal;
                        System.out.println();
                        if (bal > 0) {
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            phrase = new Phrase("THE ORGANIZATION OWES " + names + " an amount of KSH. " + bal,
                                    pFontHeader);
                            table.addCell(phrase);
                        }

                        else {
                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            phrase = new Phrase(
                                    "THE ORGANIZATION OVERPAID " + names + " an amount of KSH. " + bals,
                                    pFontHeader);
                            table.addCell(phrase);
                        }
                        docPdf.add(table);
                    } catch (java.sql.SQLException SqlExec) {

                        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
                                SqlExec.getMessage());

                    }

                } catch (com.lowagie.text.BadElementException BadElExec) {

                    javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), BadElExec.getMessage());

                } catch (SQLException ex) {
                    Logger.getLogger(OrdersPdf.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (java.io.FileNotFoundException fnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());

            } catch (SQLException ex) {
                Logger.getLogger(SupplierInvPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(SupplierInvPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (com.lowagie.text.DocumentException lwDocexec) {

            javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());

        }

        docPdf.close();

        deskTop.open(tempFile);

    } catch (java.io.IOException IOexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());

    }

}