Example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.lowagie.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

/**
 * Outputs a PDF file report of the data in drs to the given
 * output stream.//from  w  ww . j av a 2  s .  c  o  m
 * @throws SQLObjectException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void format(OutputStream out, List<ProfileResult> profileResults)
        throws DocumentException, IOException, SQLException, SQLObjectException, InstantiationException,
        IllegalAccessException, ClassNotFoundException {

    final int minRowsTogether = 1; // counts smaller than this are considered orphan/widow
    final int mtop = 50; // margin at top of page (in points)
    final int mbot = 50; // margin at bottom of page (page numbers are below this)
    //        final int pbot = 20;  // padding between bottom margin and bottom of body text
    final int mlft = 50; // margin at left side of page
    final int mrgt = 50; // margin at right side of page
    final Rectangle pagesize = PageSize.LETTER.rotate();
    final Document document = new Document(pagesize, mlft, mrgt, mtop, mbot);
    final PdfWriter writer = PdfWriter.getInstance(document, out);

    final float fsize = 6f; // the font size to use in the table body
    final BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    document.addTitle("Table Profiling Report");
    document.addSubject("Tables: " + profileResults);
    document.addAuthor(System.getProperty("user.name"));
    document.addCreator("Power*Architect version " + ArchitectVersion.APP_FULL_VERSION);

    document.open();

    // vertical position where next element should start
    //   (bottom is 0; top is pagesize.height())
    float pos = pagesize.height() - mtop;

    final PdfContentByte cb = writer.getDirectContent();
    final PdfTemplate nptemplate = cb.createTemplate(50, 50);
    writer.setPageEvent(new PdfPageEventHelper() {
        // prints the "page N of <template>" footer
        public void onEndPage(PdfWriter writer, Document document) {
            int pageN = writer.getPageNumber();
            String text = "Page " + pageN + " of ";
            float len = bf.getWidthPoint(text, fsize - 2);
            cb.beginText();
            cb.setFontAndSize(bf, fsize - 2);
            cb.setTextMatrix(pagesize.width() / 2 - len / 2, mbot / 2);
            cb.showText(text);
            cb.endText();
            cb.addTemplate(nptemplate, pagesize.width() / 2 - len / 2 + len, mbot / 2);
        }

        public void onCloseDocument(PdfWriter writer, Document document) {
            nptemplate.beginText();
            nptemplate.setFontAndSize(bf, fsize - 2);
            nptemplate.showText(String.valueOf(writer.getPageNumber() - 1));
            nptemplate.endText();
        }
    });

    document.add(new Paragraph("SQL Power Architect Profiling Report"));
    document.add(new Paragraph("Generated " + new java.util.Date() + " by " + System.getProperty("user.name")));

    float[] widths = new float[totalColumn]; // widths of widest cells per row in pdf table
    LinkedList<ProfileTableStructure> profiles = new LinkedList<ProfileTableStructure>(); // 1 table per profile result

    Font f = new Font(bf, fsize);

    // This ddl generator is set to the appropriate ddl generator for the source database
    // every time we encounter a table profile result in the list.
    DDLGenerator ddlg = null;

    PdfPTable pdfTable = null;
    for (ProfileResult result : profileResults) {
        if (result instanceof TableProfileResult) {
            TableProfileResult tableResult = (TableProfileResult) result;
            pdfTable = new PdfPTable(widths.length);
            pdfTable.setWidthPercentage(100f);
            ProfileTableStructure oneProfile = makeNextTable(tableResult, pdfTable, bf, fsize, widths);
            profiles.add(oneProfile);
            ddlg = tableResult.getDDLGenerator();
        } else if (result instanceof ColumnProfileResult) {
            final ColumnProfileResult columnResult = (ColumnProfileResult) result;
            TableProfileResult tResult = columnResult.getParent();
            addBodyRow(tResult, columnResult, ddlg, pdfTable, bf, f, fsize, widths);
        }
    }

    double allowedTableSize = pagesize.width() - mrgt - mlft;
    double totalWidths = 0;
    for (int i = 0; i < headings.length; i++) {
        if (!columnsToTruncate.contains(headings[i])) {
            widths[i] += PIXELS_PER_BORDER;
            totalWidths += widths[i];
        }
    }
    truncateLength = (allowedTableSize - totalWidths - (PIXELS_PER_BORDER * (columnsToTruncate.size())))
            / columnsToTruncate.size();
    logger.debug("Truncate length is " + truncateLength);
    widths = new float[totalColumn];

    profiles = new LinkedList<ProfileTableStructure>(); // 1 table per profile result
    for (ProfileResult result : profileResults) {
        if (result instanceof TableProfileResult) {
            TableProfileResult tableResult = (TableProfileResult) result;
            pdfTable = new PdfPTable(widths.length);
            pdfTable.setWidthPercentage(100f);
            ProfileTableStructure oneProfile = makeNextTable(tableResult, pdfTable, bf, fsize, widths);
            profiles.add(oneProfile);
            ddlg = tableResult.getDDLGenerator();
        } else if (result instanceof ColumnProfileResult) {
            final ColumnProfileResult columnResult = (ColumnProfileResult) result;
            TableProfileResult tResult = columnResult.getParent();
            addBodyRow(tResult, columnResult, ddlg, pdfTable, bf, f, fsize, widths);
        }
    }

    for (int i = 0; i < headings.length; i++) {
        widths[i] += PIXELS_PER_BORDER;
    }

    // add the PdfPTables to the document; try to avoid orphan and widow rows
    pos = writer.getVerticalPosition(true) - fsize;
    logger.debug("Starting at pos=" + pos);
    boolean newPageInd = true;

    for (ProfileTableStructure profile : profiles) {

        pdfTable = profile.getMainTable();
        pdfTable.setTotalWidth(pagesize.width() - mrgt - mlft);
        pdfTable.setWidths(widths);
        resetHeaderWidths(profile, widths);

        int startrow = pdfTable.getHeaderRows();
        int endrow = startrow; // current page will contain header+startrow..endrow

        /* no other rows in the table, just the header, and the header may
         * contain error message
         */
        if (endrow == pdfTable.size()) {
            pos = pdfTable.writeSelectedRows(0, pdfTable.getHeaderRows(), mlft, pos, cb);
            continue;
        }

        while (endrow < pdfTable.size()) {

            // figure out how many body rows fit nicely on the page
            float endpos = pos - calcHeaderHeight(pdfTable);

            // y position of page number# = (mbot/2+fsize)
            while ((endpos - pdfTable.getRowHeight(endrow)) >= (mbot / 2 + fsize + 2)
                    && endrow < pdfTable.size()) {
                endpos -= pdfTable.getRowHeight(endrow);
                endrow++;
            }

            // adjust for orphan rows. Might create widows or make
            // endrow < startrow, which is handled later by deferring the table
            if (endrow < pdfTable.size() && endrow + minRowsTogether >= pdfTable.size()) {

                // page # maybe fall into table area, but usually that's column of
                // min value, usually that's enough space for both, or we should
                // disable page # on this page
                if (endrow + 1 == pdfTable.size() && endpos - pdfTable.getRowHeight(endrow) > 10) {

                    // short by 1 row.. just squeeze it in
                    endrow = pdfTable.size();
                } else {
                    // more than 1 row remains: shorten this page so orphans aren't lonely
                    endrow = pdfTable.size() - minRowsTogether;
                }
            }

            if (endrow == pdfTable.size() || endrow - startrow >= minRowsTogether) {
                // this is the end of the table, or we have enough rows to bother printing
                pos = pdfTable.writeSelectedRows(0, pdfTable.getHeaderRows(), mlft, pos, cb);
                pos = pdfTable.writeSelectedRows(startrow, endrow, mlft, pos, cb);
                startrow = endrow;
                newPageInd = false;
            } else {
                // not the end of the table and not enough rows to print out
                if (newPageInd)
                    throw new IllegalStateException(
                            "PDF Page is not large engouh to display " + minRowsTogether + " row(s)");
                endrow = startrow;
            }

            // new page if necessary (that is, when we aren't finished the table yet)
            if (endrow != pdfTable.size()) {
                document.newPage();
                pos = pagesize.height() - mtop;
                newPageInd = true;
            }
        }
    }
    document.close();
}

