Example usage for com.lowagie.text Rectangle BOTTOM

List of usage examples for com.lowagie.text Rectangle BOTTOM

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle BOTTOM.

Prototype

int BOTTOM

To view the source code for com.lowagie.text Rectangle BOTTOM.

Click Source Link

Document

This represents one side of the border of the Rectangle.

Usage

From source file:QMSMultiQuoteController.java

License:Open Source License

private int doPDFGeneration(MultiQuoteFinalDOB finalDOB, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    int mailFlag = 0;
    int faxFlag = 0;
    int printFlag = 0;
    int returnFlag = 3;
    //@@Modified by kiran.v on 01/08/2011 for Wpbn Issue 271485
    ArrayList Sd = null;//from   w  w  w . j av  a2s. c  om
    ArrayList Cd = null;
    ArrayList Cdn = null;
    boolean frequencyFlag = false;
    boolean carrierFlag = false;
    boolean serviceFlag = false;
    Map<String, String> surChargesMap = null;
    //Kiran ends
    String transitTime = null;
    String[] contents = null;
    String[] levels = null;
    String[] aligns = null;
    String[] headFoot = null;
    String charge_desc = null;//@@Added by govind for the issue 258189
    //@@Added by Kameswari for the WPBN issue-61289
    ArrayList dobList = new ArrayList();
    MultiQuoteAttachmentDOB attachmentDOB = null;
    //@@Added by Kameswari for the WPBN issue-146448
    ArrayList charges = null;
    int chargesSize = 0;
    int noOfLanes = 0;
    MultiQuoteCharges chargesDOB = null;
    MultiQuoteChargeInfo multiQuoteChargeInfo = null;
    ArrayList freightCharges = null;
    MultiQuoteFreightLegSellRates legCharges = null;
    MultiQuoteFreightLegSellRates legOrginCharges = null;
    MultiQuoteFreightLegSellRates legDestCharges = null;
    String str1[] = null;
    ArrayList frequency = new ArrayList();
    ArrayList carrier = new ArrayList();
    ArrayList transittime = new ArrayList();
    ArrayList ratevalidity = new ArrayList();
    ArrayList frequency_o = new ArrayList();
    ArrayList frequency_d = new ArrayList();
    ArrayList carrier_o = new ArrayList();
    ArrayList carrier_d = new ArrayList();
    ArrayList transit_o = new ArrayList();
    ArrayList transit_d = new ArrayList();
    ArrayList validity_o = new ArrayList();
    ArrayList validity_d = new ArrayList();
    int size = 0;

    int gTemp = 0; // Added By Gowtham For PDF View Issue
    String placeDesc = null; // Added By Gowtham For PDF View Issue
    String tmpOrgPort = ""; // Added by Gowtham
    int gTemp1 = 0;
    String tmpfrq = "";
    String tmpServl = "";
    String tmpCarrier = "";
    String tmpDestPort = "";
    int LegSize = 0;
    HashSet PortAbbSet = null;
    //@@WPBN issue-146448
    ArrayList filesList = new ArrayList();
    File file = null;
    byte[] buffer = null;
    ArrayList bufferList = new ArrayList();
    ArrayList pdfFilesList = new ArrayList();
    HttpSession session = request.getSession();
    // Added by kiran.v on 16/09/2011
    String operation = finalDOB.getOperation() != null ? finalDOB.getOperation()
            : finalDOB.getMasterDOB().getOperation();

    PdfWriter writer = null; //Method: doPDFGeneration Defect: PdfWriter is not closedSuggestion: Close and nullify the writer in the finally block.
    //   @@ Added by subrahmanyam for the WPBN ISSUE: 146460 on 29/01/2009    
    QMSMultiQuoteSessionHome home = null;
    QMSMultiQuoteSession remote = null;
    int incoSize = 0; // Added by Gowtham on 24Feb2011 for IncoTerms display in PDF
    //   @@ Ended by subrahmanyam for the WPBN ISSUE: 146460 on 29/01/2009   

    //@@ WPBN issue-61289
    PdfPTable pTable;
    PdfPCell pCell;

    try {
        Sd = new ArrayList();
        Cd = new ArrayList();
        Cdn = new ArrayList();
        String carrierChecked = request.getParameter("selectCarrier");
        String serviceLevelChecked = request.getParameter("selectService");
        String frequencyChecked = request.getParameter("selectFrequecy");
        String transitTimeChecked = request.getParameter("selectTransitTime");
        String validityChecked = request.getParameter("selectFrieghtValidity");
        boolean carrierflag = false;
        boolean serviceflag = false;
        boolean frequencyflag = false;
        //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
        boolean transittimeflag = false;
        boolean freightValidity = false;
        DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
        MultiQuoteHeader headerDOB = finalDOB.getHeaderDOB();
        MultiQuoteMasterDOB masterDOB = finalDOB.getMasterDOB();
        ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
        ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                .getAttribute("loginbean");

        eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
        //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());
        //@@ Commented & Added by subrahmanyam for the Effective pbn Issue 212006 on # 26-Jul-10
        /* String[] strDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
        String[] effDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
        */
        String[] strDate = null;
        String[] effDate = null;
        if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
            if ("PDF".equalsIgnoreCase(request.getParameter("pdf"))) {
                strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getEffDate());
            } else {
                strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                //effDate  = eSupplyDateUtility.getDisplayStringArray(masterDOB.getCreatedDate());
                //@@Modified by kiran.v on 28/07/2011 for Wpbn Issue -256087
                effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getEffDate());
            }

        } else {
            strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());

        }

        String[] validDate;
        String validUptoStr = null;
        if (headerDOB.getValidUpto() != null) {
            validDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getValidUpto());
            validUptoStr = validDate[0];
        }

        StringBuffer attentionTo = new StringBuffer("");
        if (masterDOB.getCustContactNames() != null) {
            for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                attentionTo.append(
                        masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i] : "");
                if (i != (masterDOB.getCustContactNames().length - 1))
                    attentionTo.append(",");
            }
        }
        charges = finalDOB.getLegDetails();

        chargesSize = charges.size();
        // System.out.println("Before Document Objec--------------------------->");
        Document document = new Document(PageSize.A4, 54f, 54f, 68.4f, 68.4f);//@@ 36 points represent 0.5 inch
        if (!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith()))
            document.setPageSize(PageSize.A4.rotate());
        String PDF_FILE_NAME = "Approved.pdf";
        document.addTitle("Approved Report");
        document.addSubject("Report PDF");
        document.addKeywords("Test, Key Words");
        document.addAuthor("QuoteShop");
        document.addCreator("QuoteShop");
        document.addCreationDate();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ByteArrayOutputStream baosFile = new ByteArrayOutputStream();
        writer = PdfWriter.getInstance(document, baos);
        // int b = writer.getPageNumber();
        baos.close();

        document.open();

        //jyothi
        PdfContentByte cb = writer.getDirectContent();
        cb.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                document.top() - document.bottom());

        cb.stroke();
        //jyothi
        // Graphic horizontalLine = new Graphic();
        //horizontalLine.setHorizontalLine(1f, 100f);
        // horizontalLine.setColorStroke(Color.BLACK);
        //horizontalLine.setLineWidth(100);

        // PdfFileStamp fileStamp = new PdfFileStamp("Approved.pdf");

        //PdfPageEventHelper helper

        //writer.setPageEvent(new PdfPageEventHelper());

        //document.setMargins(15,15,15,15);            
        // Draw a rectangle inside the page's margins.
        //PdfContentByte cb = writer.getDirectContent();
        //cb.rectangle (document.left (), document.bottom (), document.right ()-document.left (),document.top ()-document.bottom ());
        //cb.stroke ();
        int[] widths = { 12, 12, 12, 12, 12, 12, 28 };
        /*Table mainT = new Table(2);
        mainT.setWidth(80);
        //mainT.setWidths(widths);
        mainT.setBorderColor(Color.white);
        mainT.setPadding(1);
        mainT.setSpacing(0);*/

        int[] width = { 4, 1 };
        Table mainT = new Table(2, 2);
        mainT.setWidth(100);
        mainT.setWidths(width);
        mainT.setBorderColor(Color.white);
        mainT.setPadding(3);
        mainT.setSpacing(0);

        Phrase headingPhrase = new Phrase("", FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
        Cell cellHeading = new Cell(headingPhrase);
        cellHeading.setBorderColor(new Color(255, 255, 255));
        cellHeading.setHorizontalAlignment(cellHeading.ALIGN_CENTER);
        cellHeading.setBorderWidth(0);
        // cellHeading.setColspan(6);
        mainT.addCell(cellHeading);

        Cell imageCell = new Cell();
        java.net.URL url = getServletConfig().getServletContext().getResource("/images/DHLlogo.gif");
        Image img0 = Image.getInstance(url);
        img0.setAlignment(Image.ALIGN_RIGHT);
        // img0.scaleToFit(6.0f, 1.9f);
        //System.out.println("Lower Left:   "" Upper   Left:   "+img0.getRight()+"   "+);

        // imageCell.setWidth("6");

        // imageCell.setColspan(2);
        imageCell.setHorizontalAlignment(imageCell.ALIGN_LEFT);
        imageCell.add(img0);
        imageCell.setBorderWidth(0);
        imageCell.setNoWrap(true);
        System.out.println(imageCell.cellWidth());
        mainT.addCell(imageCell);
        mainT.setAlignment(mainT.ALIGN_CENTER);

        document.add(mainT);

        pTable = new PdfPTable(1);
        pTable.setSpacingAfter(10f);
        pCell = new PdfPCell(new Phrase(new Chunk("")));
        pCell.setBorder(0);
        pTable.addCell(pCell);

        document.add(pTable);
        // System.out.println("After Image && Before Content--------------------------->");

        Table partCountry = new Table(4, 5);

        Table partCountry1 = new Table(4);
        int[] widths1 = { 30, 20, 30, 20 };
        //partCountry1.setBorderWidth(0);
        partCountry1.setBorderWidth(1f);//modified by silpa.p on 3-06-11
        partCountry1.setWidths(widths1);
        partCountry1.setWidth(100);
        partCountry1.setBorderColor(Color.black);
        partCountry1.setPadding(1);
        partCountry1.setSpacing(0);
        partCountry1.setBorder(1);//added by silpa.p on 3-06-11
        partCountry1.setAutoFillEmptyCells(true);
        //partCountry.setTableFitsPage(true);
        partCountry.setAlignment(partCountry.ALIGN_CENTER);
        partCountry.setBorderWidth(0);
        ;

        int[] widths2 = { 20, 30, 20, 30 };
        partCountry.setBorderWidth(0);
        partCountry.setBorderWidth(1f);//modified by silpa.p on 3-06-11
        partCountry.setWidths(widths2);
        partCountry.setWidth(100);
        partCountry.setBorderColor(Color.black);
        partCountry.setPadding(1);
        partCountry.setBorder(1);//added by silpa.p on 3-06-11
        partCountry.setSpacing(0);
        partCountry.setAutoFillEmptyCells(true);
        //partCountry.setTableFitsPage(true);
        partCountry.setAlignment(partCountry.ALIGN_CENTER);
        //Jyothi
        partCountry.setBorderWidthBottom(1);
        partCountry.setBorderWidthTop(0);
        partCountry.setBorderWidthLeft(1);
        partCountry.setBorderWidthRight(1);
        //Jyothi
        partCountry.setBorderWidth(0);
        ;
        Cell cellCountry;

        String shipmentMode = "";
        if (!finalDOB.isMultiModalQuote()) {
            if (finalDOB.getMasterDOB().getShipmentMode() == 1) {
                shipmentMode = "AIR FREIGHT PROPOSAL";
                transitTime = "Approximate Transit Time";
            } else if (finalDOB.getMasterDOB().getShipmentMode() == 2) {
                shipmentMode = "SEA FREIGHT PROPOSAL";
                transitTime = "Approximate Transit Days";
            } else if (finalDOB.getMasterDOB().getShipmentMode() == 4) {
                shipmentMode = "TRUCK FREIGHT PROPOSAL";
                transitTime = "Approximate Transit Time";
            }
        } else {
            shipmentMode = " MULTI-MODAL FREIGHT PROPOSAL ";
            transitTime = "Approximate Transit time and Days";

        }

        Chunk chk = new Chunk(shipmentMode, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setWidth("100");
        //cellCountry.setColspan(1);
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
        partCountry1.addCell(cellCountry);

        chk = new Chunk("");
        cellCountry = new Cell(chk);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setWidth("100");
        //cellCountry.setColspan(1);
        cellCountry.setBorderWidth(0);
        partCountry1.addCell(cellCountry);

        chk = new Chunk("SERVICE INFORMATION", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setWidth("100");
        //cellCountry.setColspan(2);
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
        partCountry1.addCell(cellCountry);

        chk = new Chunk("");
        cellCountry = new Cell(chk);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setWidth("100");
        //cellCountry.setColspan(1);
        cellCountry.setBorderWidth(0);
        partCountry1.addCell(cellCountry);

        document.add(partCountry1);

        chk = new Chunk("Customer Name: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("30");
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(headerDOB.getCustomerName() != null ? toTitleCase(headerDOB.getCustomerName()) : "",
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Agent: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("30");
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(headerDOB.getAgent() != null ? headerDOB.getAgent() : "",
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Attention To: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(toTitleCase(attentionTo.toString()),
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Commodity Or Product: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        //chk = new Chunk(headerDOB.getCommodity()!=null?toTitleCase(headerDOB.getCommodity()):"",FontFactory.getFont("ARIAL", 7, Font.NORMAL,Color.BLACK));//commented by silpa.p on 21-06-11
        chk = new Chunk(headerDOB.getCommodity() != null ? (headerDOB.getCommodity()) : "",
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//added by silpa.p on 21-06-11
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Quote Reference: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(masterDOB.getQuoteId() != null ? masterDOB.getQuoteId() : "",
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Notes: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//modified by silpa.p on 13-06-11
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(headerDOB.getNotes() != null ? toTitleCase(headerDOB.getNotes()) : "",
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Date Of Quotation: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk(strDate[0], FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Date Effective: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk((effDate[0] != null ? effDate[0] : ""),
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Sales Person : ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk((headerDOB.getPreparedBy() != null ? toTitleCase(headerDOB.getPreparedBy()) : ""),
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk("Validity Of Quote: ", FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        chk = new Chunk((validUptoStr != null ? validUptoStr : "VALID UNTIL FURTHER NOTICE"),
                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setHeader(true);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setBackgroundColor(Color.LIGHT_GRAY);//modified by silpa.p on 3-06-11
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
        partCountry.addCell(cellCountry);

        document.add(partCountry);

        pTable = new PdfPTable(1);
        pTable.setSpacingAfter(10f);
        pCell = new PdfPCell(new Phrase(new Chunk("")));
        pCell.setBorder(0);
        pTable.addCell(pCell);

        document.add(pTable);

        /* if(chargesSize==1)
         {
         if("MY".equalsIgnoreCase(masterDOB.getCountryId()))
         {
         chk = new Chunk((headerDOB.getOriginCountry()!=null?headerDOB.getOriginCountry()[0].toUpperCase():"")+" TO "+(headerDOB.getDestinationCountry()!=null?headerDOB.getDestinationCountry()[0].toUpperCase():""),FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.BLUE));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(13.0f);//@@Do Not Decrease.
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
                
         cellCountry = new Cell("");
         cellCountry.setBorderWidth(0);
         cellCountry.setLeading(5.0f);
         partCountry.addCell(cellCountry);
                 
                 
         chk = new Chunk(headerDOB.getCustomerName(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.BLUE));
         cellCountry = new Cell(chk);
         cellCountry.setHeader(true);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("ATTENTION TO: "+attentionTo.toString(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.BLUE));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
         }
         else
         {
         chk = new Chunk((headerDOB.getOriginCountry()!=null?headerDOB.getOriginCountry()[0].toUpperCase():"")+" TO "+(headerDOB.getDestinationCountry()!=null?headerDOB.getDestinationCountry()[0].toUpperCase():""),FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.RED));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(13.0f);//@@Do Not Decrease.
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
                 
         cellCountry = new Cell("");
         cellCountry.setBorderWidth(0);
         cellCountry.setLeading(5.0f);
         partCountry.addCell(cellCountry);
                 
                 
         chk = new Chunk(headerDOB.getCustomerName(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.RED));
         cellCountry = new Cell(chk);
         cellCountry.setHeader(true);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("ATTENTION TO: "+attentionTo.toString(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.RED));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);
         }
         }else{
          if("MY".equalsIgnoreCase(masterDOB.getCountryId()))
          {
          //chk = new Chunk("Multi-Lane/Multi-Carrier",FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.BLUE)); // Commented by Gowtham on 24Feb2011
          chk = new Chunk("Multiple Origins And/Or Destinations",FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.BLUE));
          cellCountry = new Cell(chk);
          cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
          cellCountry.setNoWrap(true); 
          cellCountry.setLeading(13.0f);//@@Do Not Decrease.
          cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
          partCountry.addCell(cellCountry);
                   
          cellCountry = new Cell("");
          cellCountry.setBorderWidth(0);
          cellCountry.setLeading(5.0f);
          partCountry.addCell(cellCountry);
                  
                  
          chk = new Chunk(headerDOB.getCustomerName(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.BLUE));
          cellCountry = new Cell(chk);
          cellCountry.setHeader(true);
          cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
          cellCountry.setNoWrap(true); 
          cellCountry.setLeading(10.0f);
          cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
          partCountry.addCell(cellCountry);
                  
          chk = new Chunk("ATTENTION TO: "+attentionTo.toString(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.BLUE));
          cellCountry = new Cell(chk);
          cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
          cellCountry.setNoWrap(true); 
          cellCountry.setLeading(10.0f);
          cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
          partCountry.addCell(cellCountry);
          }
          else
          {
            //chk = new Chunk("Multi-Lane/Multi-Carrier",FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.RED));
            chk = new Chunk("Multiple Origins And/Or Destinations",FontFactory.getFont("ARIAL", 16, Font.BOLD,Color.RED)); // Commented by Gowtham on 24Feb2011
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true); 
            cellCountry.setLeading(13.0f);//@@Do Not Decrease.
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);
                    
            cellCountry = new Cell("");
            cellCountry.setBorderWidth(0);
            cellCountry.setLeading(5.0f);
            partCountry.addCell(cellCountry);
                    
                    
            chk = new Chunk(headerDOB.getCustomerName(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.RED));
            cellCountry = new Cell(chk);
            cellCountry.setHeader(true);
            cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true); 
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);
                    
            chk = new Chunk("ATTENTION TO: "+attentionTo.toString(),FontFactory.getFont("ARIAL", 14, Font.BOLD,Color.RED));
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true); 
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);
          }
         }
         cellCountry = new Cell("");
         cellCountry.setBorderWidth(0);
         cellCountry.setLeading(5.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("QUOTE REFERENCE: "+masterDOB.getQuoteId(),FontFactory.getFont("ARIAL", 12, Font.BOLD,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");
         cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry);  
         chk = new Chunk("DATE OF QUOTATION: "+strDate[0],FontFactory.getFont("ARIAL", 12, Font.BOLD,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setWidth("100");cellCountry.setBorderWidth(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(10.0f);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         partCountry.addCell(cellCountry); */

        contents = masterDOB.getContentOnQuote();
        levels = masterDOB.getLevels();
        aligns = masterDOB.getAlign();
        headFoot = masterDOB.getHeaderFooter();
        Table content = null;
        if (contents != null && contents.length > 0) {
            content = new Table(1);
            content.setOffset(5);
            content.setWidth(100);
            content.setPadding(1);
            content.setSpacing(0);
            content.setBackgroundColor(Color.WHITE);
            content.setBorderColor(Color.black);
            content.setBorderWidth(1f);
            Cell cellContent = null;
            chk = null;
            int headFootLen = headFoot.length;
            for (int i = 0; i < headFootLen; i++) {
                if (headFoot[i] != null && "H".equalsIgnoreCase(headFoot[i])) {
                    chk = new Chunk(contents[i], FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));
                    cellContent = new Cell(chk);
                    cellContent.setBorder(0);
                    cellContent.setLeading(8.0f);
                    cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                    if ("L".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);
                    else if ("C".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_CENTER);
                    else if ("R".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_RIGHT);
                    content.addCell(cellContent);
                }
            }
            document.add(content);
            /*content = null;
            cellContent =  null;*/
        }
        /*content = new Table(1);
        Cell cellContent1 = new Cell(new Chunk(""));
        content.addCell(cellContent1); */

        if (!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())) {
            //@@Added by Kameswari for the WPBN issue-146448 on 03/12/08
            for (int i = 0; i < chargesSize; i++) {
                legCharges = (MultiQuoteFreightLegSellRates) charges.get(0);
                freightCharges = legCharges.getFreightChargesList();
                int tempCount = freightCharges.size();
                for (int j = 0; j < tempCount; j++) {
                    multiQuoteChargeInfo = (MultiQuoteChargeInfo) freightCharges.get(i);//govind

                    if (multiQuoteChargeInfo.getSelectedLaneNum() == i) {
                        if (multiQuoteChargeInfo != null && multiQuoteChargeInfo.getValidUpto() != null) {
                            str1 = eSupplyDateUtility
                                    .getDisplayStringArray(multiQuoteChargeInfo.getValidUpto());
                        }
                        ///////////////////////////////////////////Second Table////////////////////////////
                        if (chargesSize > 1) {
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())) {
                                //Added by kiran.v on 16/09/2011
                                frequencyFlag = true;
                                frequency.add(multiQuoteChargeInfo.getFrequency());
                                frequency_o.add(legCharges.getOrigin());
                                frequency_d.add(legCharges.getDestination());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())) {
                                transittime.add(multiQuoteChargeInfo.getTransitTime());
                                transit_o.add(legCharges.getOrigin());
                                transit_d.add(legCharges.getDestination());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())) {
                                carrierFlag = true;
                                carrier.add(multiQuoteChargeInfo.getCarrier());
                                carrier_o.add(legCharges.getOrigin());
                                carrier_d.add(legCharges.getDestination());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())) {
                                if (multiQuoteChargeInfo.getValidUpto() != null) {
                                    str1 = eSupplyDateUtility
                                            .getDisplayStringArray(multiQuoteChargeInfo.getValidUpto());
                                    ratevalidity.add(str1[0]);
                                }

                                validity_o.add(legCharges.getOrigin());
                                validity_d.add(legCharges.getDestination());
                            }
                        } else {

                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())) {
                                frequency.add(multiQuoteChargeInfo.getFrequency());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())) {
                                transittime.add(multiQuoteChargeInfo.getTransitTime());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())) {
                                carrier.add(multiQuoteChargeInfo.getCarrier());
                            }
                            if ("Y".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())) {
                                if (multiQuoteChargeInfo.getValidUpto() != null) {
                                    str1 = eSupplyDateUtility
                                            .getDisplayStringArray(multiQuoteChargeInfo.getValidUpto());
                                    ratevalidity.add(str1[0]);
                                }

                            }
                        }
                    }
                }
            }
        } // partCountry  =  new Table(2,13);
        size = frequency.size() + transittime.size() + carrier.size() + ratevalidity.size();
        /* Table prepareTable = new Table(1) ;
         prepareTable.setWidth(100);
         prepareTable.setBackgroundColor(Color.white);
         prepareTable.setBorderColor(Color.white);
         prepareTable.setPadding(1);
         chk = new Chunk("Prepared By: "+(headerDOB.getPreparedBy()!=null?headerDOB.getPreparedBy().toUpperCase():""),FontFactory.getFont("ARIAL", 10, Font.BOLD,Color.BLACK));
         cellCountry = new Cell(chk);
        // cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setBorder(0);
         cellCountry.setNoWrap(true);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_LEFT);
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         prepareTable.addCell(cellCountry);
                
         document.add(prepareTable); */

        /*  partCountry  =  new Table(2,13+size);
                  
        //@@WPBN issue-146448 on 03/12/08
          partCountry.setOffset(5);
          partCountry.setWidth(100);
          partCountry.setPadding(1);
          partCountry.setSpacing(0);
          partCountry.setBackgroundColor(Color.WHITE);
          partCountry.setBorderColor(Color.WHITE);
          partCountry.setBorderWidth(1f);
                  
          /*chk = new Chunk("Prepared By: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
          cellCountry = new Cell(chk);
         // cellCountry.setBackgroundColor(Color.lightGray);
          cellCountry.setBorder(0);
          cellCountry.setNoWrap(true);
          cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
          cellCountry.setBorder(0);
          cellCountry.setLeading(8.0f);
          partCountry.addCell(cellCountry);*/

        /* chk = new Chunk("SERVICE INFORMATION ",FontFactory.getFont("Courier-Bold", 12, Font.UNDERLINE,Color.blue));
         cellCountry = new Cell(chk);
         cellCountry.setColspan(2);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
         //cellCountry.setBackgroundColor(Color.ORANGE);
         cellCountry.setBorder(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("Agent: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk); 
         //cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setBorder(0);
         cellCountry.setNoWrap(true); 
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+(headerDOB.getAgent()!=null?headerDOB.getAgent().toUpperCase():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true);
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                
         chk = new Chunk("Commodity or Product: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
        // cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+(headerDOB.getCommodity()!=null?headerDOB.getCommodity().toUpperCase():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("Type Of Service Quoted: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
        // cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+(headerDOB.getTypeOfService()!=null?headerDOB.getTypeOfService().toUpperCase():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
          partCountry.addCell(cellCountry);
                 
         chk = new Chunk("Notes: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
        // cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk(" "+(headerDOB.getNotes()!=null?headerDOB.getNotes().toUpperCase()+'\n':""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setLeading(8.0f);
         cellCountry.setBorder(0);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("Date Effective: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         //cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+(effDate[0]!=null?effDate[0]:""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("Validity Of Quote: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
        //  cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+(validUptoStr!=null?validUptoStr:"VALID UNTIL FURTHER NOTICE"),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true);
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         if(headerDOB.getPaymentTerms()!=null && headerDOB.getPaymentTerms().trim().length()!=0)
         {
         chk = new Chunk("Payment Terms: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         //cellCountry.setBackgroundColor(Color.lightGray);
         cellCountry.setNoWrap(true);
         cellCountry.setBorder(0);
         cellCountry.setHorizontalAlignment(cellCountry.ALIGN_RIGHT);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
                 
         chk = new Chunk("   "+headerDOB.getPaymentTerms(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         cellCountry = new Cell(chk);
         cellCountry.setNoWrap(true); 
         cellCountry.setBorder(0);
         cellCountry.setLeading(8.0f);
         partCountry.addCell(cellCountry);
         }
                 
         document.add(partCountry);*/
        partCountry.complete();
        //System.out.println("After Page Country-------------------------------->");
        //Origin Charges
        //document.setMargins(10,10,10,10);
        // b1= writer.getPageNumber();

        //@@Added by Kameswari for the WPBN issue-146448
        charges = finalDOB.getLegDetails();
        noOfLanes = charges.size();
        //Added by kiran.v on 16/09/2011
        // session.setAttribute("legSize",noOfLanes);           
        PdfPTable chargeCountry2 = null;
        Table chargeCountry = null;
        PdfPCell cell2 = null;
        Cell cell = null;
        Table frtHeader = null;
        Table chargeTitle = null;
        Table chargeCountry1 = null;
        Cell cell1 = null;
        CustomCell border = new CustomCell();
        // float cellWidths[]   = {40,20,10,15,25};//@@Added by Kameswari for the WPBN issue - on 12/11/08
        float cellWidths[] = { 40, 15, 15, 15, 25, 15 };
        float cellWidths1 = 40;

        /* chk = new Chunk("Charge Name",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
         Cell cell = new Cell(chk);
         cell.setHeader(true);
         cell.setBackgroundColor(Color.ORANGE);
         cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
         chargeCountry.addCell(cell);
                 
         chk = new Chunk("Breakpoint",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
        cell = new Cell(chk);
         cell.setHeader(true);
         cell.setBackgroundColor(Color.ORANGE);
         cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
         chargeCountry.addCell(cell);
                 
         chk = new Chunk("Currency",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
        cell = new Cell(chk);
         cell.setHeader(true);
         cell.setBackgroundColor(Color.ORANGE);
         cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
         chargeCountry.addCell(cell);
                 
         chk = new Chunk("Rate",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
        cell = new Cell(chk);
         cell.setHeader(true);
         cell.setBackgroundColor(Color.ORANGE);
         cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
         chargeCountry.addCell(cell);
                 
         chk = new Chunk("Basis",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
        cell = new Cell(chk);
         cell.setHeader(true);
         cell.setBackgroundColor(Color.ORANGE);
         cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
         chargeCountry.addCell(cell);           
                 
         chargeCountry.endHeaders();
         System.out.println("End of Charge Headers--------------------------------->");
         System.out.println("");*/
        //    boolean b3 = document.newPage();
        //  QuoteCharges chargesDOB           = null;
        ArrayList originChargeInfo = null;
        int originChargesInfoSize = 0;
        MultiQuoteChargeInfo chargeInfo = null;
        ArrayList originLaneCharges = finalDOB.getLegDetails();//.get(0)).getOriginChargesList();
        for (int c = 0; c < noOfLanes; c++) //charges........
        {
            legOrginCharges = (MultiQuoteFreightLegSellRates) originLaneCharges.get(c);
            ArrayList originCharges = legOrginCharges.getOriginChargesList();
            int[] originIndices = legOrginCharges.getSelectedOriginChargesListIndices();
            int originChargesSize = 0;
            if (originIndices != null)
                originChargesSize = originIndices.length;
            else
                originChargesSize = 0;

            /*PdfPCell hLine = new PdfPCell(new Phrase(""));
            hLine.setBorder(PdfPCell.NO_BORDER);*/

            if (originChargesSize <= 0) {
                continue;
            }
            /*  if(b1>1)
             {
            chk = new Chunk("QUOTE REFERENCE:"+masterDOB.getQuoteId(),FontFactory.getFont("ARIAL", 10, Font.BOLD,Color.BLACK));
             cell = new Cell(chk);
             cell.setColspan(5);cell.setLeading(10.0f);
             cell.setBackgroundColor(Color.WHITE);                
             cell.setHeader(true);
             cell.setBorder(0);
             chargeCountry.addCell(cell); 
             }*/
            // chargeCountry  = new Table(5);
            home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");
            remote = home.create();
            //document.add(horizontalLine);

            chargeTitle = new Table(1);
            chargeTitle.setWidth(100);
            chargeTitle.setPadding(1);
            chargeTitle.setSpacing(1);
            chargeTitle.setBorderColor(Color.BLACK);
            chargeTitle.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
            chargeTitle.setBackgroundColor(Color.ORANGE);//modified by silpa.p on 3-06-11
            chargeTitle.setBorderWidth(1f);
            //chargeTitle.setBorder(1);

            if (legOrginCharges.getShipmentMode() == 2)
                chk = new Chunk(remote.getPortName(legOrginCharges.getOrigin()) + "-Origin Charges",
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.black));
            else
                chk = new Chunk(remote.getLocationName(legOrginCharges.getOrigin()) + "-Origin Charges",
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.black));
            cell1 = new Cell(chk);
            cell1.setLeading(10.0f);
            cell1.setBorder(0);
            cell1.setHeader(true);
            chargeTitle.addCell(cell1);
            document.add(chargeTitle);

            //chargeCountry  = new PdfPTable(6);
            chargeCountry = new Table(6);
            //chargeCountry.setWidth(100);
            chargeCountry.setWidths(cellWidths);
            chargeCountry.setBorder(1);
            chargeCountry.setWidth(100);
            chargeCountry.setDefaultVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.setDefaultHorizontalAlignment(cell.ALIGN_CENTER);
            chargeCountry.setPadding(3);
            chargeCountry.setSpacing(0);
            //chargeCountry.setOffset(5);
            //chargeCountry.setBackgroundColor(Color.WHITE);
            // chargeCountry.setBorderColor(Color.WHITE);
            // chargeCountry.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry.setBorderWidth(1f);
            //chargeCountry.setWidthPercentage(100);

            chargeCountry.setWidths(cellWidths);
            //document.add(horizontalLine);
            chk = new Chunk("Charge Description", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK)); // Added by Gowtham on 01-Feb-2011.
            // cell = new PdfPCell(new Phrase(chk));
            cell = new Cell(new Phrase(chk));
            //cell.setColspan(5);/@@Added by Kameswari for the WPBN issue - on 12/11/08
            // cell.setColspan(6);
            //cell.setLeading(10.0f);
            cell.setHorizontalAlignment(cell.ALIGN_LEFT);
            // cell.setBackgroundColor(Color.ORANGE);  
            ////cell.setBorder(0);
            //cell.setHeader(true);
            //cell.setBorder(Rectangle.BOTTOM);
            cell.setBorderWidth(1);
            //cell.setCellEvent(border); 
            chargeCountry.addCell(cell);

            chk = new Chunk("Weight Break Slab", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
            cell = new Cell(new Phrase(chk));
            //cell.setBorder(Rectangle.BOTTOM);
            //cell.setCellEvent(border); 
            cell.setHorizontalAlignment(cell.ALIGN_CENTER);
            cell.setBorderWidth(1);
            chargeCountry.addCell(cell);

            chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
            cell = new Cell(new Phrase(chk));
            //cell.setBorder(Rectangle.BOTTOM);
            //cell.setCellEvent(border);
            cell.setBorderWidth(1);
            cell.setHorizontalAlignment(cell.ALIGN_CENTER);
            chargeCountry.addCell(cell);

            chk = new Chunk("Charge Rate", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
            cell = new Cell(new Phrase(chk));
            //cell.setBorder(Rectangle.BOTTOM);
            //cell.setCellEvent(border);
            cell.setBorderWidth(1);
            cell.setHorizontalAlignment(cell.ALIGN_CENTER);
            chargeCountry.addCell(cell);

            chk = new Chunk("Basis", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
            cell = new Cell(new Phrase(chk));
            //cell.setBorder(Rectangle.BOTTOM);
            //cell.setCellEvent(border);
            cell.setBorderWidth(1);
            cell.setHorizontalAlignment(cell.ALIGN_LEFT);
            chargeCountry.addCell(cell);

            chk = new Chunk("Density Ratio", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
            cell = new Cell(new Phrase(chk));
            //cell.setBorder(Rectangle.BOTTOM);
            //cell.setCellEvent(border);
            cell.setBorderWidth(1);
            cell.setHorizontalAlignment(cell.ALIGN_CENTER);
            chargeCountry.addCell(cell);

            //@@Commented and Modified by Kameswari for the internal issue on 09/04/09
            /*chk = new Chunk("ORIGIN CHARGES",FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
            cell = new Cell(chk);
            //cell.setColspan(5);/@@Added by Kameswari for the WPBN issue - on 12/11/08
            cell.setColspan(6);
            cell.setLeading(10.0f);
            cell.setBackgroundColor(Color.ORANGE);                
            cell.setHeader(true);
            chargeCountry.addCell(cell);*/
            //   boolean b = document.newPage();
            // charge_desc  = "";
            for (int lc = 0; lc < originChargesSize; lc++) {
                if ((operation != null && "view".equalsIgnoreCase(operation) || ("Y".equalsIgnoreCase(
                        legOrginCharges.getOriginChargesSelectedFlag()[originIndices[lc]])))) {

                    //chargeCountry.endHeaders();
                    chargesDOB = (MultiQuoteCharges) originCharges.get(originIndices[lc]);

                    // for(int i=0;i<originChargesSize;i++)
                    //{
                    if (originIndices[lc] != -1) {

                        logger.info("Origin Charges doPDFGeneration::" + lc + ":" + chargesDOB); // newly added                  
                        originChargeInfo = chargesDOB.getChargeInfoList();
                        originChargesInfoSize = originChargeInfo.size();
                        int m = 0;//146455
                        String breakPoint = null;//146455

                        for (int k = 0; k < originChargesInfoSize; k++) {
                            chargeInfo = (MultiQuoteChargeInfo) originChargeInfo.get(k);
                            if (k == 0) {
                                if ("B".equalsIgnoreCase(chargesDOB.getSellBuyFlag())
                                        || "S".equalsIgnoreCase(chargesDOB.getSellBuyFlag()))//||"BC".equalsIgnoreCase(chargesDOB.getSellBuyFlag())||"SC".equalsIgnoreCase(chargesDOB.getSellBuyFlag())) // Added by Gowtham
                                    chk = new Chunk(
                                            chargesDOB.getExternalName() != null ? chargesDOB.getExternalName()
                                                    : "",
                                            FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                else
                                    chk = new Chunk(
                                            chargesDOB.getChargeDescriptionId() != null
                                                    ? chargesDOB.getChargeDescriptionId()
                                                    : "",
                                            FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));

                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                cell.setBorder(1);
                                cell.setRowspan(originChargesInfoSize);
                                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                cell.setVerticalAlignment(cell.ALIGN_LEFT);
                                cell.setBorderWidthTop(0);
                                cell.setBorderWidthBottom(0.1f);
                                if (lc == originChargesSize - 1 && k == originChargesInfoSize - 1) {
                                    cell.setBorderWidthBottom(0.1f);
                                    cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);

                                } else if (k == originChargesInfoSize - 1) {
                                    cell.setBorderWidthBottom(0.1f);
                                    cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                    //cell.setBorderWidthBottom(0.1f);                            
                                } else {
                                    cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    //cell.setVerticalAlignment(cell.ALIGN_CENTER);

                                }
                                chargeCountry.addCell(cell);

                            }
                            /* else if (k==originChargesInfoSize-1) 
                             {
                               cell = new Cell(new Phrase(new Chunk("")));
                             //  cell.setLeading(15.0f);
                               //cell.setBorder(Rectangle.BOTTOM);
                            // cell.setCellEvent(border);                        
                               if(lc!=originChargesSize-1){
                               cell.setBorder(0);
                               cell.setBorderWidth(0f);
                               }    
                               else{
                                  cell.setBorderWidthBottom(0.1f);  
                                      
                               }
                             cell.setHorizontalAlignment(cell.ALIGN_BOTTOM);
                                      
                            cell.setVerticalAlignment(cell.ALIGN_CENTER);
                             chargeCountry.addCell(cell);
                                    
                             }*/

                            /*else{
                               cell = new Cell(new Phrase(new Chunk("")));
                              //cell.setBorder(0);
                               //cell.setCellEvent(border); 
                              cell.setBorder(0);
                                 cell.setBorderWidth(0f);
                                // cell.setLeading(15.0f);
                               cell.setHorizontalAlignment(cell.ALIGN_BOTTOM);
                                     
                              cell.setVerticalAlignment(cell.ALIGN_CENTER);
                                     
                              chargeCountry.addCell(cell);
                                       
                            }*/
                            //@@ Commented by subrahmanyam for 146455 on 19/02/09
                            /* chk = new Chunk((chargeInfo.getBreakPoint()!=null && !"Absolute".equalsIgnoreCase(chargeInfo.getBreakPoint()) && !"Percent".equalsIgnoreCase(chargeInfo.getBreakPoint()))?chargeInfo.getBreakPoint().toUpperCase():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                             cell = new Cell(chk);cell.setLeading(8.0f);
                             cell.setBackgroundColor(Color.lightGray);
                             cell.setHeader(true);
                             chargeCountry.addCell(cell);*/
                            //@@ Added by subrahmanyam for 146455 on 19/02/09                      

                            if (chargeInfo.getBreakPoint().equalsIgnoreCase("MIN")) {
                                breakPoint = "Min";
                            }

                            else if (chargeInfo.getBreakPoint().equalsIgnoreCase("FLAT")) {
                                breakPoint = "Flat";
                            }

                            else if (chargeInfo.getBreakPoint().equalsIgnoreCase("MAX")) {
                                breakPoint = "Max";
                            } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("CSF")) {
                                breakPoint = "Absolute";
                            } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("SURCHARGE")) {
                                breakPoint = "Percent";
                            } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("BASE")) {
                                breakPoint = "Base";
                            }

                            else {
                                breakPoint = chargeInfo.getBreakPoint();
                            }

                            //chk = new Chunk(breakPoint!=null&& !"Absolute".equalsIgnoreCase(breakPoint)&&!"Percent".equalsIgnoreCase(breakPoint)?breakPoint:"",FontFactory.getFont("ARIAL", 7, Font.NORMAL,Color.BLACK)); Commented by silpa for not displaying the abslute brak in pdf
                            chk = new Chunk(breakPoint != null ? breakPoint : "",
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//added by silpa.p on 16-06-11
                            cell = new Cell(new Phrase(chk));
                            cell.setLeading(7.0f);
                            if (k == originChargesInfoSize - 1) {
                                //cell.setBorder(Rectangle.ALIGN_CENTER);
                                // cell.setCellEvent(border); 
                                //  cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            } else {
                                ;
                                //cell.setBorder(0);
                                //cell.setCellEvent(border); 
                                // cell.setBorder(Rectangle.ALIGN_CENTER);                          
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            }

                            chargeCountry.addCell(cell);
                            //   @@ Ended by subrahmanyam for 146455 on 19/02/09                

                            chk = new Chunk(chargeInfo.getCurrency(),
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                            cell = new Cell(new Phrase(chk));
                            cell.setLeading(7.0f);
                            if (k == originChargesInfoSize - 1) {
                                //cell.setBorder(Rectangle.BOTTOM);
                                // cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            } else {
                                //cell.setBorder(0);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            }
                            chargeCountry.addCell(cell);

                            chk = new Chunk(
                                    df.format(chargeInfo.getSellRate())
                                            + (chargeInfo.isPercentValue() ? " %" : ""),
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                            cell = new Cell(new Phrase(chk));
                            cell.setLeading(7.0f);
                            if (k == originChargesInfoSize - 1) {
                                //cell.setBorder(Rectangle.BOTTOM);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            } else {
                                //cell.setBorder(0);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            }
                            chargeCountry.addCell(cell);

                            chk = new Chunk(chargeInfo.getBasis() != null ? chargeInfo.getBasis() : "",
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                            cell = new Cell(new Phrase(chk));
                            cell.setLeading(7.0f);
                            if (k == originChargesInfoSize - 1) {
                                //cell.setBorder(Rectangle.BOTTOM);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                            } else {
                                //cell.setBorder(0);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                            }
                            chargeCountry.addCell(cell);

                            //@@Added by Kameswari for the WPBN issue- on 12/11/08
                            chk = new Chunk(chargeInfo.getRatio() != null ? "1:" + chargeInfo.getRatio() : "",
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                            cell = new Cell(new Phrase(chk));
                            cell.setLeading(7.0f);
                            if (k == originChargesInfoSize - 1) {
                                //cell.setBorder(Rectangle.BOTTOM);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            } else {
                                //cell.setBorder(0);
                                //cell.setCellEvent(border); 
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                            }
                            chargeCountry.addCell(cell);

                        }
                    }
                    //}
                }
            }

            if (chargeCountry != null)
                document.add(chargeCountry);

            pTable = new PdfPTable(1);
            pTable.setSpacingAfter(10f);
            pCell = new PdfPCell(new Phrase(new Chunk("")));
            pCell.setBorder(0);
            pTable.addCell(pCell);
            document.add(pTable);

            //} // Added by Gowtham on 01-Feb-2011.
            //@@Added by kiran.v on 31/01/2012 for Wpbn Issue-287659

        }
        pTable = new PdfPTable(1);
        pTable.setSpacingAfter(10f);
        pCell = new PdfPCell(new Phrase(new Chunk("")));
        pCell.setBorder(0);
        pTable.addCell(pCell);

        document.add(pTable);

        // document.newPage();

        // boolean b1 = document.newPage();

        //Freight Charges
        //document.setMargins(10,10,10,10);
        //System.out.println("After         Origin Charges --------------------------------->");

        if (!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())) {
            // Added by Gowtham. to skip in case of quote with charges.
            //Table   chargeCountry1 = null;
            //Cell   cell1         =null;
            int freightChargesSize = 0;
            int freightChargesInfoSize = 0;
            int[] frtIndices = null;
            int tableColwidth = 0; //Added by Gowtham for Landscape Issue.
            String tmpBasis = "";
            int tmpBrkptsize = 0;
            String tmpmultiBrkpt = "";
            int tmpTableWidth = 0;
            String rates = null;
            Double rates1 = 0.00;
            int tmpCount = 0;
            String basis = "";
            String orgDesc = "";
            String destDesc = "";
            String breakpt = "";
            String tmpFreq = "";
            String tmpFreq1 = "";
            int tmpFrCnt = 0; //Added by Gowtham for Landscape Issue
            MultiQuoteChargeInfo viewDOB = null;
            ArrayList chargesInfolist = new ArrayList();
            int[] tmpBrksize = null;

            //QuoteFreightLegSellRates       legCharges       = null;
            // ArrayList                      freightCharges = null;
            ArrayList freightChargeInfo = null;
            int m = 0;
            String breakPoint = null;
            String space = "";
            Table country = null;
            String serviceLevelDesc = "";//Added by silpa on 16-05-2011
            String carrierDesc = "";//Added by silpa on 16-05-2011

            // b2= writer.getPageNumber();
            // int[] frtCellWidths = {15,16,15,15,18,12,25,12,12,20,15}; // Modified by Gowtham on 24Feb2011

            if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");
                remote = home.create();

                chargesInfolist = remote.getChargeInfoDetailsforView(masterDOB.getQuoteId());
                viewDOB = (MultiQuoteChargeInfo) chargesInfolist.get(0);
                tmpBrkptsize = viewDOB.getMultiBreakPoints().length;
                surChargesMap = viewDOB.getSurChragesMap();

            } else {

                surChargesMap = new HashMap<String, String>();
                for (int lane = 0; lane < noOfLanes; lane++) {
                    legCharges = (MultiQuoteFreightLegSellRates) charges.get(lane);
                    freightCharges = legCharges.getFreightChargesList();
                    MultiQuoteChargeInfo tempChargeInfo = freightCharges != null
                            ? (MultiQuoteChargeInfo) freightCharges.get(lane)
                            : null;
                    // tmpBrkptsize =   tempChargeInfo!=null?finalDOB.getMultiQuoteSelectedBreaks().split(",").length:0;

                    String[] breakpoints = tempChargeInfo != null ? tempChargeInfo.getMultiBreakPoints() : null;
                    String[] rateDescs = tempChargeInfo != null ? tempChargeInfo.getMultiRateDescriptions()
                            : null;
                    String chargeDesc = null;

                    for (int i = 0; i < (breakpoints != null ? breakpoints.length : 0); i++) {
                        chargeDesc = rateDescs[i];
                        /*if(chargeDesc!=null && !"-".equals(chargeDesc) && !"A FREIGHT RATE".equals(chargeDesc)){
                           surChargesMap.put(breakpoints[i].length()>=7?breakpoints[i].substring(0, 3):breakpoints[i],chargeDesc.substring(0, chargeDesc.length()-3) );
                        }*/
                        if (!"List".equalsIgnoreCase(finalDOB.getMasterDOB().getMultiquoteweightBrake())) {
                            if (chargeDesc != null && !"-".equals(chargeDesc)
                                    && !"A FREIGHT RATE".equals(chargeDesc)) {
                                if (breakpoints[i].length() >= 7)
                                    surChargesMap.put(breakpoints[i].substring(0, 3),
                                            chargeDesc.substring(0, chargeDesc.length() - 3));
                            }
                        }

                        if ("List".equalsIgnoreCase(finalDOB.getMasterDOB().getMultiquoteweightBrake())) {
                            if (chargeDesc != null && !"-".equals(chargeDesc)
                                    && !"A FREIGHT RATE".equals(chargeDesc)) {
                                if (breakpoints[i].length() > 4 && breakpoints[i].length() < 10)
                                    surChargesMap.put(breakpoints[i].substring(4, 7),
                                            chargeDesc.substring(0, chargeDesc.length() - 3));
                            }
                        }
                    }
                }

                legCharges = (MultiQuoteFreightLegSellRates) charges.get(0);
                freightCharges = legCharges.getFreightChargesList();
                MultiQuoteChargeInfo tempChargeInfo = freightCharges != null
                        ? (MultiQuoteChargeInfo) freightCharges.get(0)
                        : null;
                tmpBrkptsize = tempChargeInfo != null ? finalDOB.getMultiQuoteSelectedBreaks().split(",").length
                        : 0;

                tmpBrksize = new int[tmpBrkptsize];
                int tmpBrk = 0;
                for (int frtCnt1 = 0; frtCnt1 < tmpBrkptsize; frtCnt1++) {
                    tmpBrk = Integer.parseInt(finalDOB.getMultiQuoteSelectedBreaks().split(",")[frtCnt1]);
                    //if("Y".equalsIgnoreCase(tempChargeInfo.getChecked_Flag().split(",")[frtCnt1]))
                    //{ 
                    tmpBasis = tmpBasis != "" ? (tmpBasis + tempChargeInfo.getBasis().split(",")[tmpBrk] + ",")
                            : (tempChargeInfo.getBasis().split(",")[tmpBrk] + ",");
                    tmpmultiBrkpt = tmpmultiBrkpt != ""
                            ? (tmpmultiBrkpt + tempChargeInfo.getMultiBreakPoints()[tmpBrk] + ",")
                            : (tempChargeInfo.getMultiBreakPoints()[tmpBrk] + ",");
                    tmpBrksize[frtCnt1] = tmpBrk;
                    // tmpTableWidth++;
                    // }
                }
            }

            /* if("Add".equalsIgnoreCase(request.getParameter("Operation"))||"Modify".equalsIgnoreCase(request.getParameter("Operation"))||"Copy".equalsIgnoreCase(request.getParameter("Operation")))
             {      
                     
             tableColwidth = tmpBrkptsize;
                     
             }
             else
             tableColwidth =  tmpBrkptsize;*/

            // tableColwidth = tmpBrkptsize + 4;   //added by silpa.p on 16-05-11//commented by silpa.p on 23-06-11
            tableColwidth = tmpBrkptsize + 5; //added by silpa.p on 23-06-11 for currency add
            //@@Modified by kiran on 10/08/2011 for WPBN Issue-258778
            // 09/11/2011
            if ("add".equalsIgnoreCase(operation) || "modify".equalsIgnoreCase(operation)
                    || "Copy".equalsIgnoreCase(operation)) {
                if ("checked".equalsIgnoreCase(request.getParameter("selectCarrier"))) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectService"))) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectFrequecy"))) {
                    tableColwidth = tableColwidth + 1;
                }
                //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                if ("checked".equalsIgnoreCase(request.getParameter("selectTransitTime"))) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectFrieghtValidity"))) {
                    tableColwidth = tableColwidth + 1;
                }
            } else {
                if ("checked".equalsIgnoreCase(request.getParameter("selectCarrier"))
                        || "Y".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getCarrierChecked() : "N")
                        || "on".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getCarrierChecked() : "")) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectService"))
                        || "Y".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getServiceChecked() : "N")
                        || "on".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getServiceChecked() : "")) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectFrequecy"))
                        || "Y".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getFrequencyChecked() : "N")
                        || "on".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getFrequencyChecked()
                                        : "")) {
                    tableColwidth = tableColwidth + 1;
                }
                //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                if ("checked".equalsIgnoreCase(request.getParameter("selectTransitTime"))
                        || "Y".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getTransitTimeChecked()
                                        : "N")
                        || "on".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getTransitTimeChecked()
                                        : "")) {
                    tableColwidth = tableColwidth + 1;
                }
                if ("checked".equalsIgnoreCase(request.getParameter("selectFrieghtValidity"))
                        || "Y".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getRateValidityChecked()
                                        : "N")
                        || "on".equalsIgnoreCase(
                                multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getRateValidityChecked()
                                        : "")) {
                    tableColwidth = tableColwidth + 1;
                }
            }
            //@@Ended by kiran.v
            int[] frtCellWidths = new int[tableColwidth];//modified by silpa.p 0n 16-05-11
            for (int frtcnt = 0; frtcnt < tableColwidth; frtcnt++)//modified by silpa.p 0n 16-05-11
            {
                frtCellWidths[frtcnt] = 10;
            }
            if (noOfLanes > 0) {

                //if( originChargesSize >0)
                //document.newPage(); 
                //document.add(horizontalLine);
                frtHeader = new Table(1);
                frtHeader.setWidth(100);
                frtHeader.setBackgroundColor(Color.white);
                frtHeader.setBorderColor(Color.BLACK);
                //frtHeader.setBorder(Rectangle.TOP);
                frtHeader.setBorderWidth(1f);
                frtHeader.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
                frtHeader.setPadding(1);
                frtHeader.setSpacing(1);
                frtHeader.setTableFitsPage(true);

                chk = new Chunk("FREIGHT CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cell1 = new Cell(chk);
                cell1.setLeading(10.0f);
                cell1.setBorder(0);
                cell1.setBackgroundColor(Color.ORANGE);//modified by silpa.p on 3-06-11
                frtHeader.addCell(cell1);
                document.add(frtHeader);
                //document.add(horizontalLine);
                chargeCountry2 = new PdfPTable(tableColwidth);//modified by silpa.p on 16-05-11
                chargeCountry2.setWidthPercentage(100);
                chargeCountry2.setWidths(frtCellWidths);

                /*chargeCountry.setPadding(1);
                chargeCountry.setSpacing(0);
                chargeCountry.setOffset(5);*/

                /*
                cell = new PdfPCell(new Phrase(new Chunk("")));
                 cell.setBorder(Rectangle.BOTTOM);
                cell.setCellEvent(border); 
                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                chargeCountry.addCell(cell);*/

                /* chargeCountry.setBackgroundColor(Color.WHITE);
                 chargeCountry.setBorderColor(Color.white);
                 chargeCountry.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
                 //chargeCountry.setBorderWidth(1f);
                 chargeCountry.setTableFitsPage(true);//@@Added by kameswari 
                */
                if (!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())) {//Added by Anil.k
                    //for(int i=0;i<noOfLanes;i++)//testttttttttttinggggggggg

                    legCharges = (MultiQuoteFreightLegSellRates) charges.get(0);
                    freightCharges = legCharges.getFreightChargesList();

                    freightChargesSize = freightCharges.size();//No of rates per lane
                    //Added By Kishore Podili (this change was over rided)
                    if ("View".equalsIgnoreCase(request.getParameter("Operation")))
                        freightChargesSize = chargesInfolist.size();

                    //added by silpa.p on 16-05-11
                    //ended                      
                    if (freightChargesSize > 0) {

                        chk = new Chunk("Origin",
                                FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                        chk = new Chunk("Destination",
                                FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);
                        System.out.println("operation" + operation);
                        //@@Modified by kiran on 10/08/2011 for WPBN Issue-258778
                        // 09/11/2011
                        if ("add".equalsIgnoreCase(operation) || "modify".equalsIgnoreCase(operation)
                                || "Copy".equalsIgnoreCase(operation)) {
                            if ("checked".equalsIgnoreCase(carrierChecked)) {//added by silpa.p on 14-05-11
                                chk = new Chunk("Carrier",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            } //ended

                            if ("checked".equalsIgnoreCase(serviceLevelChecked)) {//added by silpa.p on 14-05-11
                                chk = new Chunk("Service level",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                // serviceflag=true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            } //ended
                            if ("checked".equalsIgnoreCase(frequencyChecked)) {//added by silpa.p on 16-05-11
                                chk = new Chunk("Frequency",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                // frequencyflag=true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            if ("checked".equalsIgnoreCase(transitTimeChecked)) {
                                chk = new Chunk("TransitTime",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                // frequencyflag=true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(validityChecked)) {
                                chk = new Chunk("FreightValidity",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                // frequencyflag=true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        } else {
                            if ("checked".equalsIgnoreCase(carrierChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())) {//added by silpa.p on 14-05-11
                                chk = new Chunk("Carrier",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                carrierFlag = true;
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            } //ended
                            if ("checked".equalsIgnoreCase(serviceLevelChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getServiceChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getServiceChecked())) {//added by silpa.p on 14-05-11
                                chk = new Chunk("Service level",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                serviceflag = true;
                                serviceFlag = true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            } //ended
                            if ("checked".equalsIgnoreCase(frequencyChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())) {//added by silpa.p on 16-05-11
                                chk = new Chunk("Frequency",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                frequencyflag = true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            if ("checked".equalsIgnoreCase(transitTimeChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())) {
                                chk = new Chunk("TransitTime",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                transittimeflag = true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(validityChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())) {
                                chk = new Chunk("FreightValidity",
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                freightValidity = true;
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        }
                        //@@ Ended by kiran.v
                        chk = new Chunk("Incoterms",
                                FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);
                        //added by silpa.p on 23-06-11 for currency add
                        chk = new Chunk("Currency",
                                FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);//ended

                        if ("Add".equalsIgnoreCase(request.getParameter("Operation"))
                                || "Modify".equalsIgnoreCase(request.getParameter("Operation"))
                                || "Copy".equalsIgnoreCase(request.getParameter("Operation"))) {
                            for (int brk1 = 0; brk1 < tmpBrkptsize; brk1++) {

                                if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("MIN")) {
                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "MIN" + "\n" + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "MIN";
                                    else
                                        breakpt = "MIN";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("BASIC")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "BASIC" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "BASIC";
                                    else
                                        breakpt = "BASIC";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("FLAT")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "FLAT" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt ="FLAT";
                                    else
                                        breakpt = "FLAT";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("ABSOLUTE")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 10)
                                        breakpt = "ABSOLUTE" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "ABSOLUTE";
                                    else
                                        breakpt = "ABSOLUTE";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("PERCENT")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 10)
                                        breakpt = "PERCENT" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "PERCENT";
                                    else
                                        breakpt = "PERCENT";
                                } else if (isInteger(tmpmultiBrkpt.split(",")[brk1])
                                        || isDouble(tmpmultiBrkpt.split(",")[brk1])) {
                                    breakpt = tmpmultiBrkpt.split(",")[brk1];
                                } else
                                    breakpt = tmpmultiBrkpt
                                            .split(",")[brk1] != null
                                                    ? (tmpmultiBrkpt.split(",")[brk1].length() > 5
                                                            ? tmpmultiBrkpt.split(",")[brk1].substring(0, 4)
                                                                    + "\n"
                                                                    + tmpmultiBrkpt.split(",")[brk1].substring(
                                                                            4,
                                                                            tmpmultiBrkpt.split(",")[brk1]
                                                                                    .length() - 2)
                                                            : tmpmultiBrkpt.split(",")[brk1])
                                                    : "";
                                basis = tmpBasis.split(",")[brk1] != null ? tmpBasis.split(",")[brk1] : "";

                                //chk = new Chunk(breakpt+"\n"+basis,FontFactory.getFont("Courier-Bold ", 8, Font.BOLD,Color.BLACK));
                                chk = new Chunk(breakpt,
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        } else {
                            for (int t = 0; t < tmpBrkptsize; t++) {
                                if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("MIN")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "MIN" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "MIN";
                                    else
                                        breakpt = "MIN";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("BASIC")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "BASIC" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "BASIC";
                                    else
                                        breakpt = "BASIC";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("FLAT")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "FLAT" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "FLAT";

                                    else
                                        breakpt = "FLAT";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase()
                                        .endsWith("ABSOLUTE")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 10)
                                        breakpt = "ABSOLUTE" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "ABSOLUTE";
                                    else
                                        breakpt = "ABSOLUTE";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("PERCENT")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "PERCENT" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "PERCENT";
                                    else
                                        breakpt = "PERCENT";
                                } else
                                    breakpt = viewDOB.getMultiBreakPoints()[t] != null
                                            ? (viewDOB.getMultiBreakPoints()[t].length() > 5
                                                    ? viewDOB.getMultiBreakPoints()[t].substring(0, 4) + "\n"
                                                            + viewDOB.getMultiBreakPoints()[t].substring(4,
                                                                    viewDOB.getMultiBreakPoints()[t].length()
                                                                            - 2)
                                                    : viewDOB.getMultiBreakPoints()[t])
                                            : "";

                                //chk = new Chunk(breakpt+"\n"+viewDOB.getBasis().split(",")[t],FontFactory.getFont("Courier-Bold ", 8, Font.BOLD,Color.BLACK));
                                chk = new Chunk(breakpt,
                                        FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            }
                        }

                        chk = new Chunk("Density Ratio",
                                FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                    }

                    //added by silpa.p on 16-05-11 for adding new line for pdf
                    if (freightChargesSize > 0) {

                        chk = new Chunk("", FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);
                        chk = new Chunk("", FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        //@@ Modified by kiran.v on 28/08/2011 for Wpbn Issue -258778
                        // 09/11/2011
                        if ("add".equalsIgnoreCase(operation) || "modify".equalsIgnoreCase(operation)
                                || "Copy".equalsIgnoreCase(operation)) {
                            if ("checked".equalsIgnoreCase(carrierChecked)) {//added by silpa.p on 14-05-11
                                chk = new Chunk("",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }

                            if ("checked".equalsIgnoreCase(serviceLevelChecked)) {//added by silpa.p on 14-05-11
                                chk = new Chunk("",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            }
                            if ("checked".equalsIgnoreCase(frequencyChecked)) {//added by silpa.p on 16-05-11
                                chk = new Chunk("",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            if ("checked".equalsIgnoreCase(transitTimeChecked)) {
                                chk = new Chunk("",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(validityChecked)) {
                                chk = new Chunk("",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        } else {
                            if ("Y".equalsIgnoreCase(
                                    multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getCarrierChecked()
                                            : "N")
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo != null
                                            ? multiQuoteChargeInfo.getCarrierChecked()
                                            : "")) {//added by silpa.p on 14-05-11
                                chk = new Chunk(" ",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }

                            if ("Y".equalsIgnoreCase(
                                    multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getServiceChecked()
                                            : "N")
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo != null
                                            ? multiQuoteChargeInfo.getServiceChecked()
                                            : "")) {//added by silpa.p on 14-05-11
                                chk = new Chunk(" ",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            }
                            if ("Y".equalsIgnoreCase(
                                    multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getFrequencyChecked()
                                            : "N")
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo != null
                                            ? multiQuoteChargeInfo.getFrequencyChecked()
                                            : "")) {//added by silpa.p on 16-05-11
                                chk = new Chunk(" ",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            if ("Y".equalsIgnoreCase(
                                    multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getTransitTimeChecked()
                                            : "N")
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo != null
                                            ? multiQuoteChargeInfo.getTransitTimeChecked()
                                            : "")) {
                                chk = new Chunk(" ",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("Y".equalsIgnoreCase(
                                    multiQuoteChargeInfo != null ? multiQuoteChargeInfo.getRateValidityChecked()
                                            : "N")
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo != null
                                            ? multiQuoteChargeInfo.getRateValidityChecked()
                                            : "")) {
                                chk = new Chunk(" ",
                                        FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        }
                        chk = new Chunk("", FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);
                        //added by silpa.p on 23-06-11 for currency add
                        chk = new Chunk("", FontFactory.getFont("Courier-Bold ", 8, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);//ended

                        if ("Add".equalsIgnoreCase(request.getParameter("Operation"))
                                || "Modify".equalsIgnoreCase(request.getParameter("Operation"))
                                || "Copy".equalsIgnoreCase(request.getParameter("Operation"))) {
                            for (int brk1 = 0; brk1 < tmpBrkptsize; brk1++) {

                                if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("MIN")) {
                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "MIN" + "\n" + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "MIN";
                                    else
                                        breakpt = "MIN";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("BASIC")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "BASIC" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "BASIC";
                                    else
                                        breakpt = "BASIC";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("FLAT")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 7)
                                        breakpt = "FLAT" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt ="FLAT";
                                    else
                                        breakpt = "FLAT";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("ABSOLUTE")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 10)
                                        breakpt = "ABSOLUTE" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "ABSOLUTE";
                                    else
                                        breakpt = "ABSOLUTE";
                                } else if (tmpmultiBrkpt.split(",")[brk1] != null
                                        && tmpmultiBrkpt.split(",")[brk1].toUpperCase().endsWith("PERCENT")) {

                                    if (tmpmultiBrkpt.split(",")[brk1].length() > 10)
                                        breakpt = "PERCENT" + "\n"
                                                + tmpmultiBrkpt.split(",")[brk1].substring(0, 3);
                                    //breakpt = "PERCENT";
                                    else
                                        breakpt = "PERCENT";
                                } else if (isInteger(tmpmultiBrkpt.split(",")[brk1])
                                        || isDouble(tmpmultiBrkpt.split(",")[brk1])) {
                                    breakpt = tmpmultiBrkpt.split(",")[brk1];
                                } else
                                    breakpt = tmpmultiBrkpt
                                            .split(",")[brk1] != null
                                                    ? (tmpmultiBrkpt.split(",")[brk1].length() > 5
                                                            ? tmpmultiBrkpt.split(",")[brk1].substring(0, 4)
                                                                    + "\n"
                                                                    + tmpmultiBrkpt.split(",")[brk1].substring(
                                                                            4,
                                                                            tmpmultiBrkpt.split(",")[brk1]
                                                                                    .length() - 2)
                                                            : tmpmultiBrkpt.split(",")[brk1])
                                                    : "";
                                basis = tmpBasis.split(",")[brk1] != null ? tmpBasis.split(",")[brk1] : "";

                                //chk = new Chunk(breakpt+"\n"+basis,FontFactory.getFont("Courier-Bold ", 8, Font.BOLD,Color.BLACK));
                                chk = new Chunk(basis,
                                        FontFactory.getFont("Courier-Bold ", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }

                        } else {
                            for (int t = 0; t < tmpBrkptsize; t++) {
                                if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("MIN")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "MIN" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "MIN";
                                    else
                                        breakpt = "MIN";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("BASIC")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "BASIC" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "BASIC";
                                    else
                                        breakpt = "BASIC";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("FLAT")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "FLAT" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "FLAT";

                                    else
                                        breakpt = "FLAT";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase()
                                        .endsWith("ABSOLUTE")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 10)
                                        breakpt = "ABSOLUTE" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "ABSOLUTE";
                                    else
                                        breakpt = "ABSOLUTE";
                                } else if (viewDOB.getMultiBreakPoints()[t].toUpperCase().endsWith("PERCENT")) {
                                    if (viewDOB.getMultiBreakPoints()[t].length() > 7)
                                        breakpt = "PERCENT" + "\n"
                                                + viewDOB.getMultiBreakPoints()[t].substring(0, 3);
                                    //breakpt= "PERCENT";
                                    else
                                        breakpt = "PERCENT";
                                } else
                                    breakpt = viewDOB.getMultiBreakPoints()[t] != null
                                            ? (viewDOB.getMultiBreakPoints()[t].length() > 5
                                                    ? viewDOB.getMultiBreakPoints()[t].substring(0, 4) + "\n"
                                                            + viewDOB.getMultiBreakPoints()[t].substring(4,
                                                                    viewDOB.getMultiBreakPoints()[t].length()
                                                                            - 2)
                                                    : viewDOB.getMultiBreakPoints()[t])
                                            : "";

                                //chk = new Chunk(breakpt+"\n"+viewDOB.getBasis().split(",")[t],FontFactory.getFont("Courier-Bold ", 8, Font.BOLD,Color.BLACK));
                                chk = new Chunk(viewDOB.getBasis().split(",")[t],
                                        FontFactory.getFont("Courier-Bold ", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);

                            }
                        }
                        chk = new Chunk("", FontFactory.getFont("Courier-Bold ", 7, Font.BOLD, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                    } //ended
                    if ("View".equalsIgnoreCase(request.getParameter("Operation")))
                        freightChargesSize = chargesInfolist.size();
                    for (int j = 0; j < freightChargesSize; j++) {
                        if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                            multiQuoteChargeInfo = (MultiQuoteChargeInfo) chargesInfolist.get(j);
                            // multiQuoteChargeInfo         = (MultiQuoteChargeInfo)freightCharges.get(j);
                        } else
                            multiQuoteChargeInfo = (MultiQuoteChargeInfo) freightCharges.get(j);
                        logger.info("Freight Charges doPDFGeneration::" + j + ":" + chargesDOB); // newly added

                        home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");
                        remote = home.create();
                        //orgDesc = remote.getLocationName(multiQuoteChargeInfo.getOrginLoc());//Commented by silpa.p on 5-07-11
                        orgDesc = multiQuoteChargeInfo.getOrginLoc();//modified by silpa.p on 5-07-11
                        chk = new Chunk(orgDesc != null ? orgDesc : "",
                                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                        //destDesc = remote.getLocationName(multiQuoteChargeInfo.getDestLoc());//commented by silpa.p on 5-07-11
                        destDesc = multiQuoteChargeInfo.getDestLoc();//modified by silpa.p on 5-07-11

                        chk = new Chunk(destDesc != null ? destDesc : "",
                                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                        // tmpCarrier1 = multiQuoteChargeInfo.getCarrier(); Commented by Gowtham
                        /* if("View".equalsIgnoreCase(request.getParameter("Operation"))&& ("C".equalsIgnoreCase(CarrierChecked)))
                        {     
                        chk = new Chunk(multiQuoteChargeInfo.getCarrier()!=null?multiQuoteChargeInfo.getCarrier():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                        cell = new PdfPCell(new Phrase(chk));
                          cell.setBorder(Rectangle.BOTTOM);
                        cell.setCellEvent(border); 
                        cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry.addCell(cell);
                                
                        }
                        else
                        {
                           if("C".equalsIgnoreCase(CarrierChecked)){
                           chk = new Chunk(multiQuoteChargeInfo.getCarrierName()!=null?multiQuoteChargeInfo.getCarrierName():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                           cell = new PdfPCell(new Phrase(chk));
                             cell.setBorder(Rectangle.BOTTOM);
                           cell.setCellEvent(border); 
                           cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                           chargeCountry.addCell(cell);
                           }
                        }*/ //carrierDesc = remote.getServiceLevelName(multiQuoteChargeInfo.getServiceLevel());
                        //@@Added by kiran.v on 01/08/2011 for Wpbn Issue 258778
                        carrierDesc = multiQuoteChargeInfo.getCarrier();
                        Cd.add(carrierDesc);
                        String carrierName = remote.getCarrierName(multiQuoteChargeInfo.getCarrier());
                        Cdn.add(carrierName);
                        //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                        String time = multiQuoteChargeInfo.getTransitTime();
                        //Cdn.add(multiQuoteChargeInfo.getCarrierName());
                        // carrierDesc = remote.getCarrierName(multiQuoteChargeInfo.getCarrier());//added by silpa.p on 16-05-11
                        if ("View".equalsIgnoreCase(request.getParameter("Operation")))
                            //chk = new Chunk(multiQuoteChargeInfo.getCarrierName()!=null?multiQuoteChargeInfo.getCarrierName():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            chk = new Chunk(carrierDesc != null ? carrierDesc : "",
                                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//modified by silpa.p on 16-05-11
                        //@@Modified by kiran on 10/08/2011 for WPBN Issue-258778
                        // 09/11/2011
                        if ("add".equalsIgnoreCase(operation) || "modify".equalsIgnoreCase(operation)
                                || "Copy".equalsIgnoreCase(operation)) {
                            if ("checked".equalsIgnoreCase(carrierChecked)) {//added by silpa.p on 14-05-11                            
                                // chk = new Chunk(multiQuoteChargeInfo.getCarrier()!=null?multiQuoteChargeInfo.getCarrier():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(carrierDesc != null ? carrierDesc : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            } //ended
                            //@@Added by kiran.v on 01/08/2011 for Wpbn Issue 258778
                            serviceLevelDesc = multiQuoteChargeInfo.getServiceLevel();

                            Sd.add(serviceLevelDesc);
                            // serviceLevelDesc = remote.getServiceLevelName(multiQuoteChargeInfo.getServiceLevel());//added by silpa.p on 16-05-11
                            //tmpServl1=multiQuoteChargeInfo.getServiceLevel(); Commented by Gowtham
                            if ("checked".equalsIgnoreCase(serviceLevelChecked)) {//added by silpa.p on 14-05-11
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(serviceLevelDesc != null ? serviceLevelDesc : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//modified by silpa.p on 16-05-11
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(frequencyChecked)) {//added by silpa.p on 16-05-11
                                tmpFrCnt = multiQuoteChargeInfo.getFrequency() != null
                                        ? multiQuoteChargeInfo.getFrequency().split(",").length
                                        : 0;
                                if (tmpFrCnt > 1) {
                                    for (int tmpFc = 0; tmpFc < tmpFrCnt; tmpFc++) {
                                        if ("1".equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Mon";
                                        else if ("2"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Tue";
                                        else if ("3"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Wed";
                                        else if ("4"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Thr";
                                        else if ("5"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Fri";
                                        else if ("6"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Sat";
                                        else if ("7"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Sun";
                                        if (tmpFc == tmpFrCnt - 1)
                                            tmpFreq1 = tmpFreq1 + tmpFreq;
                                        else
                                            tmpFreq1 = tmpFreq1 + tmpFreq + ",";
                                    }
                                } else if (multiQuoteChargeInfo.getFrequency() != null
                                        && isInteger(multiQuoteChargeInfo.getFrequency())) {
                                    if ("1".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Mon";
                                    else if ("2".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Tue";
                                    else if ("3".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Wed";
                                    else if ("4".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Thr";
                                    else if ("5".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Fri";
                                    else if ("6".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Sat";
                                    else if ("7".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Sun";
                                } else
                                    tmpFreq1 = multiQuoteChargeInfo.getFrequency() != null
                                            ? multiQuoteChargeInfo.getFrequency()
                                            : "";

                                chk = new Chunk(tmpFreq1 != null ? tmpFreq1 : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            String time1 = multiQuoteChargeInfo.getTransitTime();
                            String validity = multiQuoteChargeInfo.getRateValidity();
                            if ("checked".equalsIgnoreCase(transitTimeChecked)) {
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(time1 != null ? time1 : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(validityChecked)) {
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(validity != null ? validity : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        } else {
                            if ("checked".equalsIgnoreCase(carrierChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getCarrierChecked())
                                    || carrierFlag) {//added by silpa.p on 14-05-11                            
                                // chk = new Chunk(multiQuoteChargeInfo.getCarrier()!=null?multiQuoteChargeInfo.getCarrier():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(carrierDesc != null ? carrierDesc : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            } //ended
                              //@@Added by kiran.v on 01/08/2011 for Wpbn Issue 258778
                            serviceLevelDesc = multiQuoteChargeInfo.getServiceLevel();

                            Sd.add(serviceLevelDesc);
                            // serviceLevelDesc = remote.getServiceLevelName(multiQuoteChargeInfo.getServiceLevel());//added by silpa.p on 16-05-11
                            //tmpServl1=multiQuoteChargeInfo.getServiceLevel(); Commented by Gowtham                     
                            if ("checked".equalsIgnoreCase(serviceLevelChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getServiceChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getServiceChecked())
                                    || serviceflag) {//added by silpa.p on 14-05-11
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(serviceLevelDesc != null ? serviceLevelDesc : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//modified by silpa.p on 16-05-11
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            if ("checked".equalsIgnoreCase(frequencyChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getFrequencyChecked())
                                    || frequencyflag) {//added by silpa.p on 16-05-11
                                tmpFrCnt = multiQuoteChargeInfo.getFrequency() != null
                                        ? multiQuoteChargeInfo.getFrequency().split(",").length
                                        : 0;
                                if (tmpFrCnt > 1) {
                                    for (int tmpFc = 0; tmpFc < tmpFrCnt; tmpFc++) {
                                        if ("1".equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Mon";
                                        else if ("2"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Tue";
                                        else if ("3"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Wed";
                                        else if ("4"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Thr";
                                        else if ("5"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Fri";
                                        else if ("6"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Sat";
                                        else if ("7"
                                                .equals(multiQuoteChargeInfo.getFrequency().split(",")[tmpFc]))
                                            tmpFreq = "Sun";
                                        if (tmpFc == tmpFrCnt - 1)
                                            tmpFreq1 = tmpFreq1 + tmpFreq;
                                        else
                                            tmpFreq1 = tmpFreq1 + tmpFreq + ",";
                                    }
                                } else if (multiQuoteChargeInfo.getFrequency() != null
                                        && isInteger(multiQuoteChargeInfo.getFrequency())) {
                                    if ("1".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Mon";
                                    else if ("2".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Tue";
                                    else if ("3".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Wed";
                                    else if ("4".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Thr";
                                    else if ("5".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Fri";
                                    else if ("6".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Sat";
                                    else if ("7".equals(multiQuoteChargeInfo.getFrequency()))
                                        tmpFreq1 = "Sun";
                                } else
                                    tmpFreq1 = multiQuoteChargeInfo.getFrequency() != null
                                            ? multiQuoteChargeInfo.getFrequency()
                                            : "";

                                chk = new Chunk(tmpFreq1 != null ? tmpFreq1 : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            //@@Added by kiran.v on 23/09/2011 for Wpbn Issue 272712
                            String time1 = multiQuoteChargeInfo.getTransitTime();
                            if ("checked".equalsIgnoreCase(transitTimeChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getTransitTimeChecked())
                                    || transittimeflag) {
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(time1 != null ? time1 : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                            String validity = multiQuoteChargeInfo.getRateValidity();

                            if ("checked".equalsIgnoreCase(validityChecked)
                                    || "Y".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())
                                    || "on".equalsIgnoreCase(multiQuoteChargeInfo.getRateValidityChecked())
                                    || freightValidity) {
                                //chk = new Chunk(multiQuoteChargeInfo.getServiceLevel()!=null?multiQuoteChargeInfo.getServiceLevel():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(validity != null ? validity : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell2 = new PdfPCell(new Phrase(chk));
                                cell2.setBorder(Rectangle.BOTTOM);
                                cell2.setCellEvent(border);
                                cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry2.addCell(cell2);
                            }
                        }
                        //@@Ended by kiran.v
                        chk = new Chunk((multiQuoteChargeInfo.getIncoTerms() != null
                                ? multiQuoteChargeInfo.getIncoTerms()
                                : ""), FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);
                        //added by silpa.p on 23-06-11 for currency add
                        if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                            chk = new Chunk((multiQuoteChargeInfo.getCurrency() != null
                                    ? multiQuoteChargeInfo.getCurrency()
                                    : ""), FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        } else {
                            chk = new Chunk((multiQuoteChargeInfo.getCurrency() != null
                                    ? multiQuoteChargeInfo.getCurrency()
                                    : ""), FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        }
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);//ended

                        for (int trc = 0; trc < tmpBrkptsize; trc++) {
                            if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                                rates1 = Double.parseDouble(multiQuoteChargeInfo.getMultiBuyRates()[trc]);
                                rates = ("0.00".equals(rates1.toString()) || "0".equals(rates1.toString()))
                                        ? "-"
                                        : rates1.toString();
                            } else
                                rates = multiQuoteChargeInfo.getMultiCalSellRates()[tmpBrksize[trc]] != null
                                        ? ("0.00".equals(
                                                multiQuoteChargeInfo.getMultiCalSellRates()[tmpBrksize[trc]])
                                                || ("0".equals(multiQuoteChargeInfo
                                                        .getMultiCalSellRates()[tmpBrksize[trc]]))
                                                                ? "-"
                                                                : multiQuoteChargeInfo
                                                                        .getMultiCalSellRates()[tmpBrksize[trc]])
                                        : "0.00";//modified by silpa.p on 3-06-11

                            chk = new Chunk(rates, FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                            cell2 = new PdfPCell(new Phrase(chk));
                            cell2.setBorder(Rectangle.BOTTOM);
                            cell2.setCellEvent(border);
                            cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                            chargeCountry2.addCell(cell2);
                        }

                        chk = new Chunk(
                                multiQuoteChargeInfo.getRatio() != null ? "1:" + multiQuoteChargeInfo.getRatio()
                                        : "",
                                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                        cell2 = new PdfPCell(new Phrase(chk));
                        cell2.setBorder(Rectangle.BOTTOM);
                        cell2.setCellEvent(border);
                        cell2.setHorizontalAlignment(cell.ALIGN_CENTER);
                        chargeCountry2.addCell(cell2);

                        tmpFreq1 = "";
                    }
                    //02Mar11
                }

                document.add(chargeCountry2);

            } //end of if(charge)
              //document.newPage();

        } // Added by Gowtham. to skip in case of quote with charges.

        pTable = new PdfPTable(1);
        pTable.setSpacingAfter(20f);
        pCell = new PdfPCell(new Phrase(new Chunk("")));
        pCell.setBorder(0);
        pTable.addCell(pCell);

        document.add(pTable);

        ArrayList destChargeInfo = null;
        //Destination
        MultiQuoteChargeInfo chargeInfo1 = null;
        ArrayList destLaneCharges = finalDOB.getLegDetails();//.get(0)).getOriginChargesList();

        for (int dc = 0; dc < noOfLanes; dc++) {
            legDestCharges = (MultiQuoteFreightLegSellRates) destLaneCharges.get(dc);
            ArrayList destCharges = legDestCharges.getDestChargesList();
            int[] destIndices = legDestCharges.getSelctedDestChargesListIndices();
            int destChargesSize = 0;
            String breakPoint = "";
            if (destIndices != null)
                destChargesSize = destIndices.length;
            else
                destChargesSize = 0;

            int destChargesInfoSize = 0;
            if (destChargesSize > 0) { //document.newPage();  
                //document.add(horizontalLine);
                chargeTitle = new Table(1);
                chargeTitle.setWidth(100);
                chargeTitle.setPadding(1);
                chargeTitle.setSpacing(1);
                chargeTitle.setBorderColor(Color.BLACK);
                chargeTitle.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
                chargeTitle.setBackgroundColor(Color.ORANGE);//modified by silpa.p on 3-06-11
                chargeTitle.setBorderWidth(1f);

                home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");
                remote = home.create();
                if (legOrginCharges.getShipmentMode() == 2
                        && !"Charges".equalsIgnoreCase(masterDOB.getQuoteWith()))//added by silpa.p on 16-06-11
                {
                    chk = new Chunk(
                            (legDestCharges.getDestination() != null
                                    ? remote.getPortName(legDestCharges.getDestination())
                                    : "") + "-Destination Charges",
                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK)); // Added by Gowtham on 01-Feb-2011.   
                } else
                    chk = new Chunk(
                            (legDestCharges.getDestination() != null
                                    ? remote.getLocationName(legDestCharges.getDestination())
                                    : "") + "-Destination Charges",
                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));// Added by Gowtham on 01-Feb-2011.
                cell1 = new Cell(chk);

                cell1.setLeading(10.0f);
                cell1.setBackgroundColor(Color.WHITE);
                cell1.setHeader(true);
                cell1.setBorder(0);
                cell1.setBackgroundColor(Color.ORANGE);//modified by silpa.p on 3-06-11
                chargeTitle.addCell(cell1);
                //document.newPage();
                document.add(chargeTitle);

                //document.add(horizontalLine);

                /* chargeCountry1  = new Table(6);
                 chargeCountry1.setWidth(100);
                 chargeCountry1.setWidths(cellWidths);
                 chargeCountry1.setPadding(1);
                 chargeCountry1.setSpacing(0);
                 chargeCountry1.setOffset(5);
                 chargeCountry1.setBackgroundColor(Color.WHITE);
                 chargeCountry1.setBorderColor(Color.WHITE);
                 chargeCountry1.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
                 chargeCountry1.setBorderWidth(1f);
                 chargeCountry1.setTableFitsPage(true);*/

                chargeTitle.setWidth(100);
                chargeTitle.setBorderWidth(1f);

                chargeCountry = new Table(6);
                chargeCountry.setWidths(cellWidths);
                //chargeCountry.setWidthPercentage(100);
                chargeCountry.setPadding(3);
                chargeCountry.setSpacing(0);
                chargeCountry.setWidths(cellWidths);
                chargeCountry.setBorder(1);
                chargeCountry.setWidth(100);
                chargeCountry.setBorderWidth(1f);
                /* home        = (QMSMultiQuoteSessionHome)LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");//146460
                remote      = home.create();
                 if(legOrginCharges.getShipmentMode()==2)
                 {       
                 chk = new Chunk((legDestCharges.getDestination()!=null?remote.getPortName(legDestCharges.getDestination()):"")+"-Destination Charges",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK)); // Added by Gowtham on 01-Feb-2011.   
                 }
                 else
                chk = new Chunk((legDestCharges.getDestination()!=null ? remote.getLocationName(legDestCharges.getDestination()):"")+"-Destination Charges",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));// Added by Gowtham on 01-Feb-2011.
                cell = new Cell(chk);
                        
                cell.setLeading(10.0f);
                cell.setBackgroundColor(Color.ORANGE);                
                cell.setHeader(true);
                chargeCountry.addCell(cell);*/
                chk = new Chunk("Charge Description", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                chargeCountry.addCell(cell);

                chk = new Chunk("Weight Break Slab", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                chargeCountry.addCell(cell);

                chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                chargeCountry.addCell(cell);

                chk = new Chunk("Charge Rate", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                chargeCountry.addCell(cell);

                chk = new Chunk("Basis", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                chargeCountry.addCell(cell);

                chk = new Chunk("Density Ratio", FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cell = new Cell(new Phrase(chk));
                ////cell.setBorder(Rectangle.BOTTOM);
                cell.setBorderWidth(1);
                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                chargeCountry.addCell(cell);

                for (int dcc = 0; dcc < destChargesSize; dcc++) {
                    if ((operation != null && operation.equals("View")) || ("Y"
                            .equalsIgnoreCase(legDestCharges.getDestChargesSelectedFlag()[destIndices[dcc]])))//modified by silpa.p on 21-06-11
                    {

                        chargesDOB = (MultiQuoteCharges) destCharges.get(destIndices[dcc]);

                        //  for(int j=0;j<destChargesSize;j++)
                        //{
                        if (destIndices[dcc] != -1) {
                            // chargesDOB            = (MultiQuoteCharges)destCharges.get(destIndices[j]);
                            logger.info("Destination Charges doPDFGeneration::" + dcc + ":" + chargesDOB); // newly added                      
                            destChargeInfo = chargesDOB.getChargeInfoList();
                            destChargesInfoSize = destChargeInfo.size();
                            for (int k = 0; k < destChargesInfoSize; k++) {
                                chargeInfo = (MultiQuoteChargeInfo) destChargeInfo.get(k);
                                // if(k==destChargesInfoSize/2 )
                                if (k == 0) {
                                    if ("B".equalsIgnoreCase(chargesDOB.getSellBuyFlag())
                                            || "S".equalsIgnoreCase(chargesDOB.getSellBuyFlag()))
                                        chk = new Chunk(
                                                chargesDOB.getExternalName() != null
                                                        ? chargesDOB.getExternalName()
                                                        : "",
                                                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                    else
                                        chk = new Chunk(
                                                chargesDOB.getChargeDescriptionId() != null
                                                        ? chargesDOB.getChargeDescriptionId()
                                                        : "",
                                                FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));

                                    /*cell1 = new Cell(chk);
                                    cell1.setLeading(9.0f);
                                    //cell.setRowspan(destChargesInfoSize);
                                    //cell.setBorderWidth(0);
                                    //cell.setBackgroundColor(Color.lightGray);
                                    cell1.setBorder(0);
                                    cell1.setHeader(true);       
                                    cell1.setHorizontalAlignment(cell1.ALIGN_LEFT);
                                    chargeCountry1.addCell(cell1)*/;

                                    cell = new Cell(new Phrase(chk));
                                    cell.setLeading(7.0f);
                                    cell.setBorder(1);
                                    cell.setRowspan(destChargesInfoSize);
                                    cell.setBorderWidthTop(0);
                                    cell.setBorderWidthBottom(0.1f);
                                    cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    cell.setVerticalAlignment(cell.ALIGN_LEFT);

                                    if (dcc == destChargesSize - 1 && k == destChargesInfoSize - 1) {
                                        cell.setBorderWidthBottom(0.1f);
                                        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    } else if (k == destChargesInfoSize - 1) {
                                        cell.setBorderWidthBottom(0.1f);
                                        cell.setHorizontalAlignment(cell.ALIGN_LEFT);

                                    } else {
                                        cell.setHorizontalAlignment(cell.ALIGN_LEFT);
                                    }
                                    // cell.setBorderWidthTop(0);
                                    // cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                    chargeCountry.addCell(cell);

                                }
                                /*else if (k==destChargesInfoSize-1) 
                                {
                                   cell = new Cell(new Phrase(new Chunk("")));
                                   ////cell.setBorder(Rectangle.BOTTOM);
                                 ////cell.setCellEvent(border); 
                                   if(dcc!=destChargesSize-1){
                                 cell.setBorder(0);
                                 cell.setBorderWidth(0f);
                                 cell.setLeading(7.0f);
                                   }
                                   else
                                {
                                    cell.setBorder(1);  
                                    cell.setBorderWidthTop(0);
                                    cell.setBorderWidthBottom(0.1f);
                                    cell.setLeading(7.0f);
                                            
                                   }
                                  cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                  chargeCountry.addCell(cell);
                                        
                                }
                                else
                                {
                                     cell = new Cell(new Phrase(new Chunk("")));
                                  ////cell.setBorder(0);
                                  ////cell.setCellEvent(border); 
                                  cell.setBorder(0);
                                     cell.setLeading(7.0f);
                                    cell.setBorderWidth(0f);                                
                                  cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                  chargeCountry.addCell(cell);
                                }*/

                                //@@Commented by subrahmanyam for 146455 on 18/02/09                   
                                /* chk = new Chunk((chargeInfo.getBreakPoint()!=null && !"Absolute".equalsIgnoreCase(chargeInfo.getBreakPoint()) && !"Percent".equalsIgnoreCase(chargeInfo.getBreakPoint()))?chargeInfo.getBreakPoint().toUpperCase():"",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                 cell = new Cell(chk);cell.setLeading(8.0f);
                                 cell.setBackgroundColor(Color.lightGray);
                                 cell.setHeader(true);
                                 chargeCountry.addCell(cell);*/
                                //@@Added by subrahmanyam for 146455 on 18/02/09                        
                                if (chargeInfo.getBreakPoint().equalsIgnoreCase("MIN")) {
                                    breakPoint = "Min";
                                }

                                else if (chargeInfo.getBreakPoint().equalsIgnoreCase("FLAT")) {
                                    breakPoint = "Flat";
                                } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("CSF")) {
                                    breakPoint = "Absolute";
                                } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("SURCHARGE")) {
                                    breakPoint = "Percent";
                                } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("MAX")) {
                                    breakPoint = "Max";
                                } else if (chargeInfo.getBreakPoint().equalsIgnoreCase("BASE")) {
                                    breakPoint = "Base";
                                }

                                else {
                                    breakPoint = chargeInfo.getBreakPoint();
                                }

                                // chk = new Chunk(breakPoint!=null&& !"Absolute".equalsIgnoreCase(breakPoint)&&!"Percent".equalsIgnoreCase(breakPoint)?breakPoint:"",FontFactory.getFont("ARIAL", 7, Font.NORMAL,Color.BLACK));

                                chk = new Chunk(breakPoint != null ? breakPoint : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));//added by silpa.p on 16-06-11
                                /*cell1 = new Cell(chk);cell1.setLeading(8.0f);
                                // cell.setBackgroundColor(Color.lightGray);
                                cell1.setHeader(true);
                                cell1.setBorder(0);
                                  chargeCountry1.addCell(cell1);*/

                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                if (k == destChargesInfoSize - 1) {
                                    ////cell.setBorder(Rectangle.BOTTOM);
                                    ////cell.setCellEvent(border); 

                                } else {
                                    // //cell.setBorder(0);
                                }
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry.addCell(cell);

                                //@@Ended by subrahmanyam for 146455 on 18/02/09   

                                chk = new Chunk(chargeInfo.getCurrency(),
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                if (k == destChargesInfoSize - 1) {
                                    ////cell.setBorder(Rectangle.BOTTOM);
                                    ////cell.setCellEvent(border); 

                                } else {
                                    ////cell.setBorder(0);
                                }
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry.addCell(cell);

                                chk = new Chunk(
                                        df.format(chargeInfo.getSellRate())
                                                + (chargeInfo.isPercentValue() ? " %" : ""),
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                if (k == destChargesInfoSize - 1) {
                                    ////cell.setBorder(Rectangle.BOTTOM);
                                    // //cell.setCellEvent(border); 

                                } else {
                                    ////cell.setBorder(0);
                                }
                                cell.setHorizontalAlignment(cell.ALIGN_CENTER);
                                chargeCountry.addCell(cell);

                                chk = new Chunk(chargeInfo.getBasis() != null ? chargeInfo.getBasis() : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                if (k == destChargesInfoSize - 1) {
                                    ////cell.setBorder(Rectangle.BOTTOM);
                                    ////cell.setCellEvent(border); 

                                } else {
                                    //cell.setBorder(0);
                                }
                                cell.setHorizontalAlignment(cell1.ALIGN_LEFT);
                                chargeCountry.addCell(cell);

                                //@@Added by Kameswari for the WPBN issue- on 12/11/08
                                chk = new Chunk(
                                        chargeInfo.getRatio() != null ? "1:" + chargeInfo.getRatio() : "",
                                        FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                                cell = new Cell(new Phrase(chk));
                                cell.setLeading(7.0f);
                                if (k == destChargesInfoSize - 1) {
                                    ////cell.setBorder(Rectangle.BOTTOM);
                                    //  //cell.setCellEvent(border); 

                                } else {
                                    //cell.setBorder(0);
                                }
                                cell.setHorizontalAlignment(cell1.ALIGN_CENTER);
                                chargeCountry.addCell(cell);
                            }
                        }
                        //}
                    }
                }
                document.add(chargeCountry);
                pTable = new PdfPTable(1);
                pTable.setSpacingAfter(10f);
                pCell = new PdfPCell(new Phrase(new Chunk("")));
                pCell.setBorder(0);
                pTable.addCell(pCell);

                document.add(pTable);
            }

        }
        if (finalDOB.getExternalNotes() != null && finalDOB.getExternalNotes().length > 0) {
            Table notes = new Table(1, finalDOB.getExternalNotes().length + 1);
            notes.setWidth(100);
            notes.setPadding(1);
            notes.setSpacing(1);
            notes.setOffset(5);
            notes.setBackgroundColor(Color.WHITE);
            notes.setBorderColor(Color.black);
            //@@Commented and Modified by Kameswari for the internal issue on 08/04/09
            notes.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
            notes.setBorderWidth(1f);
            Cell notesCell;

            chk = new Chunk("NOTES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            notesCell = new Cell(chk);
            notesCell.setHeader(true);
            notesCell.setLeading(8.0f);
            notesCell.setBackgroundColor(Color.ORANGE);//MODIFIED BY SILPA.P ON 3-06-11
            notes.addCell(notesCell);
            for (int i = 0; i < finalDOB.getExternalNotes().length; i++) {
                if (finalDOB.getExternalNotes()[i] != null
                        && !"".equals(finalDOB.getExternalNotes()[i].trim())) {
                    chk = new Chunk(
                            finalDOB.getExternalNotes()[i] != null ? finalDOB.getExternalNotes()[i] : "",
                            FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
                    notesCell = new Cell(chk);
                    notesCell.setLeading(8.0f);
                    notes.addCell(notesCell);
                }
            }
            document.add(notes);
        }

        if (contents != null && contents.length > 0) {
            content = new Table(1);
            content.setOffset(5);
            content.setWidth(100);
            content.setPadding(1);
            content.setSpacing(0);
            content.setBackgroundColor(Color.WHITE);
            content.setBorderColor(Color.black);
            content.setBorderWidth(1f);
            content.setTableFitsPage(true);
            Cell cellContent = null;
            int hFLen = headFoot.length;
            for (int i = 0; i < hFLen; i++) {
                if (headFoot[i] != null && "F".equalsIgnoreCase(headFoot[i])) {
                    chk = new Chunk(contents[i], FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));//modified by silpa.p on 2-06-11
                    cellContent = new Cell(chk);
                    cellContent.setBorder(0);
                    cellContent.setLeading(8.0f);
                    cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                    if ("L".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);
                    else if ("C".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_CENTER);
                    else if ("R".equalsIgnoreCase(aligns[i]))
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_RIGHT);
                    content.addCell(cellContent);
                }
            }
            document.add(content);
        }
        //@@Modified by kiran.v on 19/09/2011 for Wpbn Issue 271485
        if (!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())) {
            String filename = "Abbrivation.pdf";
            doPdfAbbrivations(filename, finalDOB, request, response, Sd, Cd, Cdn, frequencyFlag, carrierFlag,
                    serviceFlag, surChargesMap);
        }
        //@@Ended by kiran.v
        PdfContentByte cb1 = writer.getDirectContent();
        cb1.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                document.top() - document.bottom());
        cb1.stroke();

        //Jyothi
        document.close();

        //System.out.println("After     document Close----------------------------------------->");
        // write ByteArrayOutputStream to the ServletOutputStream            
        // ServletOutputStream sout = response.getOutputStream();
        //baos.writeTo(sout);
        //System.out.println("after writer");
        // sout.flush();
        //dataList  = (ArrayList)  remote.sendEmail(dataList);
        // Thread.sleep(1000);

        String file_tsmp = "" + new java.sql.Timestamp((new java.util.Date()).getTime())
                + masterDOB.getQuoteId();
        file_tsmp = file_tsmp.replaceAll("\\:", "");
        file_tsmp = file_tsmp.replaceAll("\\.", "");
        file_tsmp = file_tsmp.replaceAll("\\-", "");
        file_tsmp = file_tsmp.replaceAll(" ", "");
        File f = new File("Quote.pdf");
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        baos.writeTo(fileOutputStream);
        //@@Added by Kameswari for the WPBN issue-80440
        PdfReader reader = new PdfReader("Quote.pdf");
        int n = reader.getNumberOfPages();
        File fs = new File("Quote" + file_tsmp + ".pdf");

        // we create a stamper that will copy the document to a new file
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));

        // adding some metadata
        // adding content to each page

        int k = 0;
        PdfContentByte under = null;
        PdfContentByte over = null;
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
        while (k < n) {
            k++;
            over = stamp.getOverContent(k);
            under = stamp.getOverContent(k);
            //jyothi
            //over.rectangle(30, 30, 550, 800);
            over.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                    document.top() - document.bottom());
            over.stroke();
            //jyothi
            over.beginText();
            over.setFontAndSize(bf, 8);
            over.setTextMatrix(15, 15);
            over.showText("page " + k + " of " + n);
            if (k > 1) {
                // over.setFontAndSize(bf, 10);
                over.setFontAndSize(bf, 7);
                over.showText(
                        "                                                                                                    QUOTE REFERENCE:"
                                + masterDOB.getQuoteId());
                //@@ Added by subrahmanyam for WPBN:146452 on 12/12/2008               
                over.endText();
                over.beginText();
                over.showText(
                        "                                                                                                                                CUSTOMER NAME: "
                                + headerDOB.getCustomerName() + "\n\n\n");//subrahmanyam 12/12/2008

                //   @@ Ended by subrahmanyam for WPBN ISSUE:146452 on 12/12/2008               

            }
            over.endText();
        }
        stamp.close();
        //@@WPBN issue-80440    
        file = new File("Concatenated" + file_tsmp + ".pdf");
        pdfFilesList.add((String) file.getName());
        //@@Added by Kameswari for the WPBN issue-61289
        //@@ Added by subrahmanyam for the  WPBN ISSUE:146460 on 29/01/09             
        if (finalDOB.getAttachmentDOBList() != null && finalDOB.getAttachmentDOBList().size() == 0
                && "View".equalsIgnoreCase(request.getParameter("Operation"))) {

            home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");//146460
            remote = home.create();//146460
            filesList = remote.getQuoteAttachmentDtls(finalDOB);
            if (filesList != null) {
                finalDOB.setAttachmentDOBList(filesList);
            }
        }
        //   @@ Ended by subrahmanyam for the WPBN ISSUE: 146460 on 29/01/09   
        /* if(finalDOB.getAttachmentDOBList()!=null)
        {
          //filesList = finalDOB.getAttachmentDOBList(); // commented for for 192431 on 16-dec-09
             //@@ Added by subrahmanyam for 192431 on 16-dec-09
               if("pdf".equalsIgnoreCase(request.getParameter("pdf")))
               {
                 home        = (QMSMultiQuoteSessionHome)LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");   
                 remote      = home.create();//146460
                 filesList  = remote.getQuoteAttachmentDtls(finalDOB);
               }
              else
                filesList = finalDOB.getAttachmentDOBList();
                // ended for 192431 on 16-dec-09
                
               int fileListSize   = filesList.size();   
        for(int i=0;i<fileListSize;i++)
        {
             attachmentDOB = (MultiQuoteAttachmentDOB)filesList.get(i);
              FileOutputStream  fileStream= new FileOutputStream(attachmentDOB.getFileName());
              fileStream.write(attachmentDOB.getPdfFile());
              pdfFilesList.add((String)attachmentDOB.getFileName());
        }
        }
             buffer = concatPDF(pdfFilesList);
        //@@WPBN issue-61289  
                
        //@@ Commented By Subrahmanyam for enhancement 146460           
        //  if("on".equalsIgnoreCase(request.getParameter("print")))
        {     
        //     request.getSession().setAttribute("QuoteOuptutStream",fs);
        //     request.getSession().setAttribute("filepdf",buffer); //@@Added by Kameswari for the WPBN issue-61289
                
                
        //  }
        //@@ Added by subrahmanyam for the enhancement 146460
        if("PDF".equalsIgnoreCase(request.getParameter("pdf"))||"on".equalsIgnoreCase(request.getParameter("print")))
        {
        request.getSession().setAttribute("QuoteOuptutStream",fs);
        request.getSession().setAttribute("filepdf",buffer);
        }
        */
        //@@ Ended by subrahmanyam for the enhancement 146460
        //f.delete();
        //baos.close();

        String[] contactPersons = masterDOB.getCustContactNames();
        String contactName = "";
        int contactPersonsLength = 0;//added by silpa.p for sent mail modifications on 24-05-11
        boolean mailSent = false;//added by silpa.p for sent mail modifications  on 24-05-11

        String filename = "Annexure" + file_tsmp + ".pdf";
        StringBuffer subject = new StringBuffer("DHL Global Forwarding Quotation,");
        String body = "";

        if (!finalDOB.isMultiModalQuote()) {
            if (masterDOB.getShipmentMode() == 1)
                subject.append(" Airfreight ");
            if (masterDOB.getShipmentMode() == 2)
                subject.append(" Seafreight ");
            else if (masterDOB.getShipmentMode() == 4)
                subject.append(" Truckfreight ");
        } else {
            subject.append(" Multi-Modal ");
        }

        subject.append(
                (headerDOB.getOriginCountry() != null ? headerDOB.getOriginCountry()[0].toUpperCase() : ""))
                .append(" to ")
                .append((headerDOB.getDestinationCountry()[0] != null
                        ? headerDOB.getDestinationCountry()[0].toUpperCase()
                        : ""));
        subject.append(" Quote Reference ");
        if (finalDOB.getUpdatedReportDOB() != null)
            subject.append(request.getAttribute("quoteId")).append(" Replacing ")
                    .append(finalDOB.getUpdatedReportDOB().getQuoteId());
        else
            subject.append(masterDOB.getQuoteId() != null ? masterDOB.getQuoteId() + ""
                    : request.getAttribute("quoteId"));

        doGenerateCartagePDF(filename, finalDOB, request, response);

        if (finalDOB.getAttachmentDOBList() != null) {
            //filesList = finalDOB.getAttachmentDOBList(); // commented for for 192431 on 16-dec-09
            //@@ Added by subrahmanyam for 192431 on 16-dec-09
            if ("pdf".equalsIgnoreCase(request.getParameter("pdf"))) {
                home = (QMSMultiQuoteSessionHome) LookUpBean.getEJBHome("QMSMultiQuoteSessionBean");
                remote = home.create();//146460
                filesList = remote.getQuoteAttachmentDtls(finalDOB);
            } else
                filesList = finalDOB.getAttachmentDOBList();
            // ended for 192431 on 16-dec-09

            int fileListSize = filesList.size();
            for (int i = 0; i < fileListSize; i++) {
                attachmentDOB = (MultiQuoteAttachmentDOB) filesList.get(i);
                FileOutputStream fileStream = new FileOutputStream(attachmentDOB.getFileName());
                fileStream.write(attachmentDOB.getPdfFile());
                pdfFilesList.add((String) attachmentDOB.getFileName());
                fileStream.close();
            }
        }

        if (pdfFilesList.size() > 1) {
            for (int l = 1; l < pdfFilesList.size(); l++) {
                FileInputStream inputStream = new FileInputStream((String) pdfFilesList.get(l));
                buffer = new byte[inputStream.available()];
                inputStream.read(buffer);
                bufferList.add(buffer);
                inputStream.close();
            }
        }

        //buffer = concatPDF(pdfFilesList); 

        //@@WPBN issue-61289
        /* //@@ Commented By Subrahmanyam for enhancement 146460           
        /* if("on".equalsIgnoreCase(request.getParameter("print")))
         {     
              request.getSession().setAttribute("QuoteOuptutStream",fs);
             request.getSession().setAttribute("filepdf",buffer); //@@Added by Kameswari for the WPBN issue-61289
        }*/

        //@@ Added by subrahmanyam for the enhancement 146460
        if ("PDF".equalsIgnoreCase(request.getParameter("pdf"))
                || "on".equalsIgnoreCase(request.getParameter("print"))) {
            request.getSession().setAttribute("QuoteOuptutStream", fs);
            request.getSession().setAttribute("filepdf", bufferList);
        }

        for (int dc = 0; dc < noOfLanes; dc++) {
            legDestCharges = (MultiQuoteFreightLegSellRates) destLaneCharges.get(dc);

            try {
                if ("Y".equalsIgnoreCase(finalDOB.getFlagsDOB().getEmailFlag())) {
                    // mailFlag  = 1;
                    //finalDOB.getFlagsDOB().setQuoteStatusFlag("PEN");//@@Quote is Pending
                    //ReportsSessionBeanHome home      = (ReportsSessionBeanHome)LookUpBean.getEJBHome("ReportsSessionBean");
                    //ReportsSession remote   = (ReportsSession)home.create();
                    //@@Modified by kameswari for the WPBN issue-61289
                    //String to_emailIds = finalDOB.getHeaderDOB().getCustEmailId();
                    String to_emailIds = null;
                    if ("Y".equalsIgnoreCase(masterDOB.getSalesPersonFlag()))
                        to_emailIds = finalDOB.getHeaderDOB().getCustEmailId() + ','
                                + masterDOB.getSalesPersonEmail();
                    else
                        to_emailIds = finalDOB.getHeaderDOB().getCustEmailId();
                    //@@WPBN issue-61289
                    to_emailIds = to_emailIds.replaceAll(";", ",");

                    //System.out.println("Before Sending Mail------------------------------>");

                    if (contactPersons != null) {
                        int contPersonLen = contactPersons.length;
                        for (int i = 0; i < contPersonLen; i++) {
                            mailFlag = 1;

                            // if(i<contactPersons.length)//@@Added by Kameswari for the WPBN issue-61289
                            //    {
                            if (masterDOB.getCustomerContactsEmailIds()[i] != null
                                    && masterDOB.getCustomerContactsEmailIds()[i].trim().length() != 0) {

                                contactName = masterDOB.getCustContactNames()[i];
                                if (masterDOB.getCustContactNames()[i].indexOf("[") != -1)
                                    contactName = contactName.substring(0,
                                            masterDOB.getCustContactNames()[i].indexOf("["));
                                /* if(finalDOB.getUpdatedReportDOB()!=null)
                                 {
                                            
                                             
                                    body = "Dear "+contactName+",\n\nThis is a replacement quotation reference "+request.getAttribute("quoteId")+",replacing "+finalDOB.getUpdatedReportDOB().getQuoteId()+
                                      ", due to a change in "+(finalDOB.getEmailChargeName()!=null?finalDOB.getEmailChargeName():finalDOB.getUpdatedReportDOB().getChangeDesc())+". All information is contained within the attachment. "+
                                     "Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                 }
                                 else
                                 {
                                   body = "Dear "+contactName+",\n\nThank you for the opportunity to provide this Quotation. All information is contained within the attachment."+
                                        " Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                 }*/
                                //body  = "Dear "+contactName+",\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                if (finalDOB.getUpdatedReportDOB() != null) {
                                    body = "Dear " + (contactName != null ? contactName : "")
                                            + ",\n\nThis is a replacement quotation reference "
                                            + request.getAttribute("quoteId") + ",replacing "
                                            + finalDOB.getUpdatedReportDOB().getQuoteId()
                                            + ", due to a change in "
                                            + (finalDOB.getEmailChargeName() != null
                                                    ? finalDOB.getEmailChargeName()
                                                    : finalDOB.getUpdatedReportDOB().getChangeDesc())
                                            + ",\n\n"
                                            + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                            + "\n\n\n"
                                            + (masterDOB.getCreatorDetails() != null
                                                    ? masterDOB.getCreatorDetails()
                                                    : "")
                                            + "\n\n"
                                            + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName()
                                                    : "")
                                            + "\n"
                                            + (masterDOB.getTerminalAddress() != null
                                                    ? masterDOB.getTerminalAddress()
                                                    : "")
                                            + "\n\n" + "Phone  "
                                            + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "")
                                            + "\n" + "Fax    "
                                            + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "") + "\n"
                                            + "Mobile "
                                            + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                            + "\n\nEmail "
                                            + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                    : ""); //@@Modified by Kameswari for the WPBN issue-61303

                                } else {
                                    body = "Dear " + (contactName != null ? contactName : "") + ",\n\n"
                                            + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                            + "\n\n\n"
                                            + (masterDOB.getCreatorDetails() != null
                                                    ? masterDOB.getCreatorDetails()
                                                    : "")
                                            + "\n\n"
                                            + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName()
                                                    : "")
                                            + "\n"
                                            + (masterDOB.getTerminalAddress() != null
                                                    ? masterDOB.getTerminalAddress()
                                                    : "")
                                            + "\n\n" + "Phone  "
                                            + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "")
                                            + "\n" + "Fax    "
                                            + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "") + "\n"
                                            + "Mobile "
                                            + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                            + "\n\nEmail "
                                            + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                    : ""); //@@Modified by Kameswari for the WPBN issue-61303

                                }
                                if (masterDOB.getShipperZipCode() == null
                                        || masterDOB.getConsigneeZipCode() == null) {
                                    if ((legDestCharges.getPickZoneZipMap() != null
                                            && legDestCharges.getPickZoneZipMap().size() > 0)
                                            || (legDestCharges.getDeliveryZoneZipMap() != null
                                                    && legDestCharges.getDeliveryZoneZipMap().size() > 0)) {
                                        if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications  on 24-05-11
                                            sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                                    masterDOB.getCustomerContactsEmailIds()[i],
                                                    subject.toString(), body,
                                                    "Quote" + file_tsmp + ".pdf,Annexure" + file_tsmp + ".pdf",
                                                    finalDOB.getAttachmentDOBList());
                                            mailSent = true;
                                            contactPersonsLength++;
                                        } //ended
                                    }

                                    else if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications  on 24-05-11

                                        sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                                masterDOB.getCustomerContactsEmailIds()[i], subject.toString(),
                                                body, "Quote" + file_tsmp + ".pdf",
                                                finalDOB.getAttachmentDOBList());
                                        mailSent = true;
                                        contactPersonsLength++;
                                    } //ended

                                } else if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications  on 24-05-11
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                            masterDOB.getCustomerContactsEmailIds()[i], subject.toString(),
                                            body, "Quote" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                                    mailSent = true;
                                    contactPersonsLength++;
                                } //ended
                                //  }
                                //@@Added by Kameswari for the WPBN issue-61289
                            }
                        }
                        if ("Y".equalsIgnoreCase(masterDOB.getSalesPersonFlag())) {
                            if (masterDOB.getShipperZipCode() == null
                                    || masterDOB.getConsigneeZipCode() == null) {
                                if ((legDestCharges.getPickZoneZipMap() != null
                                        && legDestCharges.getPickZoneZipMap().size() > 0)
                                        || (legDestCharges.getDeliveryZoneZipMap() != null
                                                && legDestCharges.getDeliveryZoneZipMap().size() > 0))
                                    if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications  on 24-05-11

                                        sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                                masterDOB.getSalesPersonEmail(), subject.toString(), body,
                                                "Quote" + file_tsmp + ".pdf,Annexure" + file_tsmp + ".pdf",
                                                finalDOB.getAttachmentDOBList());
                                        mailSent = true;
                                        contactPersonsLength++;
                                    } //ended
                                    else if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications on 24-05-11
                                        sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                                masterDOB.getSalesPersonEmail(), subject.toString(), body,
                                                "Quote" + file_tsmp + ".pdf", finalDOB.getAttachmentDOBList());
                                        mailSent = true;
                                        contactPersonsLength++;
                                    } //ended
                            } else if (!mailSent || contactPersonsLength < contPersonLen) {//added by silpa.p for sent mail modifications  on 24-05-11
                                sendMail(finalDOB.getMasterDOB().getUserEmailId(),
                                        masterDOB.getSalesPersonEmail(), subject.toString(), body,
                                        "Quote" + file_tsmp + ".pdf", finalDOB.getAttachmentDOBList());
                                mailSent = true;
                                contactPersonsLength++;
                            } //ended
                        }
                        //@@ the WPBN issue-61289

                    } else {
                        mailFlag = 0;

                        /*if(finalDOB.getUpdatedReportDOB()!=null)
                        {
                                  
                          body = "Dear Customer,\n\nThis is a replacement quotation reference "+request.getAttribute("quoteId")+",replacing "+finalDOB.getUpdatedReportDOB().getQuoteId()+
                         ", due to a change in "+(finalDOB.getEmailChargeName()!=null?finalDOB.getEmailChargeName():finalDOB.getUpdatedReportDOB().getChangeDesc())+". All information is contained within the attachment. "+
                         "Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                        }
                        else
                        {
                          body = "Dear Customer,\n\nThank you for the opportunity to provide this Quotation. All information is contained within the attachment."+
                            " Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                        }*/
                        //
                        //body  ="Dear Customer,\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                        /*body  = "Dear Customer,\n\n"+finalDOB.getEmailText()+"\n\n\n"+masterDOB.getCreatorDetails()+"\n\n"+masterDOB.getCompanyName()+
                            "\n"+masterDOB.getTerminalAddress()+"\n\n"+"Phone  "+masterDOB.getPhoneNo()+"\n"+"Fax    "+masterDOB.getFaxNo()+"\n"+"Mobile "+masterDOB.getMobileNo()+"\n\nEmail "+masterDOB.getUserEmailId(); */
                        //@@Modified by Kameswari for the WPBN issue-61303

                        if (finalDOB.getUpdatedReportDOB() != null) {
                            body = "Dear Customer,\n\nThis is a replacement quotation reference "
                                    + request.getAttribute("quoteId") + ",replacing "
                                    + finalDOB.getUpdatedReportDOB().getQuoteId() + ", due to a change in "
                                    + (finalDOB.getEmailChargeName() != null ? finalDOB.getEmailChargeName()
                                            : finalDOB.getUpdatedReportDOB().getChangeDesc())
                                    + ",\n\n" + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                    + "\n\n\n"
                                    + (masterDOB.getCreatorDetails() != null ? masterDOB.getCreatorDetails()
                                            : "")
                                    + "\n\n"
                                    + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName() : "")
                                    + "\n"
                                    + (masterDOB.getTerminalAddress() != null ? masterDOB.getTerminalAddress()
                                            : "")
                                    + "\n\n" + "Phone  "
                                    + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "") + "\n"
                                    + "Fax    " + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "")
                                    + "\n" + "Mobile "
                                    + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                    + "\n\nEmail "
                                    + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId() : ""); //@@Modified by Kameswari for the WPBN issue-61303
                        } else {
                            body = "Dear Customer,\n\n"
                                    + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                    + "\n\n\n"
                                    + (masterDOB.getCreatorDetails() != null ? masterDOB.getCreatorDetails()
                                            : "")
                                    + "\n\n"
                                    + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName() : "")
                                    + "\n"
                                    + (masterDOB.getTerminalAddress() != null ? masterDOB.getTerminalAddress()
                                            : "")
                                    + "\n\n" + "Phone  "
                                    + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "") + "\n"
                                    + "Fax    " + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "")
                                    + "\n" + "Mobile "
                                    + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                    + "\n\nEmail "
                                    + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId() : ""); //@@Modified by Kameswari for the WPBN issue-61303
                        }
                        if (masterDOB.getShipperZipCode() == null || masterDOB.getConsigneeZipCode() == null) {
                            if ((legDestCharges.getPickZoneZipMap() != null
                                    && legDestCharges.getPickZoneZipMap().size() > 0)
                                    || (legDestCharges.getDeliveryZoneZipMap() != null
                                            && legDestCharges.getDeliveryZoneZipMap().size() > 0))
                                if (!mailSent) {//added by silpa.p for sent mail modifications  on 24-05-11
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(), to_emailIds,
                                            subject.toString(), body,
                                            "Quote" + file_tsmp + ".pdf,Annexure" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                                    mailSent = true;

                                } //ended
                                else if (!mailSent) {//added by silpa.p for sent mail modifications mail on 24-05-11
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(), to_emailIds,
                                            subject.toString(), body, "Quote" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                                    mailSent = true;
                                } //ended
                        } else if (!mailSent) {//added by silpa.p for sent mail modifications mail on 24-05-11
                            sendMail(finalDOB.getMasterDOB().getUserEmailId(), to_emailIds, subject.toString(),
                                    body, "Quote" + file_tsmp + ".pdf", finalDOB.getAttachmentDOBList());
                            mailSent = true;
                        } //ended
                    }

                    //System.out.println("End of mail sending and PDF Generation --------------------------------->");
                }
            } catch (Exception e) {
                //Logger.error(FILE_NAME,"Error while sending mail "+e); 
                logger.error(FILE_NAME + "Error while sending mail " + e);
                e.printStackTrace();
                mailFlag = 0;
            }
            try {
                if ("Y".equalsIgnoreCase(finalDOB.getFlagsDOB().getFaxFlag())) {
                    //faxFlag   = 2;
                    //finalDOB.getFlagsDOB().setQuoteStatusFlag("PEN");//@@Quote is Pending
                    //ReportsSessionBeanHome home      = (ReportsSessionBeanHome)LookUpBean.getEJBHome("ReportsSessionBean");
                    //ReportsSession  remote   = (ReportsSession)home.create();
                    String customerFax = headerDOB.getCustFaxNo() != null ? headerDOB.getCustFaxNo() : "";
                    String countrycode = headerDOB.getCustCountyCode() != null ? headerDOB.getCustCountyCode()
                            : "";
                    String contactFax = null;
                    if ("SG".equalsIgnoreCase(countrycode)) {
                        if (customerFax != null && customerFax.length() > 0)
                            customerFax = "fax#" + customerFax + "@tcdhl.com";
                    } else {
                        if (customerFax != null && customerFax.length() > 0)
                            customerFax = "ifax#" + customerFax + "@tcdhl.com";
                    }

                    if (contactPersons != null) {
                        int contPersonLen = contactPersons.length;
                        for (int i = 0; i < contPersonLen; i++) {
                            faxFlag = 2;
                            contactName = masterDOB.getCustContactNames()[i];
                            if (masterDOB.getCustContactNames()[i].indexOf("[") != -1)
                                contactName = contactName.substring(0,
                                        masterDOB.getCustContactNames()[i].indexOf("["));
                            if (masterDOB.getCustomerContactsFax()[i] != null
                                    && masterDOB.getCustomerContactsFax()[i].trim().length() != 0) {
                                if ("SG".equalsIgnoreCase(countrycode))
                                    contactFax = "fax#" + masterDOB.getCustomerContactsFax()[i] + "@tcdhl.com";
                                else
                                    contactFax = "ifax#" + masterDOB.getCustomerContactsFax()[i] + "@tcdhl.com";

                                /*if(finalDOB.getUpdatedReportDOB()!=null)
                                {
                                  body = "Dear "+contactName+",\n\nThis is a replacement quotation reference "+request.getAttribute("quoteId")+",replacing "+finalDOB.getUpdatedReportDOB().getQuoteId()+
                                     ", due to a change in "+(finalDOB.getEmailChargeName()!=null?finalDOB.getEmailChargeName():finalDOB.getUpdatedReportDOB().getChangeDesc())+". All information is contained within the attachment. "+
                                    "Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                 }
                                else
                                {
                                  body = "Dear "+contactName+",\n\nThank you for the opportunity to provide this Quotation. All information is contained within the attachment."+
                                       " Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                }*/
                                // body  = "Dear "+contactName+",\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                                if (finalDOB.getUpdatedReportDOB() != null) {
                                    body = "Dear " + (contactName != null ? contactName : "")
                                            + ",\n\nThis is a replacement quotation reference "
                                            + request.getAttribute("quoteId") + ",replacing "
                                            + finalDOB.getUpdatedReportDOB().getQuoteId()
                                            + ", due to a change in "
                                            + (finalDOB.getEmailChargeName() != null
                                                    ? finalDOB.getEmailChargeName()
                                                    : finalDOB.getUpdatedReportDOB().getChangeDesc())
                                            + ",\n\n"
                                            + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                            + "\n\n\n"
                                            + (masterDOB.getCreatorDetails() != null
                                                    ? masterDOB.getCreatorDetails()
                                                    : "")
                                            + "\n\n"
                                            + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName()
                                                    : "")
                                            + "\n"
                                            + (masterDOB.getTerminalAddress() != null
                                                    ? masterDOB.getTerminalAddress()
                                                    : "")
                                            + "\n\n" + "Phone  "
                                            + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "")
                                            + "\n" + "Fax    "
                                            + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "") + "\n"
                                            + "Mobile "
                                            + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                            + "\n\nEmail "
                                            + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                    : ""); //@@Modified by Kameswari for the WPBN issue-61303
                                } else {
                                    body = "Dear " + (contactName != null ? contactName : "") + ",\n\n"
                                            + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                            + "\n\n\n"
                                            + (masterDOB.getCreatorDetails() != null
                                                    ? masterDOB.getCreatorDetails()
                                                    : "")
                                            + "\n\n"
                                            + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName()
                                                    : "")
                                            + "\n"
                                            + (masterDOB.getTerminalAddress() != null
                                                    ? masterDOB.getTerminalAddress()
                                                    : "")
                                            + "\n\n" + "Phone  "
                                            + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "")
                                            + "\n" + "Fax    "
                                            + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "") + "\n"
                                            + "Mobile "
                                            + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                            + "\n\nEmail "
                                            + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                    : ""); //@@Modified by Kameswari for the WPBN issue-61303

                                }
                                if (masterDOB.getShipperZipCode() == null
                                        || masterDOB.getConsigneeZipCode() == null) {
                                    if ((legDestCharges.getPickZoneZipMap() != null
                                            && legDestCharges.getPickZoneZipMap().size() > 0)
                                            || (legDestCharges.getDeliveryZoneZipMap() != null
                                                    && legDestCharges.getDeliveryZoneZipMap().size() > 0))
                                        sendMail(finalDOB.getMasterDOB().getUserEmailId(), contactFax,
                                                subject.toString(), body,
                                                "Quote" + file_tsmp + ".pdf,Annexure" + file_tsmp + ".pdf",
                                                finalDOB.getAttachmentDOBList());
                                    else
                                        sendMail(finalDOB.getMasterDOB().getUserEmailId(), contactFax,
                                                subject.toString(), body, "Quote" + file_tsmp + ".pdf",
                                                finalDOB.getAttachmentDOBList());
                                } else
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(), contactFax,
                                            subject.toString(), body, "Quote" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                            } else
                                faxFlag = 0;
                        }
                    } else {
                        if (customerFax != null && customerFax.length() > 0) {
                            /* if(finalDOB.getUpdatedReportDOB()!=null)
                            {
                             body = "Dear Customer,\n\nThis is a replacement quotation reference "+request.getAttribute("quoteId")+",replacing "+finalDOB.getUpdatedReportDOB().getQuoteId()+
                                   ", due to a change in "+(finalDOB.getEmailChargeName()!=null?finalDOB.getEmailChargeName():finalDOB.getUpdatedReportDOB().getChangeDesc())+". All information is contained within the attachment. "+
                                   "Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                            }
                            else
                            {
                             body = "Dear Customer,\n\nThank you for the opportunity to provide this Quotation. All information is contained within the attachment."+
                            " Should you have any queries, please do not hesitate to contact us.\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress();
                            }*/
                            // body  = "Dear Customer,\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+masterDOB.getCreatorDetails()+"\n"+masterDOB.getTerminalAddress(); 
                            if (finalDOB.getUpdatedReportDOB() != null) {
                                body = "Dear Customer,\n\nThis is a replacement quotation reference "
                                        + request.getAttribute("quoteId") + ",replacing "
                                        + finalDOB.getUpdatedReportDOB().getQuoteId() + ", due to a change in "
                                        + (finalDOB.getEmailChargeName() != null ? finalDOB.getEmailChargeName()
                                                : finalDOB.getUpdatedReportDOB().getChangeDesc())
                                        + ",\n\n"
                                        + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                        + "\n\n\n"
                                        + (masterDOB.getCreatorDetails() != null ? masterDOB.getCreatorDetails()
                                                : "")
                                        + "\n\n"
                                        + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName() : "")
                                        + "\n"
                                        + (masterDOB.getTerminalAddress() != null
                                                ? masterDOB.getTerminalAddress()
                                                : "")
                                        + "\n\n" + "Phone  "
                                        + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "") + "\n"
                                        + "Fax    " + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "")
                                        + "\n" + "Mobile "
                                        + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                        + "\n\nEmail "
                                        + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                : ""); //@@Modified by Kameswari for the WPBN issue-61303
                            } else {
                                body = "Dear Customer,\n\n"
                                        + (finalDOB.getEmailText() != null ? finalDOB.getEmailText() : "")
                                        + "\n\n\n"
                                        + (masterDOB.getCreatorDetails() != null ? masterDOB.getCreatorDetails()
                                                : "")
                                        + "\n\n"
                                        + (masterDOB.getCompanyName() != null ? masterDOB.getCompanyName() : "")
                                        + "\n"
                                        + (masterDOB.getTerminalAddress() != null
                                                ? masterDOB.getTerminalAddress()
                                                : "")
                                        + "\n\n" + "Phone  "
                                        + (masterDOB.getPhoneNo() != null ? masterDOB.getPhoneNo() : "") + "\n"
                                        + "Fax    " + (masterDOB.getFaxNo() != null ? masterDOB.getFaxNo() : "")
                                        + "\n" + "Mobile "
                                        + (masterDOB.getMobileNo() != null ? masterDOB.getMobileNo() : "")
                                        + "\n\nEmail "
                                        + (masterDOB.getUserEmailId() != null ? masterDOB.getUserEmailId()
                                                : ""); //@@Modified by Kameswari for the WPBN issue-61303
                            }
                            if (masterDOB.getShipperZipCode() == null
                                    || masterDOB.getConsigneeZipCode() == null) {
                                if ((legDestCharges.getPickZoneZipMap() != null
                                        && legDestCharges.getPickZoneZipMap().size() > 0)
                                        || (legDestCharges.getDeliveryZoneZipMap() != null
                                                && legDestCharges.getDeliveryZoneZipMap().size() > 0))
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(), customerFax,
                                            subject.toString(), body,
                                            "Quote" + file_tsmp + ".pdf,Annexure" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                                else
                                    sendMail(finalDOB.getMasterDOB().getUserEmailId(), customerFax,
                                            subject.toString(), body, "Quote" + file_tsmp + ".pdf",
                                            finalDOB.getAttachmentDOBList());
                            } else
                                sendMail(finalDOB.getMasterDOB().getUserEmailId(), customerFax,
                                        subject.toString(), body, "Quote" + file_tsmp + ".pdf",
                                        finalDOB.getAttachmentDOBList());
                        } else
                            faxFlag = 0;
                    }
                }
            } catch (Exception e) {
                //Logger.error(FILE_NAME,"Error while sending fax "+e); 
                logger.error(FILE_NAME + "Error while sending fax " + e);
                e.printStackTrace();
                faxFlag = 0;
            }
        }
        if ("Y".equalsIgnoreCase(finalDOB.getFlagsDOB().getPrintFlag())) {
            //finalDOB.getFlagsDOB().setQuoteStatusFlag("PEN");//@@Quote is Pending
            printFlag = 4;
        } else {
            f.delete();
            File annexure = new File(filename);
            annexure.delete();
        }
        returnFlag = mailFlag + faxFlag + printFlag;
    } catch (Exception e) {
        e.printStackTrace();
        //Logger.error(FILE_NAME,"Error while generating the PDF"+e.toString());
        logger.error(FILE_NAME + "Error while generating the PDF" + e.toString());
        returnFlag = 0;
        //throw new Exception("Error while generating PDF format");
    } finally {
        try {
            //Method: doPDFGeneration Defect: PdfWriter is not closedSuggestion: Close and nullify the writer in the finally block.
            if (writer != null) {
                writer.close();
                writer = null;
            }
            charges = null;
            freightCharges = null;
            frequency = null;
            carrier = null;
            transittime = null;
            ratevalidity = null;
            frequency_o = null;
            frequency_d = null;
            carrier_o = null;
            carrier_d = null;
            transit_o = null;
            transit_d = null;
            validity_o = null;
            validity_d = null;
            filesList = null;

        } catch (Exception ex) {
            //Logger.error(FILE_NAME,"Exception caught :: finally :: insertFclValues() " + ex.toString() );
            logger.error(FILE_NAME + "Error while generating the PDF" + ex.toString());
        }
    }
    return returnFlag;
}

From source file:biblivre3.administration.reports.BaseBiblivreReport.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    try {//w  w  w.j a  v a 2  s.  c  o  m
        Rectangle page = document.getPageSize();

        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(this.getText("REPORTS_HEADER")));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth((page.width() / 2) - document.leftMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable date = new PdfPTable(1);
        PdfPCell dateCell = new PdfPCell(new Paragraph(dateFormat.format(generationDate)));
        dateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        dateCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        dateCell.setBorder(Rectangle.BOTTOM);
        date.addCell(dateCell);
        date.setTotalWidth((page.width() / 2) - document.rightMargin());
        date.writeSelectedRows(0, -1, (page.width() / 2),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable foot = new PdfPTable(1);
        Chunk pageNumber = new Chunk(String.valueOf(document.getPageNumber()));
        pageNumber.setFont(footerFont);
        cell = new PdfPCell(new Paragraph(pageNumber));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:br.org.acessobrasil.silvinha.util.HeaderAndFooter.java

License:Open Source License

/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 *///from w  w  w.j a v a2  s  . c  om
public void onEndPage(PdfWriter writer, Document document) {

    try {
        Rectangle page = document.getPageSize();
        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(GERAL.RELATORIOS_ASES));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());
        PdfPTable foot = new PdfPTable(1);
        cell = new PdfPCell(new Paragraph(String.valueOf(document.getPageNumber())));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:bucks.RedeemInvoice.java

License:Open Source License

void generateInvoice(HttpServletResponse res, Redeem redeem) {

    ////from w  w w .jav a2s  .  c om
    // 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:ca.sqlpower.architect.profile.output.ProfilePDFFormat.java

License:Open Source License

/**
 * @param widths The maximum width of each column's contents in
 * points.  THIS ARRAY WILL BE MODIFIED to the width of the widest
 * single word in the heading if it is wider than the existing
 * width value for that column.  Words are split using the default
 * settings for java.util.StringTokenizer.
 * @param headerTopNColumns reference to the null count/% inner table in the header
 * @param headerValueColumns reference to the unique count/% inner table in the header
 * @param headerLengthColumns reference to the length min/max/avg inner table in the header
 * @param headerUniqueColumns reference to the value min/max/avg inner table in the header
 * @param headerNullColumns reference to the top N Value/count inner table in the header
 * we will resert widths of these inner table after we have all rows
 *//*from ww  w  .j  a  va2s  .  c  o m*/
private void addHeaderRow(TableProfileResult result, ProfileTableStructure profile, BaseFont bf,
        float titleFSize, float colHeadingFSize, float[] widths)
        throws DocumentException, IOException, SQLObjectException {

    int ncols = headings.length;

    Font titleFont = new Font(bf, titleFSize, Font.BOLD);
    Font colHeadingFont = new Font(bf, colHeadingFSize);
    PdfPTable table = profile.getMainTable();
    SQLTable sqlTable = result.getProfiledObject();

    //        TableProfileResult tProfile = (TableProfileResult) pm.getResult(sqlTable);
    PdfPTable infoTable = new PdfPTable(2);
    StringBuffer heading = new StringBuffer();
    heading.append("Connection: ").append(sqlTable.getParentDatabase().getName()).append("\n");
    heading.append("Table: ").append(SQLObjectUtils.toQualifiedName(sqlTable, SQLDatabase.class));
    if (result.getException() != null) {
        heading.append("\nProfiling Error");
        if (result.getException() != null) {
            heading.append(":\n").append(result.getException());
            StackTraceElement[] stackTrace = result.getException().getStackTrace();
            for (int i = 0; i < STACK_TRACE_LENGTH && i < stackTrace.length; i++) {
                StackTraceElement element = stackTrace[i];
                heading.append("\n   ").append(element.getFileName()).append(".").append(element.getClassName())
                        .append(".").append(element.getMethodName()).append("(").append(element.getLineNumber())
                        .append(")");
            }
            if (stackTrace.length > STACK_TRACE_LENGTH) {
                heading.append("\n   ... ").append(stackTrace.length).append(" more");
            }
        }
    } else {
        PdfPCell infoCell;

        infoCell = new PdfPCell(new Phrase("Row Count:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(String.valueOf(result.getRowCount()), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Create Date:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        infoCell = new PdfPCell(new Phrase(df.format(new Date(result.getCreateStartTime())), colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase("Elapsed:", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        infoTable.addCell(infoCell);

        infoCell = new PdfPCell(new Phrase(result.getTimeToCreate() + "ms", colHeadingFont));
        infoCell.setBorder(Rectangle.NO_BORDER);
        infoTable.addCell(infoCell);
    }

    PdfPCell hcell = new PdfPCell(new Phrase(heading.toString(), titleFont));
    hcell.setColspan(ncols - 3);
    hcell.setBorder(Rectangle.NO_BORDER);
    hcell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(hcell);

    hcell = new PdfPCell(infoTable);
    hcell.setColspan(3);
    hcell.setBorder(Rectangle.NO_BORDER);
    table.addCell(hcell);

    if (sqlTable.getColumns().size() > 0) {

        int colNo = 0;
        // column name
        Phrase colTitle = new Phrase("Column Name", colHeadingFont);
        PdfPCell cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        // ensure column width is at least enough for widest word in heading
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // date type
        colTitle = new Phrase("Data Type", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
        cell.setBorderWidth(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        // null count and %
        colTitle = new Phrase("NULL", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableNullColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableNullColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // unique count and %
        colTitle = new Phrase("Unique", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableUniqueColumn().addCell(cell);

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("%", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableUniqueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableUniqueColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        cell.setBorderWidth(2);
        table.addCell(cell);

        // length max/min/avg
        colTitle = new Phrase("Length", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableLengthColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableLengthColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableLengthColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // value max/min/avg
        colTitle = new Phrase("Value", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        profile.getInnerTableValueColumn().addCell(cell);

        colTitle = new Phrase("Min", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Max", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("Avg", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableValueColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableValueColumn());
        cell.setColspan(3);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

        // top n
        colTitle = new Phrase("Top N", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        profile.getInnerTableTopNColumn().addCell(cell);

        colTitle = new Phrase("Values", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        colTitle = new Phrase("#", colHeadingFont);
        cell = new PdfPCell(colTitle);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        profile.getInnerTableTopNColumn().addCell(cell);
        widths[colNo] = Math.max(widths[colNo], bf.getWidthPoint(colTitle.content(), colHeadingFSize));
        colNo++;

        cell = new PdfPCell(profile.getInnerTableTopNColumn());
        cell.setColspan(2);
        cell.setBackgroundColor(new Color(200, 200, 200));
        cell.setBorderWidth(2);
        cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
        table.addCell(cell);

    } else {
        hcell = new PdfPCell(new Phrase("No Column Found in the table", titleFont));
        hcell.setColspan(ncols);
        hcell.setBorder(Rectangle.BOTTOM);
        hcell.setVerticalAlignment(Element.ALIGN_LEFT);
        table.addCell(hcell);
    }
    table.setHeaderRows(2);
}

From source file:ch.gpb.elexis.cst.view.CstResultPart.java

License:Open Source License

private void makeActions(final Control viewer) {

    actionScreenshot = new Action() {
        public void run() {
            if (profile == null) {
                SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden");
                return;
            }//  ww w .  ja  v a  2s  .com

            GC gc = null;
            Image image = null;
            try {

                String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null);
                if (latestPath == null) {
                    latestPath = System.getProperty("user.home");
                }

                FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE);
                fd.setText("Save");
                fd.setFilterPath(latestPath);
                String[] filterExt = { "*.png", "*.*" };
                fd.setFilterExtensions(filterExt);
                fd.setFileName(CstService.generateFilename(patient));
                String selected = fd.open();

                if (selected == null) {
                    return;
                }

                File selFile = new File(selected);

                CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH,
                        selFile.getParentFile().getAbsolutePath());

                //if (profile.getAnzeigeTyp().toLowerCase().equals("effektiv")) {
                if (profile.getAnzeigeTyp().toLowerCase().equals(CstProfile.ANZEIGETYP_EFFEKTIV)) {

                    if (profile.getAusgabeRichtung()) {
                        image = new Image(viewer.getDisplay(), 1123, viewer.getBounds().height);

                    } else {
                        image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height);

                    }
                } else {
                    image = new Image(viewer.getDisplay(), 794, viewer.getBounds().height);

                }

                ImageLoader loader = new ImageLoader();

                gc = new GC(image);
                viewer.print(gc);

                gc.dispose();

                loader.data = new ImageData[] { image.getImageData() };
                loader.save(selected, SWT.IMAGE_PNG);

            } catch (Exception e) {
                log.error("Error saving png: " + e.toString());
                showMessage("Error while saving PNG", e.getMessage());
            } finally {
                if (image != null) {
                    image.dispose();
                }
                if (gc != null) {
                    gc.dispose();
                }
            }

        }
    };
    actionScreenshot.setText(Messages.Cst_Text_Save_as_png);
    actionScreenshot.setToolTipText(Messages.Cst_Text_Save_as_png);
    actionScreenshot.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT));
    actionScreenshot.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PNG_PATH));

    // TODO: die pdf ausgabe ist eine ziemliche Baustelle - berarbeiten
    actionPdf = new Action() {
        public void run() {

            //////////////////////////
            if (profile == null) {
                SWTHelper.alert("No profile", "Ohne Profil kann kein Resultat erzeugt werden");
                return;
            }

            GC gc = null;
            Image image = null;
            try {
                String latestPath = CoreHub.userCfg.get(CstPreference.CST_IDENTIFIER_LATESTPATH, null);
                if (latestPath == null) {
                    latestPath = System.getProperty("user.home");
                }

                FileDialog fd = new FileDialog(baseComposite.getShell(), SWT.SAVE);
                fd.setText("Save");
                fd.setFilterPath(latestPath);
                String[] filterExt = { "*.pdf", "*.*" };
                fd.setFilterExtensions(filterExt);
                fd.setFileName(CstService.generateFilename(patient));
                String selected = fd.open();

                if (selected == null) {
                    return;
                }
                File selFile = new File(selected);

                CoreHub.userCfg.set(CstPreference.CST_IDENTIFIER_LATESTPATH,
                        selFile.getParentFile().getAbsolutePath());

                int printHeigth = 1123;
                int printWidth = 794;
                if (profile.getAusgabeRichtung()) {
                    printHeigth = 794;
                    printWidth = 1123;

                }

                // get the image from the viewport
                image = new Image(viewer.getDisplay(), printWidth, viewer.getBounds().height);
                ImageLoader loader = new ImageLoader();

                gc = new GC(image);
                viewer.print(gc);
                gc.dispose();

                // prepare title data
                //Date date = new Date();
                //SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy  HH:mm");

                Patient patient = Patient.load(profile.getKontaktId());
                //String sTitle = "Gemeinschaftspraxis Brunnmatt Dr. Beat Knzi ";
                String sTitle;
                sTitle = profile.getOutputHeader() == null ? "No header configured!"
                        : profile.getOutputHeader();

                if (sTitle == null || sTitle.length() == 0) {
                    sTitle = "No header configured!";
                }
                sTitle = sTitle + " Datum: " + CstService.getReadableDateAndTime();

                // get option (paging to A4/ in one piece)
                int pdfOutputOption = 0;
                boolean onePage = true;

                PdfOptionsDialog dialog = new PdfOptionsDialog(baseComposite.getShell());
                dialog.create();

                if (dialog.open() == Window.OK) {
                    pdfOutputOption = dialog.getPdfOutputOption();
                    if (pdfOutputOption == PdfOptionsDialog.OPTION_ONE_PAGE) {
                        onePage = true;
                    } else {

                        onePage = false;
                    }
                }

                float docHeight = viewer.getBounds().height;
                docHeight = docHeight / 7.5f;

                float fontSize = 12f;

                if (docHeight < 360f) {
                    docHeight = 360f;
                }

                BufferedImage bimage = ImageUtils.convertToAWT(image.getImageData());

                // create an Itextt Image from AWT BufferedImage
                com.lowagie.text.Image itextImage = null;
                java.awt.Image awtImage = null;

                try {
                    awtImage = Toolkit.getDefaultToolkit().createImage(bimage.getSource());
                    itextImage = com.lowagie.text.Image.getInstance(awtImage, null);

                } catch (Exception e) {
                    log.error("Error on image loading: " + e.toString());
                    e.printStackTrace();
                }

                // only for debugging

                //loader.data = new ImageData[] { image.getImageData() };
                //loader.save("C:\\Users\\daniel\\tmp\\debug.png", SWT.IMAGE_PNG);

                Rectangle pagesize = new Rectangle(595f, itextImage.getHeight() * 0.75f);

                // is it a4 quer?
                if (profile.getAusgabeRichtung()) {
                    pagesize = new Rectangle(842f, itextImage.getHeight() * 0.75f);

                }

                //System.out.println("pagesize: " + pagesize.toString());

                Document document;
                if (onePage) {
                    document = new Document(pagesize);

                } else {
                    document = new Document(PageSize.A4);
                    if (profile.getAusgabeRichtung()) {
                        document = new Document(PageSize.A4.rotate());
                    }

                }

                document.addCreationDate();

                try {
                    // creation of the different writers
                    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(selected));

                    // various fonts
                    BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", true);
                    BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", true);
                    BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", true);

                    com.lowagie.text.Font fontHelv12 = new com.lowagie.text.Font(bf_helv, fontSize);

                    com.lowagie.text.Font fontTimes = new com.lowagie.text.Font(bf_times, fontSize);

                    fontTimes.setSize(fontSize);
                    fontTimes.setStyle(com.lowagie.text.Font.ITALIC);

                    Chunk chunkHeader = new Chunk(sTitle, FontFactory.getFont(FontFactory.HELVETICA, fontSize,
                            com.lowagie.text.Font.NORMAL, new java.awt.Color(255, 0, 0)));

                    com.lowagie.text.Phrase phraseHeader = new com.lowagie.text.Phrase(chunkHeader);

                    // headers and footers must be added before the document
                    // is opened

                    Chunk chunkFooter = new Chunk("Seite: ", FontFactory.getFont(FontFactory.HELVETICA,
                            fontSize, com.lowagie.text.Font.BOLD, new java.awt.Color(0, 0, 0)));

                    Phrase phraseFooter = new Phrase(chunkFooter);
                    phraseFooter.setFont(fontHelv12);

                    HeaderFooter footer = new HeaderFooter(phraseFooter, true);
                    footer.setBorder(Rectangle.NO_BORDER);
                    footer.setAlignment(Element.ALIGN_CENTER);

                    document.setFooter(footer);

                    Phrase headerPhrase = new Phrase(sTitle);
                    headerPhrase.setFont(fontTimes);

                    HeaderFooter header = new HeaderFooter(phraseHeader, false);
                    header.setBorder(Rectangle.BOTTOM);
                    header.setBorderWidth(0.5f);
                    header.setAlignment(Element.ALIGN_LEFT);
                    document.setHeader(header);

                    document.open();

                    //System.out.println("itext image w: " + itextImage.getWidth() + " h:" + itextImage.getHeight());

                    if (onePage) {

                        int scale = 66;
                        itextImage.scalePercent(scale);

                        document.add(itextImage);

                    } else {

                        BufferedImage[] imageChunks = ImageUtils.splitImageByHeigth(bimage, printHeigth);

                        for (int i = 0; i < imageChunks.length; i++) {

                            com.lowagie.text.Image itextImage2 = com.lowagie.text.Image.getInstance(
                                    Toolkit.getDefaultToolkit().createImage(imageChunks[i].getSource()), null);

                            // width becomes typically 523 (595 - 72) for a4Hoch or 770 (842 - 72) for A4Quer
                            float imgWidth = document.getPageSize().getWidth() - document.leftMargin()
                                    - document.rightMargin();
                            float imgHeigth = itextImage.getHeight() * 0.75f;

                            itextImage2.setAbsolutePosition(30, 20);
                            int scale = 66;
                            itextImage2.scalePercent(scale);

                            document.add(itextImage2);
                            document.newPage();

                        }

                    }

                    // we're done!
                    document.close();

                    ///////////////////////////////

                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    showMessage("Error while generating PDF", ex.getMessage());
                }

            } finally {
                if (image != null) {
                    image.dispose();
                }
                if (gc != null) {
                    gc.dispose();
                }
                /*
                image.dispose();
                gc.dispose();
                */
            }

        }
    };

    actionPdf.setText(Messages.Cst_Text_Save_as_pdf);
    actionPdf.setToolTipText(Messages.Cst_Text_Save_as_pdf);
    /*
     * actionPdf.setImageDescriptor(PlatformUI.getWorkbench() .getSharedImages()
     * .getImageDescriptor(ISharedImages.IMG_OBJ_FILE));
     */
    actionPdf.setImageDescriptor(Activator.getImageDescriptor(Activator.IMG_PDF_PATH));

}

From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java

License:Open Source License

private static HeaderFooter getHeader(String headerText) {
    Phrase headerPhrase = new Phrase(headerText);
    headerPhrase.setFont(fontTimes);/*from w  w  w .  ja  va2  s  .  c  om*/

    HeaderFooter header = new HeaderFooter(headerPhrase, false);
    header.setBorder(Rectangle.BOTTOM);
    header.setBorderWidth(0.5f);
    header.setAlignment(Element.ALIGN_LEFT);

    return header;
}

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 {/*from  w  w w .  j av a2  s.c o m*/

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

        tempFile.deleteOnExit();

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

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;

        //        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40);

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

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

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

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

                String compName = null;
                String date = null;

                try {

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

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

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

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

                }

                docPdf.open();

                String Username = null;
                int numColumns = 9;

                try {

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

                    long dateNow = calendar.getTimeInMillis();

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

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

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

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

                    // table.endHeaders();

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

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

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

                    table1.getDefaultCell().setColspan(7);

                    Phrase phrase = new Phrase();

                    //  table.addCell(phrase);

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

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

                            table1.getDefaultCell().setColspan(6);

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

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

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

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

                }

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

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

                    //  table1.setWidths(headerwidths1);

                    table1.setWidthPercentage((100));

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

                    try {

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

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

                        while (rset4.next()) {

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

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

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

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

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

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

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

                            table1.getDefaultCell().setColspan(6);

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

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

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

                        }

                        docPdf.add(table1);

                    } catch (java.sql.SQLException SqlExec) {

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

                    }

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

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

                }

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

                try {

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

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

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

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

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

                    table3.setWidths(headerwidths3);

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

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

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

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

                    table3.getDefaultCell().setColspan(2);

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

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

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

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

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

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

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

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

                    String coment = "";

                    try {

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

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

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

                        while (rset1.next()) {

                            // value = qty * price;

                            cnt = cnt + 1;

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

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

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

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

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

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

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

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

                        }

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

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

                        table.getDefaultCell().setFixedHeight(20);

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

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

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

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

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

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

                        //                            table3.addCell(phrase);

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

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

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

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

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

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

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

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

                        table.addCell(phrase);

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

                        table.addCell(phrase);

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

                        table.getDefaultCell().setColspan(3);

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

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

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

                        table.addCell(phrase);

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

                        table.addCell(phrase);

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

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(3);

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

                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(2);

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

                        table.addCell(phrase);

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

                        table.addCell(phrase);

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

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

                        table.getDefaultCell().setColspan(9);

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

                        table.addCell(phrase);

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

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

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

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

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

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

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

                    }

                    // }

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

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

                }

            } catch (java.io.FileNotFoundException fnfExec) {

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

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

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

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

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

    } catch (java.io.IOException IOexec) {

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

    }

}

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

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

    java.lang.Process wait_for_Pdf2Show;

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

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

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

    try {/*from   www.ja v a2  s  .  c  om*/

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

        tempFile.deleteOnExit();

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

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;

        //        com.lowagie.text.Document docPdf = new com.lowagie.text.Document(com.lowagie.text.PageSize.A4,40,40,40,40);

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

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

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

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

                String compName = null;
                String date = null;

                try {

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

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

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

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

                }

                docPdf.open();

                String Username = null;
                int numColumns = 9;

                try {

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

                    long dateNow = calendar.getTimeInMillis();

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

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

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

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

                    // table.endHeaders();

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

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

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

                    table1.getDefaultCell().setColspan(7);

                    Phrase phrase = new Phrase();

                    //  table.addCell(phrase);

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

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

                            table1.getDefaultCell().setColspan(6);

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

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

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

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

                }

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

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

                    //  table1.setWidths(headerwidths1);

                    table1.setWidthPercentage((100));

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

                    try {

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

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

                        while (rset4.next()) {

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

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

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

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

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

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

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

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

                            table1.getDefaultCell().setColspan(6);

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

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

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

                        }

                        docPdf.add(table1);

                    } catch (java.sql.SQLException SqlExec) {

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

                    }

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

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

                }

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

                try {

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

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

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

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

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

                    table3.setWidths(headerwidths3);

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

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

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

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

                    table3.getDefaultCell().setColspan(2);

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

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

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

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

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

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

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

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

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

                    String coment = "";

                    try {

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

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

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

                        while (rset1.next()) {

                            // value = qty * price;

                            cnt = cnt + 1;

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

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

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

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

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

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

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

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

                        }

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

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

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

                        table.getDefaultCell().setColspan(9);

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

                        table.addCell(phrase);

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

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

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

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

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

                        docPdf.add(table);

                    } catch (java.sql.SQLException SqlExec) {

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

                    }

                    // }

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

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

                }

                try {

                    Phrase phrase = new Phrase();

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

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

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((100));

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

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

                    table.getDefaultCell().setFixedHeight(20);

                    //                         

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

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

                    table.addCell(phrase);

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

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

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

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

                    table.addCell(phrase);

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

                    table.addCell(phrase);

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

                    table.getDefaultCell().setColspan(3);

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

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

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

                    table.addCell(phrase);

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

                    table.addCell(phrase);

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

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(3);

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

                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(2);

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

                    table.addCell(phrase);

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

                    table.addCell(phrase);

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

                    table.addCell(phrase);

                    //down

                    docPdf.add(table);

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

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

                }
            }

            catch (java.io.FileNotFoundException fnfExec) {

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

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

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

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

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

    } catch (java.io.IOException IOexec) {

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

    }

}

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

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

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

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

        formLabel = "PATIENT REGISTRATION FORM";

    } else {//  ww w. ja v  a  2  s . c om
        formLabel = "PATIENT ADMISSION FORM";
    }

    java.lang.Process wait_for_Pdf2Show;

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

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

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

    try {

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

        tempFile.deleteOnExit();

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

        java.lang.String debitTotal = null;

        java.lang.String creditTotal = null;

        //com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
        com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

        try {

            try {

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

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

                docPdf.setFooter(footer);

                docPdf.open();

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

                long dateNow = calendar.getTimeInMillis();

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

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

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

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

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

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

                    int headerwidths2[] = { 30, 70 };

                    table2.setWidths(headerwidths2);

                    table2.setWidthPercentage((100));

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

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

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

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

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

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

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

                    table.getDefaultCell().setColspan(5);

                    phrase = new Phrase(formLabel, pFontHeader2);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    }

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

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

                    table.addCell(phrase);

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

                    Barcode128 code128 = new Barcode128();

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

                    code128.setBarHeight(16);

                    code128.setTextAlignment(Element.ALIGN_LEFT);

                    docPdf.add(table);

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

                    //                        docPdf.add(new com.itextpdf.text.Paragraph("Barcode QRCode"));
                    //                        BarcodeQRCode qrcode = new BarcodeQRCode(patientNumber.toUpperCase() + " " + patientName.toUpperCase(), 1, 1, null);
                    //                        com.itextpdf.text.Image qrimg = qrcode.getImage();
                    //                        docPdf.add(qrimg);
                    //  docPdf.add(table);
                } catch (com.lowagie.text.BadElementException BadElExec) {

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

                }

            } catch (java.io.FileNotFoundException fnfExec) {

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

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

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

        }

        docPdf.close();

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

    } catch (java.io.IOException IOexec) {

        IOexec.printStackTrace();

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

    }
}