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

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

Introduction

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

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:be.fedict.eid.applet.service.impl.PdfGenerator.java

License:Open Source License

public byte[] generatePdf(EIdData eIdData) throws DocumentException {
    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);

    document.open();/* w ww. j  ava2s .  c  o m*/

    Paragraph titleParagraph = new Paragraph("eID Identity Data");
    titleParagraph.setAlignment(Paragraph.ALIGN_CENTER);

    Font titleFont = titleParagraph.getFont();
    titleFont.setSize((float) 20.0);
    titleFont.setStyle(Font.BOLD);
    titleParagraph.setSpacingAfter(20);
    document.add(titleParagraph);

    if (null != eIdData && null != eIdData.getIdentity()) {
        if (null != eIdData.getPhoto()) {
            try {
                Image image = createImageFromPhoto(eIdData.getPhoto());
                document.add(image);
            } catch (Exception e) {
                LOG.error("Error getting photo: " + e.getMessage());
            }

            Identity identity = eIdData.getIdentity();

            // metadata
            setDocumentMetadata(document, identity.firstName, identity.name);
            writer.createXmpMetadata();

            // create a table with the data of the eID card
            PdfPTable table = new PdfPTable(2);
            table.getDefaultCell().setBorder(0);

            table.addCell("Name");
            table.addCell(identity.name);

            table.addCell("First name");
            String firstName = identity.firstName;
            if (null != identity.middleName) {
                firstName += " " + identity.middleName;
            }
            table.addCell(firstName);

            table.addCell("Nationality");
            table.addCell(identity.nationality);

            table.addCell("National Registration Number");
            table.addCell(identity.nationalNumber);

            table.addCell("Gender");
            table.addCell(identity.gender.toString());

            table.addCell("Date of birth");
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            table.addCell(formatter.format(identity.dateOfBirth.getTime()));

            table.addCell("Place of birth");
            table.addCell(identity.placeOfBirth);

            if (null != eIdData.getAddress()) {
                Address address = eIdData.getAddress();
                table.addCell("Address");
                PdfPCell cell = new PdfPCell();
                cell.setBorder(0);
                cell.addElement(new Paragraph(address.streetAndNumber));
                cell.addElement(new Paragraph(address.zip + " " + address.municipality));
                table.addCell(cell);
            }

            document.add(table);

            // TODO: to be tested
            /*
            try {
                Image barcodeImage =
                    createBarcodeImage(identity.nationalNumber, identity.cardNumber);
                    
                barcodeImage.setAlignment(Element.ALIGN_CENTER);
                Paragraph barcodePara = new Paragraph();
                barcodePara.add(barcodeImage);
                    
                document.add(barcodeImage);
            } catch (Exception e) {
                LOG.error("Error adding barcode: " + e.getMessage());
            }
            */
        } else {
            document.add(new Paragraph("No eID identity data available."));
        }
    }
    document.close();
    return baos.toByteArray();
}

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