From source file:classroom.filmfestival_c.Movies17.java

@SuppressWarnings("unchecked")
protected static Element getTable(Query q, Date date) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);

    PdfPCell cell = new PdfPCell(new Phrase(date.toString(), NORMALWHITE));
    cell.setBackgroundColor(BLACK);//  w  w  w .  ja v  a 2 s.com
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    q.setDate(0, date);
    java.util.List<FestivalScreening> screenings = q.list();
    for (FestivalScreening screening : screenings) {
        addScreening(table, screening);
    }
    return table;
}

From source file:classroom.filmfestival_c.Movies17.java

protected static Element fullTitle(FestivalScreening screening) throws DocumentException {
    FilmTitle movie = screening.getFilmTitle();
    // a table with 3 cells
    PdfPTable table = new PdfPTable(3);
    table.setWidths(INNER);/*w w w. j  a va  2 s.c om*/
    table.setWidthPercentage(100);

    // the title(s)
    Paragraph p = new Paragraph();
    p.add(new Phrase(movie.getTitle(), BOLD));
    p.setLeading(16);
    // maybe an alternative title
    if (movie.getATitle().trim().length() > 0) {
        p.add(new Phrase(" (" + movie.getATitle() + ")"));
    }
    PdfPCell cell = new PdfPCell();
    cell.addElement(p);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    table.addCell(cell);

    // eXploreZone?
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    if (isExploreZone(movie)) {
        cell.setBackgroundColor(WHITE);
        cell.setUseAscender(true);
        cell.setUseDescender(true);
        cell.addElement(new Paragraph("eXplore"));
    }
    table.addCell(cell);

    // Duration / shortfilm
    cell = new PdfPCell();
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBackgroundColor(WHITE);
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    StringBuffer buf = new StringBuffer();
    buf.append(movie.getDuration());
    buf.append('\'');
    if (getExtra(screening) > 0) {
        buf.append(" + KF");
        buf.append(getExtra(screening));
        buf.append('\'');
    }
    p = new Paragraph(buf.toString());
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    table.addCell(cell);
    return table;
}

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

private static void addTable(Document pdfDocument, Chapter pdfSheet, int totalWidth, float[] widths,
        PdfPTable pdfTable) throws Exception {
    final int MAX_WIDTH = (int) (pdfDocument.getPageSize().getWidth() / 842 * 65000);
    //      if(totalWidth>MAX_WIDTH) {
    //Split the tables in subcolumns
    for (int offset = 0; offset < pdfTable.getNumberOfColumns();) {
        if (offset > 0)
            pdfSheet.add(new Chunk(" "));

        //Calculates the indexes that fit the page: [offset; index2]
        int subTotalWidth = 0;
        int index2;
        for (index2 = offset; index2 < pdfTable.getNumberOfColumns() && subTotalWidth < MAX_WIDTH; index2++) {
            subTotalWidth += widths[index2] * totalWidth;
        }/*from  w  ww  .  ja v a2s  . c  o  m*/
        index2 = Math.min(index2, pdfTable.getNumberOfColumns() - 1);

        //Calculates the new sub widths
        float[] subWidths = new float[index2 - offset + 2];
        for (int i = 0; i < subWidths.length - 1; i++) {
            subWidths[i] = widths[offset + i] * totalWidth / MAX_WIDTH;
        }
        subWidths[subWidths.length - 1] = Math.max(0, (float) (MAX_WIDTH - subTotalWidth) / MAX_WIDTH);
        System.out.println("PDFUtils.addTable() " + Arrays.toString(subWidths));

        //Creates the new sub widths
        PdfPTable subtable = new PdfPTable(subWidths.length);
        subtable.setWidths(subWidths);
        for (int r = 0; r < pdfTable.getRows().size(); r++) {
            for (int c = 0; c < index2 - offset + 1; c++) {
                PdfPCell cell = pdfTable.getRow(r).getCells()[c + offset];
                subtable.addCell(cell);
            }
            PdfPCell pdfCell = new PdfPCell();
            pdfCell.setBorder(0);
            subtable.addCell(pdfCell);
        }

        subtable.setWidthPercentage(100);
        collapseBorder(subtable);
        pdfSheet.add(subtable);

        //Go to the next index offset
        offset = index2 + 1;
    }
    //      } else {
    //         //Calculates the new sub widths
    //         float[] subWidths = new float[widths.length+1];
    //         for (int i = 0; i < subWidths.length-1; i++) {
    //            subWidths[i] = widths[0]*totalWidth/MAX_WIDTH;
    //         }
    //         subWidths[subWidths.length-1] = Math.max(0, (float)(MAX_WIDTH-totalWidth)/MAX_WIDTH);
    //         pdfTable.setWidths(subWidths);
    //         pdfTable.setWidthPercentage(100);
    //         collapseBorder(pdfTable);
    //         pdfSheet.add(pdfTable);
    //      }
}

From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf.java

