Example usage for com.lowagie.text Document setFooter

List of usage examples for com.lowagie.text Document setFooter

Introduction

In this page you can find the example usage for com.lowagie.text Document setFooter.

Prototype


public void setFooter(HeaderFooter footer) 

Source Link

Document

Changes the footer of this document.

Usage

From source file:wagwaan.reports.UpdatingStockCountPdf.java

public void generatePdf() {

    try {/* www  .  j a  va2  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("Updating Stock Count - 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, 9, 8, 8, 10, 8, 9, 9, 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("Updating Stock Count");
                    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("Deficit", 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("Delivery Date", pFontHeader);
                    table.addCell(phrase);

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

                    phrase = new Phrase("Fully Delivered", 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(quantity_received*o.price) from stock_orders o,st_receiving_issuing t,stock_items s,stock_suppliers st\n"
                                        + "where t.item_code=o.item_code and t.order_id=o.order_id and t.item_code=s.item_code and st.supplier_id=t.supplier_id and receiving_no='"
                                        + receive + "'");

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

                        java.sql.ResultSet rset = st.executeQuery(
                                "SELECT t.item_code,s.item_name, quantity_ordered,sum(quantity_received) , "
                                        + "(quantity_ordered-sum(quantity_received)) as def, o.price , (o.price*sum(quantity_received)) as total, st.supplier_names , receiving_date, \n"
                                        + "\n"
                                        + "t.order_id , delivered from stock_orders o,st_receiving_issuing t,stock_items s,stock_suppliers st where t.item_code=o.item_code "
                                        + "and t.order_id=o.order_id and t.item_code=s.item_code and st.supplier_id=t.supplier_id AND RECEIVING_NO='"
                                        + receive + "' group by 1,2,3,6, 8,9, 10, 11");
                        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);

                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            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(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(UpdatingStockCountPdf.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadElementException ex) {
                Logger.getLogger(UpdatingStockCountPdf.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());

    }

}