protected PdfPTable createInfoTable() {
    final float alpha = 0.22f;
    final PdfPTable t = new PdfPTable(new float[] { alpha, 1.0f - alpha });
    t.getDefaultCell().setBorder(BORDER);
    t.setWidthPercentage(101f);// w w  w .  j  ava 2 s .  c  o  m
    return t;
}

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1//from  w w  w. java 2  s  .  co m
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:br.com.moises.servlet.Embarque.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    out.print("Pasou auqe");

    try {//from  w w w .  ja  va2  s.  c om
        Document document = new Document(PageSize.A4, 30, 20, 20, 30);
        OutputStream outputStream = new FileOutputStream("embarque.pdf");
        //   response.setContentType("application/pdf");
        Long id = Long.parseLong(request.getParameter("num_embarque"));
        //recupera o embarque
        embarque = embarqueSuport.getEmbarqueById(id);
        itens = itSuport.itensEmbarquePorEmbarque(embarque);
        out.print(itens.size());

        PdfWriter.getInstance(document, response.getOutputStream());

        document.open();
        // Titulo

        document.addTitle("Comprovante de Coleta");

        Paragraph titulo = new Paragraph("Comprovante de Coleta");
        //            //
        document.add(titulo);
        document.add(new Paragraph("\n\n"));
        PdfPTable topo = new PdfPTable(2);
        Image image = Image.getInstance("E:\\icons\\32\\cliente.png");

        topo.getDefaultCell().setBorder(0);
        topo.getDefaultCell().addElement(image);
        topo.addCell(image);
        topo.addCell("MOISES JUVENAL DA SILVA\n" + "Rua.: Bertioga N 49" + "Jardim Amrica I"
                + "Vrzea Paulista SP");

        document.add(topo);
        document.add(new Paragraph(
                "-------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(
                "TRANSP.: " + embarque.getTransportadora().getId() + " - "
                        + embarque.getTransportadora().getNome(),
                FontFactory.getFont(FontFactory.HELVETICA, 14, Color.BLUE)));
        document.add(new Paragraph(
                "-------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(new Date().toString()));

        PdfPTable table = new PdfPTable(2);
        table.addCell("");

        for (ItensEmbarque l : itens) {
            document.add(new Paragraph(String.valueOf(l.getId())));
        }
        // step 5
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:bucks.AuditSheet.java

License:Open Source License

void generateSheet(HttpServletResponse res, List<Batch> batches) {

    ////from w  w  w . ja v  a 2 s.  c o m
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String spacer = "   \n";
    ServletOutputStream out = null;
    String filename = "marketbucks_audit_sheet.pdf";
    try {
        // space
        //         
        Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
        Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35         
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        URL imgUrl = new URL(imageUrl);
        Image image = Image.getInstance(imgUrl);
        image.scalePercent(20f);
        // image.scaleAbsolute(100f, 100f);// width, height
        // image.setRotation(3.1f); // in radians
        // image.setRotationDegrees(90f); // degrees
        // image.setSpacingBefore(10f);
        // image.setSpacingAfter(10f);
        // image.setWidthPercentage(25.0f);
        Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);
        Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);
        Phrase spacePhrase = new Phrase();
        Chunk ch = new Chunk(spacer, fnt);
        spacePhrase.add(ch);

        float[] widths = { 25f, 75f }; // percentages
        PdfPTable headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        headTable.addCell(cell);

        Phrase phrase = new Phrase();
        ch = new Chunk("Printed Market Bucks Audit Sheet\n ", fntb2);
        phrase.add(ch);
        Paragraph pp = new Paragraph();
        pp.setIndentationLeft(20);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.add(phrase);
        cell = new PdfPCell(pp);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headTable.addCell(cell);
        document.add(headTable);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        float[] widths3 = { 50f, 50f }; // percentages
        PdfPTable table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        phrase = new Phrase();
        ch = new Chunk(" Date: ", fntb);
        phrase.add(ch);
        ch = new Chunk(Helper.getToday() + "\n\n\n", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        // 
        phrase = new Phrase();
        ch = new Chunk(" ", fntb); // empty cell
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //         
        document.add(table);
        //
        phrase = new Phrase(new Chunk("\n", fnt));
        document.add(phrase);
        //
        float[] widths2 = { 15f, 10f, 15f, 15f, 15f, 15f, 15f }; // percentages
        table = new PdfPTable(widths2);
        table.setWidthPercentage(90);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        // table.getDefaultCell().setPadding(5);
        phrase = new Phrase();
        ch = new Chunk("Count of MB/GC", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Value", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Total Dollars", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Printed By", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Start Number", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("End Number", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("Printed Date", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        // next rows
        //
        for (Batch one : batches) {
            phrase = new Phrase();
            ch = new Chunk(one.getBatch_size(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk("$" + one.getValue() + ".00", fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
            //
            phrase = new Phrase();
            ch = new Chunk(moneyFormat.format(one.getTotal()), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
            //
            phrase = new Phrase();
            ch = new Chunk(one.getUser().toString(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getStart_seq(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getEnd_seq(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);

            phrase = new Phrase();
            ch = new Chunk(one.getDate(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setBorderWidth(1f);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setPadding(4);
            cell.setLeading(2f, 1.2f);
            table.addCell(cell);
        }
        document.add(table);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        ch = new Chunk("Audit By:____________________________________________________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        ch = new Chunk("           :_______________________________________)_____________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        ch = new Chunk("           :_____________________________________________________________________\n\n",
                fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        //
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        res.setHeader("Content-Disposition", " attachment; filename=" + filename);
        res.setContentType("application/pdf");
        //
        // the contentlength is needed for MSIE!!!
        res.setContentLength(baos.size());
        //
        out = res.getOutputStream();
        if (out != null) {
            baos.writeTo(out);
        }
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_mb(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {/*from   ww  w .j a va  2s  .  c  o  m*/
        float[] widths = { 15f, 40f, 45f }; // percentages         
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        // cell.setFixedHeight(46f);
        table.addCell(cell);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("FARMERS' MARKET BUCKS\n", fntb2);
        phrase.add(ch);
        ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Issue Date___________ ", fnt10);
        phrase.add(ch);
        ch = new Chunk("No. " + seq, fnt10);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        // document.add(table);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is good for ", fnt);
        phrase.add(ch);
        ch = new Chunk("$" + value + ".00 ", fntb2);
        phrase.add(ch);
        ch = new Chunk("towards the purchase of ", fnt);
        phrase.add(ch);
        ch = new Chunk("eligible food items ", fntb);
        phrase.add(ch);
        ch = new Chunk("at the Bloomington Community Farmers' Market. ", fnt);
        phrase.add(ch);
        ch = new Chunk("No change allowed. \n", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(48f);
        cell.setColspan(3);
        table.addCell(cell);

        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //table.getDefaultCell().setPadding(0);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        //
        phrase = new Phrase();
        ch = new Chunk(
                "Customers shall redeem this certificate at Farmers' Market\nby December 1st of the year issued.",
                fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

        cell.setColspan(2);
        cell.setFixedHeight(81f);
        table.addCell(cell);
        //
        Barcode barcode = BarcodeFactory.createCode39("" + seq, false);
        // barcode text has problem, so we turned off
        // and decided to add it ourselves.
        barcode.setDrawingText(false);
        // barcode.setFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 16));
        // barcode.setLabel(""+seq);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        /*
        int width = bi.getWidth();
        int height = bi.getHeight();
        Graphics2D g2 = bi.createGraphics();
        g2.setColor(Color.BLACK);
        g2.drawString(""+seq, 60, 70);
        g2.dispose();
        */
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        // added this hack to get rid of underline in the barcode
        // this worked on windows, but the text did not show up on linux
        // that is why we decided to abandon the text all the way
        // and add it ourselves
        /*
        BarcodeImageHandler.writePNG(barcode, baos);
        File bcImg = File.createTempFile("bc-", ".png");
        bcImg.deleteOnExit();
        byte[] imageBytes = baos.toByteArray();
        FileOutputStream fos = new FileOutputStream(bcImg);
        BarcodeImageHandler.writePNG(barcode, fos);
        */
        //
        // old
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90f);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        // float widthf = barCodeImage.getWidth();
        // float heightf = barCodeImage.getHeight();

        cell = new PdfPCell(barCodeImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        // cell.setFixedHeight(81f);
        table.addCell(cell);
        //
        // the barcode text that we added underneath the barcode
        //
        int textWidth = 53, textHeight = 50;
        BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = bi2.createGraphics();
        g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, textWidth, textHeight);
        g.setColor(Color.BLACK);
        g.drawString("" + seq, 5, 10);

        g.dispose();
        baos = new ByteArrayOutputStream();
        ImageIO.write(bi2, "png", baos);
        imageBytes = baos.toByteArray();
        Image barCodeTextImage = Image.getInstance(imageBytes);

        barCodeTextImage.setRotationDegrees(90f);
        cell = new PdfPCell(barCodeTextImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(34f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths4 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths4);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        phrase = new Phrase();
        ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        cell.setFixedHeight(40f); // 40
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(
                "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR ISSUED\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        document.add(table);
    } catch (Exception ex) {
        System.err.println(ex);
    }

}

From source file:bucks.GenerateChecks.java

License:Open Source License

void generate_gc(Document document, int seq, String value, Image image, PdfWriter writer) {
    try {/*from   www. j  a v  a 2s. com*/
        float[] widths = { 13f, 54f, 33f }; // percents
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.setSpacingAfter(0f);
        table.setSpacingBefore(0f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(46f);
        table.addCell(cell);
        Phrase phrase = new Phrase();
        Chunk ch = new Chunk("FARMERS' MARKET GIFT CERTIFICATE\n", fntb2);
        phrase.add(ch);
        ch = new Chunk("Parks & Recreation\nBloomington, IN", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Issue Date__________ ", fnt10);
        phrase.add(ch);
        ch = new Chunk("No. " + seq, fnt10);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is good for ", fnt);
        phrase.add(ch);
        ch = new Chunk("$" + value + ".00 ", fntb2);
        phrase.add(ch);
        ch = new Chunk("towards the purchase of ", fnt);
        phrase.add(ch);
        ch = new Chunk("products from ", fnt);
        phrase.add(ch);
        ch = new Chunk("the Bloomington Community Farmers' Market and A Fair of The Arts Vendors. ", fnt);
        phrase.add(ch);
        ch = new Chunk("Change may be given. \n", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        cell.setFixedHeight(48f);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths2 = { 60f, 25f, 10f, 5f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.setSpacingAfter(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        //
        phrase = new Phrase();
        ch = new Chunk("Customers shall redeem this certificate at Market\nwithin one year of date issued. ",
                fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setColspan(2);

        cell.setFixedHeight(81f);
        table.addCell(cell);

        Barcode barcode = BarcodeFactory.createCode39("" + seq, true);
        barcode.setDrawingText(false);
        BufferedImage bi = BarcodeImageHandler.getImage(barcode);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        //
        ImageIO.write(bi, "png", baos);
        byte[] imageBytes = baos.toByteArray();
        //
        Image barCodeImage = Image.getInstance(imageBytes);

        barCodeImage.setRotationDegrees(90);
        // barCodeImage.scalePercent(35f);
        barCodeImage.scalePercent(35f, 50f);
        cell = new PdfPCell(barCodeImage);
        //
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        // adding text underneath the barcode
        //
        int textWidth = 53, textHeight = 50;
        BufferedImage bi2 = new BufferedImage(textWidth, textHeight, BufferedImage.TYPE_BYTE_BINARY);
        Graphics2D g = bi2.createGraphics();
        g.setFont(new java.awt.Font("Verdana", java.awt.Font.PLAIN, 10));
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, textWidth, textHeight);
        g.setColor(Color.BLACK);
        g.drawString("" + seq, 5, 10);

        g.dispose();
        baos = new ByteArrayOutputStream();
        ImageIO.write(bi2, "png", baos);
        imageBytes = baos.toByteArray();
        Image barCodeTextImage = Image.getInstance(imageBytes);

        barCodeTextImage.setRotationDegrees(90f);
        cell = new PdfPCell(barCodeTextImage);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(0);
        cell.setLeading(0f, 0f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("\nThis certificate is not refundable and cannot be replaced if lost or stolen.\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setFixedHeight(30f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("\nMust have official stamp to be valid.\n\n", fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setColspan(3);
        table.addCell(cell);
        document.add(table);
        //
        float[] widths3 = { 40f, 60f }; // percentages         
        table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.setSpacingBefore(0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

        phrase = new Phrase();
        ch = new Chunk("APPROVED BY THE STATE BOARD OF ACCOUNTS\nFOR THE CITY OF BLOOMINGTON, IN 2007\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        // cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setFixedHeight(44f);
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(
                "VENDERS SHALL REDEEM THIS CERTIFICATE THROUGH BLOOMINGTON'S\nPARKS & REC DEPT. BY DECEMBER 15TH OF THE YEAR RECEIVED\n\n\n",
                fnts);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);

        document.add(table);
        // document.add( Chunk.NEWLINE );
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

From source file:bucks.RedeemInvoice.java

License:Open Source License

void generateInvoice(HttpServletResponse res, Redeem redeem) {

    ///*w w w.  ja  v  a  2  s .c  o m*/
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String spacer = "   \n";
    User user = redeem.getUser();
    Vendor vendor = redeem.getVendor();
    List<Buck> bk_bucks = redeem.getBk_bucks();
    List<Buck> gc5_bucks = redeem.getGc5_bucks();
    List<Buck> gc20_bucks = redeem.getGc20_bucks();
    List<Buck> gc_bucks = redeem.getGc_bucks();
    List<Dispute> disputes = redeem.getDisputes();
    int bk_total = 0, gc5_total = 0, gc20_total = 0, total = 0;
    if (bk_bucks.size() > 0) {
        bk_total = bk_bucks.size() * 3;
    }
    if (gc5_bucks.size() > 0) {
        gc5_total = gc5_bucks.size() * 5;
    }
    if (gc20_bucks.size() > 0) {
        gc20_total = gc20_bucks.size() * 20;
    }
    total = bk_total + gc5_total + gc20_total;
    String vendor_name = "";
    if (vendor != null) {
        vendor_name = vendor.getCleanName();
    }
    ServletOutputStream out = null;
    String filename = "invoice_" + vendor_name + "_" + redeem.getId() + ".pdf";
    try {
        // space
        //         
        Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
        Document document = new Document(pageSize, 36, 36, 18, 18);// 18,18,54,35         
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance(imageUrl);
        // image = Image.getInstance(byte bytes[]);// generated image
        image.scalePercent(20f);
        Font fnt = new Font(Font.TIMES_ROMAN, 12, Font.NORMAL);
        Font fntb = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);
        Font fntb2 = new Font(Font.TIMES_ROMAN, 14, Font.BOLD);

        //
        Phrase spacePhrase = new Phrase();
        Chunk ch = new Chunk(spacer, fnt);
        spacePhrase.add(ch);

        float[] widths = { 15f, 85f }; // percentages
        PdfPTable headTable = new PdfPTable(widths);
        headTable.setWidthPercentage(100);
        headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        // image.setWidthPercentage(15.0f);
        PdfPCell cell = new PdfPCell(image);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        // cell.setFixedHeight(46f);
        headTable.addCell(cell);

        Phrase phrase = new Phrase();
        ch = new Chunk(
                "City of Bloomington Community Farmers Market\n Gift Certificates/Market Bucks Invoice\n ",
                fntb2);
        phrase.add(ch);
        Paragraph pp = new Paragraph();
        pp.setIndentationLeft(20);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.add(phrase);
        cell = new PdfPCell(pp);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headTable.addCell(cell);
        document.add(headTable);
        //
        float[] widths3 = { 50f, 50f }; // percentages
        PdfPTable table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        phrase = new Phrase();
        ch = new Chunk(" Vendor Name: ", fntb);
        phrase.add(ch);
        ch = new Chunk(vendor.getFullName(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //         
        phrase = new Phrase();
        ch = new Chunk("Date: ", fntb);
        phrase.add(ch);
        ch = new Chunk(redeem.getDate(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        phrase = new Phrase();
        ch = new Chunk(" Vendor Number: ", fntb);
        phrase.add(ch);
        ch = new Chunk(vendor.getId(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        phrase = new Phrase(); // empty cell
        ch = new Chunk(" ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        table.addCell(cell); // extra space
        table.addCell(cell);
        document.add(table);
        //
        phrase = new Phrase(new Chunk("\n", fnt));
        document.add(phrase);
        //
        float[] widths2 = { 30f, 25f, 15f, 15f, 15f }; // percentages
        table = new PdfPTable(widths2);
        table.setWidthPercentage(90);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        // table.getDefaultCell().setPadding(5);
        phrase = new Phrase();
        ch = new Chunk("Type of Voucher", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("City Account Number", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("Quantity", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("Multiply", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("Value", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setBorderWidth(2f);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        // second row
        phrase = new Phrase();
        ch = new Chunk("Market Bucks", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47240", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        String str = " ";
        if (bk_bucks.size() > 0) {
            str = "" + bk_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $3.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);

        phrase = new Phrase();
        str = " ";
        if (bk_total > 0) {
            str = "$" + bk_total + ".00";
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 3rd row
        phrase = new Phrase();
        ch = new Chunk("$5 Gift Cerificates", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47230", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        str = " ";
        if (gc5_bucks.size() > 0) {
            str = "" + gc5_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $5.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);

        phrase = new Phrase();
        str = " ";
        if (gc5_total > 0) {
            str = "$" + gc5_total + ".00";
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 4th row
        phrase = new Phrase();
        ch = new Chunk("$20 Gift Certificates", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("201-18-1865003-47230", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        //
        phrase = new Phrase();
        str = " ";
        if (gc20_bucks.size() > 0) {
            str = "" + gc20_bucks.size();
        }
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);

        phrase = new Phrase();
        ch = new Chunk("x $20.00 = ", fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        table.addCell(cell);
        str = " ";
        if (gc20_total > 0) {
            str = "$" + gc20_total + ".00";
        }
        phrase = new Phrase();
        ch = new Chunk(str, fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPadding(4);
        table.addCell(cell);
        //
        // 5th row total
        phrase = new Phrase();
        ch = new Chunk(" Total Value: ", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2f);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk("$" + total + ".00", fntb);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(2f);
        cell.setPadding(4);
        cell.setLeading(2f, 1.2f);
        table.addCell(cell);
        document.add(table);
        //
        //
        float[] withs5 = { 100f };
        table = new PdfPTable(withs5);
        table.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase(" "));
        cell.setBorder(Rectangle.BOTTOM);
        // cell.setBorderColorBottom(Color.BLACK);
        cell.setBorderWidthBottom(2f);
        table.addCell(cell);
        document.add(table);
        //
        ch = new Chunk("\n", fnt);
        phrase = new Phrase();
        phrase.add(ch);
        document.add(phrase);
        //
        // float[] widths3 = {50f, 50f}; // percentages
        table = new PdfPTable(widths3);
        table.setWidthPercentage(100);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        phrase = new Phrase();
        ch = new Chunk(" Data Entry Completed by: ", fntb);
        phrase.add(ch);
        ch = new Chunk(user.getFullName(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        //
        phrase = new Phrase();
        ch = new Chunk(" Invoice Number: ", fntb);
        phrase.add(ch);
        ch = new Chunk(redeem.getId(), fnt);
        phrase.add(ch);
        cell = new PdfPCell(phrase);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        table.addCell(cell);
        document.add(table);
        document.add(spacePhrase);
        document.add(spacePhrase);
        //
        // adding bucks and GC
        //
        float[] widths4 = { 100f }; // percentages
        table = new PdfPTable(widths4);
        table.setWidthPercentage(100);
        // table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        int row = 1, col = 1;
        if (bk_bucks.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Market Bucks ", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            phrase = new Phrase();
            for (Buck one : bk_bucks) {
                ch = new Chunk("" + one.getId() + " ", fntb);
                phrase.add(ch);
                col++;
                if (col > 15) {
                    row++;
                    col = 1;
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    phrase = new Phrase();
                }
            }
            if (col > 1) {
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
            if (row < 10) {
                for (int j = 0; j < 2; j++) {
                    phrase = new Phrase();
                    ch = new Chunk(" ", fntb);
                    phrase.add(ch);
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    row++;
                }
            }
        }
        col = 1;
        if (gc_bucks.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Gift Certificates ", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            phrase = new Phrase();
            for (Buck one : gc_bucks) {
                ch = new Chunk("" + one.getId() + " ", fntb);
                phrase.add(ch);
                col++;
                if (col > 15) {
                    row++;
                    col = 1;
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    phrase = new Phrase();
                }
            }
            if (col > 1) {
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
            if (row < 15) {
                for (int j = 0; j < 2; j++) {
                    phrase = new Phrase();
                    ch = new Chunk(" ", fntb);
                    phrase.add(ch);
                    cell = new PdfPCell(phrase);
                    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.addCell(cell);
                    row++;
                }
            }
        }
        if (disputes != null && disputes.size() > 0) {
            phrase = new Phrase();
            ch = new Chunk(" Disputed Market Bucks and/or Gift Certificates (number: reason)", fntb);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidth(2f);
            table.addCell(cell);
            row++;
            for (Dispute one : disputes) {
                phrase = new Phrase();
                ch = new Chunk(one.getBuck_id() + ": " + one.getReason(), fnt);
                phrase.add(ch);
                if (one.hasNotes()) {
                    ch = new Chunk("\nNotice: " + one.getNotes(), fnt);
                    phrase.add(ch);
                    row++;
                }
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
                row++;
            }
        }
        if (redeem.hasNotes()) {
            phrase = new Phrase();
            ch = new Chunk("\nNotice: " + redeem.getNotes(), fnt);
            phrase.add(ch);
            cell = new PdfPCell(phrase);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
            row++;
        }
        if (row < 18) {
            for (int j = row; j < 18; j++) {
                phrase = new Phrase();
                ch = new Chunk(" ", fntb);
                phrase.add(ch);
                cell = new PdfPCell(phrase);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                table.addCell(cell);
            }
        }

        document.add(table);
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        res.setHeader("Content-Disposition", " attachment; filename=" + filename);
        res.setContentType("application/pdf");
        //
        // the contentlength is needed for MSIE!!!
        res.setContentLength(baos.size());
        //
        out = res.getOutputStream();
        if (out != null) {
            baos.writeTo(out);
        }
    } catch (Exception ex) {
        System.err.println(ex);
    }
}

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.j av  a  2s .  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  w w  w .j  a  v a  2s  .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,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());

    }

}