public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {/*w ww . jav  a2 s .c  o  m*/

        java.io.File tempFile = java.io.File.createTempFile("REP" + this.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(com.lowagie.text.PageSize.A4,40,40,40,40);

        //   com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4);
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
        try {

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

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

                // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize());

                String compName = null;
                String date = null;

                try {

                    java.sql.Statement st6 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

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

                    //  docPdf.setFooter(footer);
                } catch (java.sql.SQLException SqlExec) {

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

                }

                docPdf.open();

                String Username = null;
                int numColumns = 9;

                try {

                    java.util.Calendar calendar = java.util.Calendar.getInstance();

                    long dateNow = calendar.getTimeInMillis();

                    java.sql.Date datenowSql = new java.sql.Date(dateNow);

                    System.out.println(datenowSql.toString());

                    //  java.lang.Object listofStaffNos[] = this.getListofStaffNos();

                    com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6);
                    //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

                    // table.endHeaders();

                    int headerwidths[] = { 15, 15, 30, 15, 15, 15 };

                    table1.setWidths(headerwidths);
                    //  if (docPdf.getPageNumber() > 1) {
                    //  table1.setHeaderRows(4);
                    //  }
                    table1.setWidthPercentage((100));

                    table1.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table1.getDefaultCell().setColspan(7);

                    Phrase phrase = new Phrase();

                    //  table.addCell(phrase);

                    table1.getDefaultCell().setColspan(1);
                    //  table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    //  table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                    try {
                        Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());
                        //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark"));
                        table1.getDefaultCell().setColspan(10);
                        table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                        table1.getDefaultCell().setFixedHeight(50);
                        table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()));
                        table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                        table1.getDefaultCell().setFixedHeight(25);
                        java.sql.Statement st3 = connectDB.createStatement();
                        java.sql.ResultSet rset3 = st3
                                .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile");
                        while (rset3.next()) {

                            table1.getDefaultCell().setColspan(6);

                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11);
                            table1.addCell(phrase);
                        }
                    } catch (java.sql.SQLException SqlExec) {

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

                    }
                    docPdf.add(table1);
                } catch (com.lowagie.text.BadElementException BadElExec) {

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

                }

                try {
                    com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10);
                    table1.getDefaultCell().setPadding(3);

                    int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 };

                    //  table1.setWidths(headerwidths1);

                    table1.setWidthPercentage((100));

                    table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                    Phrase phrase = new Phrase("", pFontHeader);

                    try {

                        // java.sql.Statement st3 = conDB.createStatement();

                        //  java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner");
                        //  java.sql.Statement st3 = conDb.createStatement();
                        java.sql.Statement st3 = connectDB.createStatement();
                        //java.sql.Statement st1 = connectDB.createStatement();
                        java.sql.Statement st2 = connectDB.createStatement();
                        java.sql.Statement st11 = connectDB.createStatement();
                        java.sql.Statement st4 = connectDB.createStatement();
                        java.sql.Statement st5 = connectDB.createStatement();
                        java.sql.Statement st6 = connectDB.createStatement();
                        java.sql.ResultSet rset3 = st3.executeQuery(
                                "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile");
                        //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name  ilike '"+selectSupp+"'");
                        java.sql.ResultSet rset4 = st4.executeQuery(
                                "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier,"
                                        + " received_requisation,reason,date,store_name FROM st_receive_requisation where REQUISITION_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        java.sql.ResultSet rset5 = st5.executeQuery(
                                "select DISTINCT date_due from st_receive_requisation where requisition_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        java.sql.ResultSet rset11 = st11.executeQuery(
                                "select initcap(user_name) from st_receive_requisation where requisition_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        while (rset11.next()) {
                            Username = rset11.getObject(1).toString();
                        }
                        table1.getDefaultCell().setBorderColor(java.awt.Color.white);

                        while (rset4.next()) {

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("  ", pFontHeader);
                            //table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("FROM TEAM LEADER LOGISTICS", pFontHeader5);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5);
                            table1.addCell(phrase);
                            //                                table1.getDefaultCell().setColspan(10);
                            //                                table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            //                                phrase = new Phrase("NUMBER KNH/SCM-MTCE STORES/......", pFontHeader5);
                            //                                table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5);
                            table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);
                            //table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(6);

                            phrase = new Phrase("FROM : " + rset4.getObject(8).toString(), pFontHeader);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(4);
                            phrase = new Phrase("DATE: " + rset4.getObject(7).toString() + "PR NO: "
                                    + rset4.getObject(1).toString(), pFontHeader);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase("TO : " + rset4.getObject(3).toString(), pFontHeader);
                            table1.addCell(phrase);

                            //                                table1.getDefaultCell().setColspan(10);
                            //                                phrase = new Phrase("  " + rset4.getObject(2).toString(), pFontHeader);
                            //                                table1.addCell(phrase);

                            /*
                             * table1.getDefaultCell().setColspan(5);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase); phrase = new
                             * Phrase("PROCUREMENT METHOD : ", pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("REQUISITION NO: " +
                             * rset4.getObject(1).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("ACCOUNT NO: ",
                             * pFontHeader); table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("REASON FOR PURCHASE " +
                             * rset4.getObject(6).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5);
                             *
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("", pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase("NAME OF THE SUPPLIER " +
                             * rset4.getObject(4).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("CONTRACT NO: ",
                             * pFontHeader); table1.addCell(phrase);
                             *
                             */

                        }

                        docPdf.add(table1);

                    } 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());

                }

                double Total = 0.00;
                double discount = 0.00;
                double vat = 0.00;
                double qty = 0.00;
                double price = 0.00;
                double value = 0.00;

                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);
                    table.getDefaultCell().setPadding(3);

                    int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

                    com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9);
                    // table3.getDefaultCell().setPadding(3);

                    int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 };

                    table3.setWidths(headerwidths3);

                    table3.setWidthPercentage((100));
                    //table.getDefaultCell().setBorderColor(java.awt.Color.black);
                    //table.getDefaultCell().setBorder(Rectangle.BOTTOM);
                    table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                    table.getDefaultCell().setColspan(9);
                    Phrase phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table3.getDefaultCell()
                            .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("NOs ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Item No/Code ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(2);

                    phrase = new Phrase("Item Description", pFontHeader);
                    table3.addCell(phrase);
                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Units of Issue. ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Qty Required. ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Monthly Usage ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(2);
                    phrase = new Phrase("Remarks", pFontHeader);
                    table3.addCell(phrase);

                    //                        phrase = new Phrase("Est.Cost ", pFontHeader);
                    //                        table3.addCell(phrase);
                    //
                    //                        phrase = new Phrase("Actual Cost", pFontHeader);
                    //                        table3.addCell(phrase);
                    //
                    //                        phrase = new Phrase("Tender/Qtn Ref.", pFontHeader);
                    //                        table3.addCell(phrase);

                    phrase = new Phrase("", pFontHeader);
                    //table.addCell(phrase);
                    table3.setHeaderRows(1);

                    //                        table3.getDefaultCell().setColspan(1);
                    //
                    //                        table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    //  table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                    String coment = "";

                    try {

                        // java.sql.Statement st6 = connectDB.createStatement();
                        java.sql.Statement st1 = connectDB.createStatement();

                        java.sql.ResultSet rset1 = st1
                                .executeQuery("SELECT initcap(item_description),units,cos_glcode,"
                                        + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation"
                                        + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");

                        table.getDefaultCell().setBorderColor(java.awt.Color.lightGray);

                        while (rset1.next()) {

                            // value = qty * price;

                            cnt = cnt + 1;

                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase("" + cnt, pFontHeader2);
                            table3.getDefaultCell().setBorderColor(java.awt.Color.black);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2);
                            table3.getDefaultCell().setBorderColor(java.awt.Color.black);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(2);
                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString());
                            phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(2);
                            phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2);
                            //                                table3.addCell(phrase);
                            //
                            //                                // System.out.println("Second "+docPdf.top());
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                value = value + rset1.getDouble(6);
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            //                                // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2);
                            //
                            //                                // table.addCell(phrase);
                            //                                //  coment = rset1.getObject(12).toString();

                        }

                        table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                        table.getDefaultCell()
                                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);
                        table.getDefaultCell().setFixedHeight(350);
                        table.addCell(table3);

                        table.getDefaultCell().setFixedHeight(20);

                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                        //                            phrase = new Phrase("TOTAL COST", pFontHeader);
                        //
                        //                            table.addCell(phrase);

                        //                            table.getDefaultCell().setColspan(1);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //                            phrase = new Phrase("", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(1);

                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //                            phrase = new Phrase("", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(1);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //                            phrase = new Phrase("", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(1);

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

                        //                            table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //
                        //                            phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(value)), pFontHeader);
                        //
                        //                            table.addCell(phrase);

                        //                            table.getDefaultCell().setColspan(1);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                        //                            phrase = new Phrase("", pFontHeader);

                        //                            table3.addCell(phrase);

                        table.getDefaultCell().setColspan(9);
                        table.getDefaultCell()
                                .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT);
                        phrase = new Phrase(" ", pFontHeader);

                        table.addCell(phrase);
                        table.getDefaultCell().setBorder(Rectangle.TOP);

                        table.addCell(phrase);
                        //table.getDefaultCell().setBorder(Rectangle.TOP);

                        /*
                         *
                         *
                         * table.getDefaultCell().setColspan(6);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("Prepared By :"
                         * +Username.toUpperCase(), pFontHeader);
                         *
                         * table.addCell(phrase);
                         */

                        table.getDefaultCell().setColspan(3);
                        table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("PREPARED BY.................................", pFontHeader);

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("Sign.................................", pFontHeader);

                        table.addCell(phrase);

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

                        table.addCell(phrase);

                        phrase = new Phrase("Time.................................\n", pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(3);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader);

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("Sign.................................", pFontHeader);

                        table.addCell(phrase);

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

                        table.addCell(phrase);

                        phrase = new Phrase("Time.................................\n", pFontHeader);

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(3);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................",
                                pFontHeader);

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        phrase = new Phrase("Sign.................................", pFontHeader);

                        table.addCell(phrase);

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

                        table.addCell(phrase);

                        phrase = new Phrase("Time.................................\n", pFontHeader);

                        table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(4);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Amount Voted..................................................", pFontHeader);
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(5);
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Vote Balance.........................................................", pFontHeader);
                        //                            table.addCell(phrase);
                        //
                        //
                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Date.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        // phrase = new Phrase("SIGN..........................................................", pFontHeader);
                        //table.addCell(phrase);

                        table.getDefaultCell().setColspan(9);

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

                        table.addCell(phrase);

                        //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader);

                        //table.addCell(phrase);
                        //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);

                        //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Approved/Not Approved.....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Procurement Section.....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Inv No.......................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign....................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date.......................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(1);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Time...........................", pFontHeader);
                        //
                        //                            table.addCell(phrase);

                        /*
                         * table.getDefaultCell().setColspan(5);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new
                         * Phrase("REMARK___________________________________",
                         * pFontHeader);
                         *
                         * table.addCell(phrase);
                         * table.getDefaultCell().setColspan(4);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("DATE
                         * RECEIVED____________________________",
                         * pFontHeader); table.addCell(phrase);
                         *
                         * table.getDefaultCell().setColspan(5);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase(" ", pFontHeader);
                         * table.addCell(phrase);
                         *
                         * table.getDefaultCell().setColspan(9);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                         * phrase = new Phrase(" ", pFontHeader);
                         *
                         * table.addCell(phrase);
                         * table.getDefaultCell().setBorder(Rectangle.TOP);
                         *
                         * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                         *
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("1. Original__________ Use
                         * department", pFontHeader);
                         *
                         * table.addCell(phrase);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("2. Duplicate________
                         * Procurement office", pFontHeader);
                         *
                         * table.addCell(phrase);
                         *
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("3. Triplicate_________ Book
                         * copy", 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 (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());

        }
        //            System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize());

        docPdf.close();
        com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

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

    }

}

From source file:com.afrisoftech.hospinventory.mtrhreports.PurchaseReqInternalMtrhPdf1_.java

public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {//from   ww w. ja v a  2 s. c  om

        java.io.File tempFile = java.io.File.createTempFile("REP" + this.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(com.lowagie.text.PageSize.A4,40,40,40,40);

        //   com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4);
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
        try {

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

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

                // System.out.println("Current Doc size 1 "+ pdfWriter.getCurrentDocumentSize());

                String compName = null;
                String date = null;

                try {

                    java.sql.Statement st6 = connectDB.createStatement();
                    java.sql.Statement st4 = connectDB.createStatement();

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

                    //  docPdf.setFooter(footer);
                } catch (java.sql.SQLException SqlExec) {

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

                }

                docPdf.open();

                String Username = null;
                int numColumns = 9;

                try {

                    java.util.Calendar calendar = java.util.Calendar.getInstance();

                    long dateNow = calendar.getTimeInMillis();

                    java.sql.Date datenowSql = new java.sql.Date(dateNow);

                    System.out.println(datenowSql.toString());

                    //  java.lang.Object listofStaffNos[] = this.getListofStaffNos();

                    com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(6);
                    //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

                    // table.endHeaders();

                    int headerwidths[] = { 15, 15, 30, 15, 15, 15 };

                    table1.setWidths(headerwidths);
                    //  if (docPdf.getPageNumber() > 1) {
                    //  table1.setHeaderRows(4);
                    //  }
                    table1.setWidthPercentage((100));

                    table1.getDefaultCell().setBorder(Rectangle.BOTTOM);

                    table1.getDefaultCell().setColspan(7);

                    Phrase phrase = new Phrase();

                    //  table.addCell(phrase);

                    table1.getDefaultCell().setColspan(1);
                    //  table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    //  table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                    try {
                        Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());
                        //Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark"));
                        table1.getDefaultCell().setColspan(10);
                        table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                        table1.getDefaultCell().setFixedHeight(50);
                        table1.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()));
                        table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                        table1.getDefaultCell().setFixedHeight(25);
                        java.sql.Statement st3 = connectDB.createStatement();
                        java.sql.ResultSet rset3 = st3
                                .executeQuery("SELECT DISTINCT hospital_name FROM pb_hospitalprofile");
                        while (rset3.next()) {

                            table1.getDefaultCell().setColspan(6);

                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11);
                            table1.addCell(phrase);
                        }
                    } catch (java.sql.SQLException SqlExec) {

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

                    }
                    docPdf.add(table1);
                } catch (com.lowagie.text.BadElementException BadElExec) {

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

                }

                try {
                    com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(10);
                    table1.getDefaultCell().setPadding(3);

                    int headerwidths1[] = { 24, 10, 8, 8, 6, 8, 6, 10, 12, 8 };

                    //  table1.setWidths(headerwidths1);

                    table1.setWidthPercentage((100));

                    table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                    Phrase phrase = new Phrase("", pFontHeader);

                    try {

                        // java.sql.Statement st3 = conDB.createStatement();

                        //  java.sql.Connection conDb = java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/purchase","postgres","pilsiner");
                        //  java.sql.Statement st3 = conDb.createStatement();
                        java.sql.Statement st3 = connectDB.createStatement();
                        //java.sql.Statement st1 = connectDB.createStatement();
                        java.sql.Statement st2 = connectDB.createStatement();
                        java.sql.Statement st11 = connectDB.createStatement();
                        java.sql.Statement st4 = connectDB.createStatement();
                        java.sql.Statement st5 = connectDB.createStatement();
                        java.sql.Statement st6 = connectDB.createStatement();
                        java.sql.ResultSet rset3 = st3.executeQuery(
                                "select hospital_name,box_no,main_telno||' '||other_telno,initcap(street),initcap(town),main_faxno,email,initcap(building_name),room_no from pb_hospitalprofile");
                        //java.sql.ResultSet rset2 = st2.executeQuery("select supplier_name,short_name,postal_address,tel1,initcap(street),initcap(avenue),fax_no,email_address,initcap(building_name) from st_suppliers WHERE supplier_name  ilike '"+selectSupp+"'");
                        java.sql.ResultSet rset4 = st4.executeQuery(
                                "select DISTINCT REQUISITION_no,date_due,cost_center, case when supplier is null then '-' else supplier end as supplier,"
                                        + " received_requisation,reason,date,store_name,requisation FROM st_receive_requisation where REQUISITION_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        java.sql.ResultSet rset5 = st5.executeQuery(
                                "select DISTINCT date_due from st_receive_requisation where requisition_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        java.sql.ResultSet rset11 = st11.executeQuery(
                                "select initcap(user_name) from st_receive_requisation where requisition_no = '"
                                        + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");
                        while (rset11.next()) {
                            Username = rset11.getObject(1).toString();
                        }
                        table1.getDefaultCell().setBorderColor(java.awt.Color.white);

                        while (rset4.next()) {

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("  ", pFontHeader);
                            //table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("INTERNAL PURCHASE REQUISITION", pFontHeader5);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("FROM TEAM LEADER LOGISTICS-    " + Department + " ",
                                    pFontHeader5);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("TO SUPPLY CHAIN MANAGER", pFontHeader5);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

                            phrase = new Phrase("NUMBER KNH/" + Department + "/  " + OrderNo, pFontHeader5);
                            table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                            phrase = new Phrase("PLEASE ORDER THE FOLLOWING MATERIALS/ITEMS", pFontHeader5);
                            table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);

                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(" ", pFontHeader);
                            //table1.addCell(phrase);

                            table1.getDefaultCell().setColspan(6);

                            phrase = new Phrase("Requisitioning Store : " + rset4.getObject(3).toString(),
                                    pFontHeader);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(4);
                            phrase = new Phrase("DATE: " + rset4.getObject(9).toString(), pFontHeader);
                            table1.addCell(phrase);
                            table1.getDefaultCell().setColspan(10);
                            table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase("Receiving Store : " + rset4.getObject(8).toString(),
                                    pFontHeader);
                            table1.addCell(phrase);

                            //                                table1.getDefaultCell().setColspan(10);
                            //                                phrase = new Phrase("  " + rset4.getObject(2).toString(), pFontHeader);
                            //                                table1.addCell(phrase);

                            /*
                             * table1.getDefaultCell().setColspan(5);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase); phrase = new
                             * Phrase("PROCUREMENT METHOD : ", pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("REQUISITION NO: " +
                             * rset4.getObject(1).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("ACCOUNT NO: ",
                             * pFontHeader); table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase(" ", pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("REASON FOR PURCHASE " +
                             * rset4.getObject(6).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5);
                             *
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("", pFontHeader);
                             * table1.addCell(phrase);
                             *
                             * table1.getDefaultCell().setColspan(5); phrase
                             * = new Phrase("NAME OF THE SUPPLIER " +
                             * rset4.getObject(4).toString(), pFontHeader);
                             * table1.addCell(phrase);
                             * table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                             * phrase = new Phrase("CONTRACT NO: ",
                             * pFontHeader); table1.addCell(phrase);
                             *
                             */

                        }

                        docPdf.add(table1);

                    } 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());

                }

                double Total = 0.00;
                double discount = 0.00;
                double vat = 0.00;
                double qty = 0.00;
                double price = 0.00;
                double value = 0.00;

                try {

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);
                    table.getDefaultCell().setPadding(3);

                    int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

                    com.lowagie.text.pdf.PdfPTable table3 = new com.lowagie.text.pdf.PdfPTable(9);
                    // table3.getDefaultCell().setPadding(3);

                    int headerwidths3[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 };

                    table3.setWidths(headerwidths3);

                    table3.setWidthPercentage((100));
                    //table.getDefaultCell().setBorderColor(java.awt.Color.black);
                    //table.getDefaultCell().setBorder(Rectangle.BOTTOM);
                    table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                    table.getDefaultCell().setColspan(9);
                    Phrase phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table3.getDefaultCell()
                            .setBorder(Rectangle.BOTTOM | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("NOs ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Item No/Code ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(2);

                    phrase = new Phrase("Item Description", pFontHeader);
                    table3.addCell(phrase);
                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Units of Issue. ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Qty Required. ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(1);
                    phrase = new Phrase("Store Balance ", pFontHeader);
                    table3.addCell(phrase);

                    table3.getDefaultCell().setColspan(2);
                    phrase = new Phrase("Monthly Usage", pFontHeader);
                    table3.addCell(phrase);

                    //                        table3.getDefaultCell().setColspan(1);
                    //                        phrase = new Phrase(" ", pFontHeader);
                    //                        table3.addCell(phrase);

                    //                        phrase = new Phrase("Est.Cost ", pFontHeader);
                    //                        table3.addCell(phrase);
                    //
                    //                        phrase = new Phrase("Actual Cost", pFontHeader);
                    //                        table3.addCell(phrase);
                    //
                    //                        phrase = new Phrase("Tender/Qtn Ref.", pFontHeader);
                    //                        table3.addCell(phrase);

                    phrase = new Phrase("", pFontHeader);
                    //table.addCell(phrase);
                    table3.setHeaderRows(1);

                    //                        table3.getDefaultCell().setColspan(1);
                    //
                    //                        table3.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    //  table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                    String coment = "";

                    try {

                        // java.sql.Statement st6 = connectDB.createStatement();
                        java.sql.Statement st1 = connectDB.createStatement();

                        java.sql.ResultSet rset1 = st1
                                .executeQuery("SELECT initcap(item_description),units,cos_glcode,"
                                        + " quantity,price,round(quantity*price,2),mainstore_bal,terms,item_code,monthly_usage from st_receive_requisation"
                                        + " WHERE requisition_no = '" + OrderNo + "'");// where supplier_name = 'Uchumi'member_no = '"+memNo+"'  AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");

                        table.getDefaultCell().setBorderColor(java.awt.Color.lightGray);

                        while (rset1.next()) {

                            // value = qty * price;

                            cnt = cnt + 1;

                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase("" + cnt, pFontHeader2);
                            table3.getDefaultCell().setBorderColor(java.awt.Color.black);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(9).toString(), pFontHeader2);
                            table3.getDefaultCell().setBorderColor(java.awt.Color.black);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(2);
                            table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(1);
                            // JOptionPane.showMessageDialog(null, "this "+rset1.getObject(10).toString());
                            phrase = new Phrase(rset1.getObject(7).toString(), pFontHeader);
                            table3.addCell(phrase);

                            table3.getDefaultCell().setColspan(2);
                            //change
                            phrase = new Phrase(rset1.getObject(10).toString(), pFontHeader2);
                            table3.addCell(phrase);

                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(4).toString()), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getObject(5).toString()), pFontHeader2);
                            //                                table3.addCell(phrase);
                            //
                            //                                // System.out.println("Second "+docPdf.top());
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //                                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)), pFontHeader2);
                            //
                            //                                table3.addCell(phrase);
                            //
                            //
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                            //                                value = value + rset1.getDouble(6);
                            //                                table3.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                            //                                // phrase = new Phrase(rset1.getObject(8).toString(), pFontHeader2);
                            //
                            //                                // table.addCell(phrase);
                            //                                //  coment = rset1.getObject(12).toString();

                        }

                        //                            table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
                        //
                        //                            table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);
                        //                            table.getDefaultCell().setFixedHeight(350);
                        //                            table.addCell(table3);
                        //
                        //                            table.getDefaultCell().setFixedHeight(20);
                        //
                        ////                         
                        //
                        //
                        //                            table.getDefaultCell().setColspan(9);
                        //                            table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT);
                        //                            phrase = new Phrase(" ", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //                            table.getDefaultCell().setBorder(Rectangle.TOP);
                        //                           
                        //                            table.addCell(phrase);
                        //table.getDefaultCell().setBorder(Rectangle.TOP);

                        /*
                         *
                         *
                         * table.getDefaultCell().setColspan(6);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("Prepared By :"
                         * +Username.toUpperCase(), pFontHeader);
                         *
                         * table.addCell(phrase);
                         */

                        //                            table.getDefaultCell().setColspan(3);
                        //                            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("PREPARED BY.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Date.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                          phrase = new Phrase("Time.................................\n", pFontHeader);
                        //                          table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Date.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time.................................\n", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Date.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time.................................\n", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //                            table.getDefaultCell().setColspan(4);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Amount Voted..................................................", pFontHeader);
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(5);
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Vote Balance.........................................................", pFontHeader);
                        //                            table.addCell(phrase);
                        //
                        //
                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Vote Holder's Authority.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Date.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time.................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        // phrase = new Phrase("SIGN..........................................................", pFontHeader);
                        //table.addCell(phrase);

                        table.getDefaultCell().setColspan(9);

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

                        table.addCell(phrase);

                        //phrase = new Phrase("FOR PROCUREMENT USE ONLY", pFontHeader);

                        //table.addCell(phrase);
                        //table.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);

                        //table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                        //                            table.getDefaultCell().setColspan(3);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Approved/Not Approved.....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("ACTION:- I/C Supplies & Proc .....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Procurement Section.....................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            //table.getDefaultCell().setColspan(5);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            phrase = new Phrase("Time............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Stock Ctr/: D/Note.............................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Inv No.......................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Sign....................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(2);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Date.......................................", pFontHeader);
                        //
                        //                            table.addCell(phrase);
                        //
                        //                            table.getDefaultCell().setColspan(1);
                        //
                        //                            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        //                            phrase = new Phrase("Time...........................", pFontHeader);
                        //
                        //                            table.addCell(phrase);

                        /*
                         * table.getDefaultCell().setColspan(5);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new
                         * Phrase("REMARK___________________________________",
                         * pFontHeader);
                         *
                         * table.addCell(phrase);
                         * table.getDefaultCell().setColspan(4);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("DATE
                         * RECEIVED____________________________",
                         * pFontHeader); table.addCell(phrase);
                         *
                         * table.getDefaultCell().setColspan(5);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase(" ", pFontHeader);
                         * table.addCell(phrase);
                         *
                         * table.getDefaultCell().setColspan(9);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                         * phrase = new Phrase(" ", pFontHeader);
                         *
                         * table.addCell(phrase);
                         * table.getDefaultCell().setBorder(Rectangle.TOP);
                         *
                         * table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                         *
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("1. Original__________ Use
                         * department", pFontHeader);
                         *
                         * table.addCell(phrase);
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("2. Duplicate________
                         * Procurement office", pFontHeader);
                         *
                         * table.addCell(phrase);
                         *
                         *
                         * table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                         * phrase = new Phrase("3. Triplicate_________ Book
                         * copy", 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());

                }

                try {

                    Phrase phrase = new Phrase();

                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);
                    table.getDefaultCell().setPadding(3);

                    int headerwidths[] = { 8, 30, 14, 14, 14, 14, 14, 16, 15 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

                    table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                    table.getDefaultCell()
                            .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);
                    table.getDefaultCell().setFixedHeight(350);
                    table.addCell(table);

                    table.getDefaultCell().setFixedHeight(20);

                    //                         

                    table.getDefaultCell().setColspan(9);
                    table.getDefaultCell()
                            .setBorder(Rectangle.TOP | Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.LEFT);
                    phrase = new Phrase(" ", pFontHeader);

                    table.addCell(phrase);
                    table.getDefaultCell().setBorder(Rectangle.TOP);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("PREPARED BY.................................", pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Sign.................................", pFontHeader);

                    table.addCell(phrase);

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

                    table.addCell(phrase);

                    phrase = new Phrase("Time.................................\n", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(3);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("AIE HOLDER/USER.................................", pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Sign.................................", pFontHeader);

                    table.addCell(phrase);

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

                    table.addCell(phrase);

                    phrase = new Phrase("Time.................................\n", pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(3);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("APPROVED BY(TL LOGISTICS).................................",
                            pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Sign.................................", pFontHeader);

                    table.addCell(phrase);

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

                    table.addCell(phrase);

                    phrase = new Phrase("Time.................................\n", pFontHeader);

                    table.addCell(phrase);

                    //down

                    docPdf.add(table);

                } 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 (com.lowagie.text.DocumentException lwDocexec) {

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

        }
        //            System.out.println("Current Doc size "+ pdfWriter.getCurrentDocumentSize());

        docPdf.close();
        com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

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

    }

}

From source file:com.afrisoftech.reports.PatientRegFormPdf.java

public void generatePdf(String patientName, String patientAge, String PatientGender, String patientNationality,
        String patientIDPassport, String placeofBirth, String patientOccupation, String maritalStatus,
        String patientReligion, String patientTelephone, String patientEmail, String patientVillage,
        String patientLocation, String patientHomeCounty, String patientResidenceCounty, String patientNOK,
        String patientRelation, String patientNOKTelephone, String patientReferFrom, String bookingDate,
        String specialtyClinic, String statusNHIF, String NHIFNumber, String educationLevel,
        String employerTelephone, String patientEmployer, String paidAmount, String receiptNumber,
        String cSheetNo, String invoiceNumber, String interviewerName, String interviewDate,
        String servicePoint, String unitNumber, String patientNumber, String admissionWard,
        String admissionDate, String admissionType, String claimNumber, java.util.Date date, String gender,
        String typeofAccident, String modeofArrival, String nameofPoliceOfficer, String policeForceNO,
        String policeStationAccident, String dateAccident, String nameofDriver, String accidentVehicleNo,
        String driverLicenceNo, String driversIDNo, String registrationTimes) {

    java.util.Date date111 = date;
    java.lang.String formLabel = null;

    if (admissionWard.toCharArray().length < 1) {

        formLabel = "PATIENT REGISTRATION FORM";

    } else {/* www  . j a va 2s .  c o m*/
        formLabel = "PATIENT ADMISSION FORM";
    }

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

        java.io.File tempFile = java.io.File.createTempFile("REP" + this.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();
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

        try {

            try {

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

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase(formLabel + " : ", pFontHeader2), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                java.util.Calendar calendar = java.util.Calendar.getInstance();

                long dateNow = calendar.getTimeInMillis();

                java.sql.Date datenowSql = new java.sql.Date(dateNow);

                System.out.println(datenowSql.toString());

                try {
                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

                    int headerwidths[] = { 16, 16, 16, 16, 16, 16 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

                    com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2);

                    int headerwidths2[] = { 30, 70 };

                    table2.setWidths(headerwidths2);

                    table2.setWidthPercentage((100));

                    table2.getDefaultCell().setFixedHeight(50);
                    //phrase = new Phrase("", pFontHeader1);

                    //table.addCell(phrase);
                    table2.getDefaultCell().setColspan(2);
                    table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());
                    img.scalePercent(50);
                    // img.sc//aleAbsolute(200, 200);
                    table2.addCell(img);
                    String compName = null;
                    String District = null;
                    String Region = null;
                    String date2 = null;
                    try {
                        java.sql.Statement st3 = connectDB.createStatement();

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

                        java.sql.ResultSet rset2 = st3.executeQuery(
                                "SELECT hospital_name,district_branch,region FROM pb_hospitalprofile");
                        java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                        while (rset2.next()) {
                            compName = dbObject.getDBObject(rset2.getObject(1), "");
                            District = dbObject.getDBObject(rset2.getObject(2), "");
                            Region = dbObject.getDBObject(rset2.getObject(3), "");
                        }
                        while (rset4.next()) {
                            date2 = dbObject.getDBObject(rset4.getObject(1), "");
                        }
                    } catch (java.sql.SQLException ex) {
                        javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage());
                        ex.printStackTrace();
                    }
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    // table.getDefaultCell().set
                    Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3);
                    table2.addCell(phrase);

                    table.addCell(table2); // painting the logo

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

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

                    table.getDefaultCell().setColspan(5);

                    phrase = new Phrase(formLabel, pFontHeader2);

                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    table.getDefaultCell().setColspan(1);
                    phrase = new Phrase("FORM: 260", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    // table.getDefaultCell().set
                    phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    dbObject = new com.afrisoftech.lib.DBObject();

                    phrase = new Phrase("Patient Name: " + patientName, pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, "") + "",
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Registration Time : " + dbObject.getDBObject(registrationTimes, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Residence: " + dbObject.getDBObject(patientLocation, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(
                            "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("3. NEXT OF KIN", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("4. CURRENT ATTENDANCE AT FACILITY", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Appointment Date: " + dbObject.getDBObject(date111, ""),
                            pFontHeadercolor);
                    table.addCell(phrase);
                    phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(4);
                    phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    // table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""),
                            pFontHeadercolor);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

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

                    ///RTA DETAILS
                    if (typeofAccident.length() > 0 || modeofArrival.length() > 0
                            || nameofPoliceOfficer.length() > 0 || policeForceNO.length() > 0
                            || policeStationAccident.length() > 0 || dateAccident.length() > 0
                            || nameofDriver.length() > 0 || accidentVehicleNo.length() > 0
                            || driverLicenceNo.length() > 0 || driversIDNo.length() > 0) {

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase("RTA DETAILS : ", pFontHeader2);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + ""
                                        + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "")
                                        + "." + "" + dbObject
                                                .getDBObject(" Police Officer Force No:-" + policeForceNO, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject(
                                        "Police Station Accident Scene :- " + policeStationAccident, "") + ". "
                                        + dbObject.getDBObject("Accident Date:-" + dateAccident, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject
                                        .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "")
                                        + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                    }

                    ///RTA END
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(" ", pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setBorder(PdfCell.RECTANGLE);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(" Patient Number : ".toUpperCase()
                            + dbObject.getDBObject(patientNumber, "").toUpperCase(), pFontHeader3);
                    table.addCell(phrase);
                    //   phrase = new Phrase(" ", pFontHeader);
                    //   table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(
                            "Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, "").toUpperCase(),
                            pFontHeader2);

                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile));
                    PdfContentByte cb = writer.getDirectContent();

                    Barcode128 code128 = new Barcode128();

                    code128.setCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase());

                    code128.setBarHeight(16);

                    code128.setTextAlignment(Element.ALIGN_LEFT);

                    docPdf.add(table);

                    docPdf.add(code128.createImageWithBarcode(cb, null, null));

                    //                        docPdf.add(new com.itextpdf.text.Paragraph("Barcode QRCode"));
                    //                        BarcodeQRCode qrcode = new BarcodeQRCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase(), 1, 1, null);
                    //                        com.itextpdf.text.Image qrimg = qrcode.getImage();
                    //                        docPdf.add(qrimg);
                    //  docPdf.add(table);
                } 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 (com.lowagie.text.DocumentException lwDocexec) {

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

        }

        docPdf.close();

        com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

        IOexec.printStackTrace();

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

    }
}

From source file:com.afrisoftech.reports.PatientRegReprintFormPdf.java

public void generatePdf(java.sql.Connection con, String patientNo, String type, String receipt_no,
        String receipt_time) {//from w ww  .j ava2 s .  c  o m

    String patientName = null;
    String patientAge = null;
    String PatientGender = null;
    String patientNationality = null;
    String patientIDPassport = null;
    String placeofBirth = null;
    String patientOccupation = null;
    String maritalStatus = null;
    String patientReligion = null;
    String patientTelephone = null;
    String patientEmail = null;
    String patientVillage = null;
    String patientLocation = null;
    String patientHomeCounty = null;
    String patientResidenceCounty = null;
    String patientNOK = null;
    String patientRelation = null;
    String patientNOKTelephone = null;
    String patientReferFrom = null;
    String bookingDate = null;
    String specialtyClinic = null;
    String statusNHIF = null;
    String NHIFNumber = null;
    String educationLevel = null;
    String employerTelephone = null;
    String patientEmployer = null;
    String paidAmount = null;
    String receiptNumber = null;
    String cSheetNo = null;
    String invoiceNumber = null;
    String interviewerName = null;
    String interviewDate = null;
    String servicePoint = null;
    String unitNumber = null;
    String patientNumber = null;
    String admissionWard = null;
    String admissionDate = null;
    String admissionType = null;
    String claimNumber = null;
    java.util.Date date = null;
    String gender = null;
    String typeofAccident = null;
    String modeofArrival = null;
    String nameofPoliceOfficer = null;
    String policeForceNO = null;
    String policeStationAccident = null;
    String dateAccident = null;
    String nameofDriver = null;
    String accidentVehicleNo = null;
    String driverLicenceNo = null;
    String driversIDNo = null;
    String patNo = null;
    patNo = patientNo;
    try {

        //            java.sql.ResultSet rse124 = stm124.executeQuery("SELECT first_name, second_name, nok, residence, \n" +
        //"       address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, \n" +
        //"       description, category, expiry_date, last_visit, department, member_name, \n" +
        //"       card_no, emails, id_no, nok_add, old_patient_no, pat_nationality, \n" +
        //"       nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status, \n" +
        //"       tribe, district, locations, sub_location, chief_name, sub_chief, \n" +
        //"       information_source, education_level, occupation, pat_religion, \n" +
        //"       patient_race, birth_place, waiting_patient, email, home_county, \n" +
        //"       residence_county, nhif_status, nhif_number, employer_name, employer_telephone, \n" +
        //"       refer_source, charge_sheet_no, specialty_clinic\n" +
        //"  FROM hp_patient_register; where patient_no='"+patNo+"' ");
        if (type.equals("OP")) {

            java.sql.Statement stm12456 = con.createStatement();
            java.sql.ResultSet rse124 = stm12456
                    .executeQuery("SELECT   hp.patient_no, first_name, second_name, last_name, nok, residence,"
                            + " address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, "
                            + " description, category, expiry_date, last_visit, department, member_name,"
                            + " card_no, emails, id_no, nok_add, old_patient_no, pat_nationality,"
                            + " nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status,"
                            + " tribe, district, locations, sub_location, chief_name, sub_chief,"
                            + " information_source, education_level, occupation, pat_religion,"
                            + " patient_race, birth_place, waiting_patient, email, home_county,"
                            + " residence_county, nhif_status, nhif_number, employer_name, employer_telephone,"
                            + " refer_source, charge_sheet_no, specialty_clinic, accident_type, arrival_mode, police_officer_no, police_station,date_time, driver_name, accident_vehicle_no, driver_license, driver_id_no,service_point,user_name FROM  hp_patient_register hp LEFT JOIN rta_info rt  on hp.patient_no=rt.patient_no WHERE hp.patient_no='"
                            + patNo + "' ORDER BY date_time desc  limit 1 ");
            while (rse124.next()) {

                patientName = rse124.getString(2).toUpperCase() + " " + rse124.getString(3).toUpperCase();
                patientAge = PatientAge.getPatientActualAge(con,
                        com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("year_of_birth")));
                PatientGender = rse124.getString("sex");
                patientNationality = rse124.getString("pat_nationality");
                patientIDPassport = rse124.getString("id_no");
                placeofBirth = rse124.getString("birth_place");
                patientOccupation = rse124.getString("occupation");
                maritalStatus = rse124.getString("pat_marital_status");
                patientReligion = rse124.getString("pat_religion");
                patientTelephone = rse124.getString("tel_no");
                patientEmail = rse124.getString("emails");
                patientVillage = rse124.getString("residence");
                patientLocation = rse124.getString("locations");
                patientHomeCounty = rse124.getString("home_county");
                patientResidenceCounty = rse124.getString("residence_county");
                patientNOK = rse124.getString("nok");
                patientRelation = rse124.getString("nok_relationship");
                //jddfsjdsj
                patientNOKTelephone = rse124.getString("nok_telno");
                patientReferFrom = rse124.getString("refer_source");
                bookingDate = rse124.getString("date");
                specialtyClinic = rse124.getString("specialty_clinic");
                statusNHIF = rse124.getString("nhif_status");
                NHIFNumber = rse124.getString("nhif_number");
                educationLevel = rse124.getString("education_level");
                employerTelephone = rse124.getString("employer_telephone");
                patientEmployer = rse124.getString("employer_name");
                paidAmount = "";
                receiptNumber = "";
                cSheetNo = rse124.getString("charge_sheet_no");
                invoiceNumber = "";
                interviewerName = rse124.getString("user_name");
                interviewDate = rse124.getString("date");
                servicePoint = rse124.getString("service_point");
                unitNumber = rse124.getString("patient_race");
                patientNumber = rse124.getString("patient_no");
                admissionWard = "";
                admissionDate = "";
                admissionType = "";
                claimNumber = "";
                date = com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("date"));
                gender = rse124.getString("sex");
                typeofAccident = rse124.getString("accident_type");
                modeofArrival = rse124.getString("arrival_mode");
                nameofPoliceOfficer = rse124.getString("police_officer_no");
                policeForceNO = rse124.getString("police_officer_no");
                policeStationAccident = rse124.getString("police_station");
                dateAccident = rse124.getString("date_time");
                nameofDriver = rse124.getString("driver_name");
                accidentVehicleNo = rse124.getString("accident_vehicle_no");
                driverLicenceNo = rse124.getString("driver_license");
                driversIDNo = rse124.getString("driver_id_no");
                System.out.println("");

            }

            ///getting the receipt details
            try {
                java.sql.Statement stmt11 = connectDB.createStatement();
                //java.sql.ResultSet rset11 = stmt11.executeQuery("SELECT  description,receipt_no, debit  FROM ac_cash_collection where  patient_no='" + patientNumberTxt.getText() + "' and receipt_time::date >= current_date-1 ");
                java.sql.ResultSet rset11 = stmt11.executeQuery(
                        "SELECT  description,receipt_no, debit  FROM ac_cash_collection where  patient_no='"
                                + patNo + "'   and receipt_no='" + receipt_no + "' and receipt_time::date='"
                                + receipt_time + "'::date ");
                while (rset11.next()) {
                    receiptNumber = rset11.getObject(2).toString();
                    paidAmount = rset11.getObject(3).toString();

                    System.out.println("This is the receipt no " + receiptNumber + " and this is the AMOUNT "
                            + paidAmount);
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                ex.getMessage();
            }

            ///end
        } else if (type.equals("IP")) {
        }

    } catch (java.sql.SQLException sq) {
        javax.swing.JOptionPane.showMessageDialog(null, sq.getMessage(), "Error Message!",
                javax.swing.JOptionPane.ERROR_MESSAGE);

        System.out.println(sq.getMessage());
    }

    java.util.Date date111 = date;
    java.lang.String formLabel = null;

    //        if(admissionWard.toCharArray().length < 1){
    //            
    //            formLabel = "PATIENT REGISTRATION FORM";
    //            
    //        } else {
    //            formLabel = "PATIENT ADMISSION FORM";
    //        }
    if (type.equals("OP")) {

        formLabel = "PATIENT REGISTRATION FORM";

    } else {
        formLabel = "PATIENT ADMISSION FORM";
    }

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

        java.io.File tempFile = java.io.File.createTempFile("REP" + this.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();
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

        try {

            try {

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

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(
                        new Phrase(formLabel + " : ", pFontHeader2), true);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12, Font.BOLDITALIC,java.awt.Color.blue));

                docPdf.setFooter(footer);

                docPdf.open();

                java.util.Calendar calendar = java.util.Calendar.getInstance();

                long dateNow = calendar.getTimeInMillis();

                java.sql.Date datenowSql = new java.sql.Date(dateNow);

                System.out.println(datenowSql.toString());

                try {
                    com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

                    int headerwidths[] = { 16, 16, 16, 16, 16, 16 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

                    com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2);

                    int headerwidths2[] = { 30, 70 };

                    table2.setWidths(headerwidths2);

                    table2.setWidthPercentage((100));

                    table2.getDefaultCell().setFixedHeight(50);
                    //phrase = new Phrase("", pFontHeader1);

                    //table.addCell(phrase);
                    table2.getDefaultCell().setColspan(2);
                    table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());
                    img.scalePercent(50);
                    // img.sc//aleAbsolute(200, 200);
                    table2.addCell(img);
                    String compName = null;
                    String District = null;
                    String Region = null;
                    String date2 = null;
                    try {
                        java.sql.Statement st3 = connectDB.createStatement();

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

                        java.sql.ResultSet rset2 = st3.executeQuery(
                                "SELECT hospital_name,district_branch,region FROM pb_hospitalprofile");
                        java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                        while (rset2.next()) {
                            compName = rset2.getObject(1).toString();
                            District = rset2.getObject(2).toString();
                            Region = rset2.getObject(3).toString();
                        }
                        while (rset4.next()) {
                            date2 = rset4.getObject(1).toString();
                        }
                    } catch (java.sql.SQLException ex) {
                        javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage());
                        ex.printStackTrace();
                    }
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    // table.getDefaultCell().set
                    Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3);
                    table2.addCell(phrase);

                    table.addCell(table2); // painting the logo

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

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

                    table.getDefaultCell().setColspan(5);

                    phrase = new Phrase(formLabel, pFontHeader2);

                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    table.getDefaultCell().setColspan(1);
                    phrase = new Phrase("FORM: 260", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    // table.getDefaultCell().set
                    phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    dbObject = new com.afrisoftech.lib.DBObject();

                    phrase = new Phrase("Patient Name: " + patientName, pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Home Location: " + dbObject.getDBObject(patientLocation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(
                            "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("3. NEXT OF KIN", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("4. CURRENT ATTENDANCE AT KNH", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Appointment Dates: " + dbObject.getDBObject(date111, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    if (statusNHIF != null) {
                        if (statusNHIF.contains("f")) {
                            statusNHIF = "NO";
                        } else {
                            statusNHIF = "YES";
                        }
                    } else {
                        statusNHIF = "NO";
                    }

                    phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(4);
                    phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    // table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""),
                            pFontHeader2);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

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

                    ///RTA DETAILS
                    //                            if(typeofAccident.length()>0 || modeofArrival.length()>0 ||
                    //                                    nameofPoliceOfficer.length()>0 || policeForceNO.length()>0 ||
                    //                                    policeStationAccident.length()>0 ||  dateAccident.length()>0 ||
                    //                                    nameofDriver.length()>0 || accidentVehicleNo.length()>0 ||
                    //                                    driverLicenceNo.length()>0 || driversIDNo.length()>0 ){
                    if (typeofAccident != null || modeofArrival != null || nameofPoliceOfficer != null
                            || policeForceNO != null || policeStationAccident != null || dateAccident != null
                            || nameofDriver != null || accidentVehicleNo != null || driverLicenceNo != null
                            || driversIDNo != null) {

                        table.getDefaultCell().setColspan(3);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase("RTA DETAILS : ", pFontHeader2);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(3);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(dbObject.getDBObject("Accident Date:-" + dateAccident, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + ""
                                        + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "")
                                        + "." + "" + dbObject
                                                .getDBObject(" Police Officer Force No:-" + policeForceNO, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject(
                                        "Police Station Accident Scene :- " + policeStationAccident, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject
                                        .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "")
                                        + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                    }

                    ///RTA END

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(" ", pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setBorder(PdfCell.RECTANGLE);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(
                            " Patient Number : ".toUpperCase() + dbObject.getDBObject(patNo.toUpperCase(), ""),
                            pFontHeader2);
                    table.addCell(phrase);
                    //   phrase = new Phrase(" ", pFontHeader);
                    //   table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, ""),
                            pFontHeader3);

                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile));
                    PdfContentByte cb = writer.getDirectContent();

                    Barcode128 code128 = new Barcode128();

                    System.out.println("PATIENT NO " + patNo + " NAME " + patientName);
                    code128.setCode(patNo + " " + patientName);

                    code128.setBarHeight(16);

                    code128.setTextAlignment(Element.ALIGN_LEFT);

                    docPdf.add(table);

                    docPdf.add(code128.createImageWithBarcode(cb, null, null));

                    //  docPdf.add(table);

                } 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 (com.lowagie.text.DocumentException lwDocexec) {

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

        }

        docPdf.close();

        com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

        IOexec.printStackTrace();

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

    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createPdfReport_hardware(String filename) {
    try {//from   w  w w  . ja v  a2 s  . c o  m
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        fileName = filename;
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
        Paragraph title = new Paragraph("", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;
        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Phrase("\n"));
        Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
        PdfPTable aTable = new PdfPTable(4);
        float[] widths = { 100f, 100f, 300f, 100f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        aTable.addCell(new Phrase("", contextFont));
        aTable.addCell(new Phrase("", contextFont));
        aTable.addCell(new Phrase("", contextFont));
        aTable.addCell(new Phrase("", contextFont));
        Vector deviceV = (Vector) reportHash.get("deviceV");
        for (int m = 0; m < deviceV.size(); m++) {
            Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m);
            String name = devicedata.getName();
            String type = devicedata.getType();
            String status = devicedata.getStatus();
            aTable.addCell(new Phrase(m + 1 + "", contextFont));
            aTable.addCell(new Phrase(type, contextFont));
            aTable.addCell(new Phrase(name, contextFont));
            aTable.addCell(new Phrase(status, contextFont));
        }
        /*
         * Image img =
         * Image.getInstance(ResourceCenter.getInstance().getSysPath() +
         * "/resource/image/jfreechart/" + newip + "ConnectUtilization" +
         * ".png");
         * 
         * img.setAlignment(Image.LEFT);//  img.scalePercent(75);
         * document.add(aTable); document.add(img);
         */
        document.add(aTable);
        document.close();
    } catch (Exception e) {
        SysLogger.error("", e);
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReportusa_oraPDF(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/*from  w w  w. j av  a 2  s . co m*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        Font contextFont1 = new Font(bfChinese, 11, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        Hashtable maxping = (Hashtable) reportHash.get("ping");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;
        Paragraph context = new Paragraph(contextString, contextFont1);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        PdfPTable aTable = new PdfPTable(4);
        float[] widths = { 220f, 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase(""));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        // cell = new PdfPCell(new Phrase((String) maxping.get("pingmax")));
        cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));// HONGLI
        // MODIFY
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        // cell = new PdfPCell(new Phrase((String) maxping.get("ping")));
        cell = new PdfPCell(new Phrase((String) maxping.get("pingmin")));// HONGLI
        // MODIFY
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.MIDDLE);// 
        img.scalePercent(76);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));
        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 
            document.add(img1);
        }
        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }
}