Example usage for com.lowagie.text Document Document

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

Introduction

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

Prototype


public Document(Rectangle pageSize) 

Source Link

Document

Constructs a new Document -object.

Usage

From source file:QMSMultiQuoteController.java

License:Open Source License

private byte[] concatPDF(ArrayList pdfFilesList) {
    byte[] buffer = null;
    FileOutputStream filestream = null;
    try {/*ww  w.  j  a va  2  s. c  o m*/
        int i = 1;

        Document document = null;
        PdfCopy pdfcopy = null;

        if (pdfFilesList.size() > 1) {
            String s = (String) pdfFilesList.get(0);
            int pdfFilListSize = pdfFilesList.size();
            for (; i < pdfFilListSize; i++) {
                PdfReader pdfreader = new PdfReader((String) pdfFilesList.get(i));
                int j = pdfreader.getNumberOfPages();
                if (i == 1) {
                    document = new Document(pdfreader.getPageSizeWithRotation(1));
                    filestream = new FileOutputStream(s);
                    pdfcopy = new PdfCopy(document, filestream);
                    document.open();
                }
                PdfImportedPage pdfimportedpage = null;
                for (int k = 0; k < j;) {
                    k++;
                    pdfimportedpage = pdfcopy.getImportedPage(pdfreader, k);
                    if (pdfimportedpage != null) {
                        pdfcopy.addPage(pdfimportedpage);
                    }
                }

                com.lowagie.text.pdf.PRAcroForm pracroform = pdfreader.getAcroForm();
                if (pracroform != null)
                    pdfcopy.copyAcroForm(pdfreader);
            }

            if (document != null) {
                document.close();
            }

            FileInputStream inputStream = new FileInputStream(s);
            buffer = new byte[inputStream.available()];
            inputStream.read(buffer);
        }
        // buffer  = pdfcopy.getDirectContent();

    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return buffer;
}

From source file:QMSMultiQuoteController.java

License:Open Source License

private ArrayList doPDFGenerationForQuoteGroup(ArrayList mainDtl, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String[] contents = null;/* w  w w.  j  a  v a2s.c  o  m*/
    String[] levels = null;
    String[] aligns = null;
    String[] headFoot = null;
    Table content = null;
    String[] contactPersons = null;
    String contactName = null;
    ArrayList contactList = new ArrayList();
    ArrayList contactEmailList = new ArrayList();
    ArrayList contactFaxList = new ArrayList();
    ArrayList returnList = new ArrayList();
    ArrayList sentEmailsList = new ArrayList();
    ArrayList unsentEmailsList = new ArrayList();
    ArrayList sentFaxList = new ArrayList();
    ArrayList unsentFaxList = new ArrayList();
    ArrayList filesDOBList = new ArrayList();
    ArrayList filesList = new ArrayList();
    HttpSession session = null;

    try {
        //System.out.println("PDF Generation Startd----------------------------------->");
        MultiQuoteFinalDOB finalDOB = null;
        ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
        MultiQuoteHeader headerDOB = null;
        MultiQuoteMasterDOB masterDOB = null;
        CostingMasterDOB costingMasterDOB = null;
        CostingChargeDetailsDOB detailsDOB = null;
        CostingLegDetailsDOB legDetails = null;
        CostingRateInfoDOB rateDetailsDOB = null;
        ArrayList rateDetails = new ArrayList();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String formMailId = "";
        String to_emailIds = "";
        String to_FaxIds = "";
        String faxMailIds = "";
        Document document = new Document(PageSize.A4);
        String PDF_FILE_NAME = "Approved.pdf";
        document.addTitle("Approved Report");
        document.addSubject("Report PDF");
        document.addKeywords("Test, Key Words");
        document.addAuthor("DHL");
        document.addCreator("Auto Generated through 4S DHL");
        document.addCreationDate();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        Table partCountry;
        Chunk chk;
        Cell cellCountry;
        if (mainDtl != null && mainDtl.size() > 0) {

            finalDOB = (MultiQuoteFinalDOB) mainDtl.get(0);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            formMailId = "webmaster@four-soft.com";
            ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                    .getAttribute("loginbean");
            eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
            //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());

            String[] strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            String[] effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
            String[] validDate;

            // System.out.println("Before Document Objec--------------------------->");

            //document.setMargins(10,10,10,10);

            Table mainT = new Table(8);
            mainT.setWidth(100);
            mainT.setBorderColor(Color.white);
            mainT.setPadding(1);
            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.setColspan(7);
            mainT.addCell(cellHeading);

            Cell imageCell = new Cell();
            java.net.URL url = getServletConfig().getServletContext().getResource("/images/DHLlogo.gif");
            Image img0 = Image.getInstance(url);
            imageCell.add(img0);
            imageCell.setHorizontalAlignment(imageCell.ALIGN_RIGHT);
            imageCell.setBorderWidth(0);
            imageCell.setNoWrap(true);
            mainT.addCell(imageCell);
            mainT.setAlignment(mainT.ALIGN_CENTER);
            document.add(mainT);

            //Default Header Content Starts
            contents = masterDOB.getDefaultContent();
            headFoot = masterDOB.getDefaultHeaderFooter();

            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 hFLen = headFoot.length;
                for (int i = 0; i < hFLen; 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(6.0f);
                        cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);//Default content is left aligned                                    
                        content.addCell(cellContent);
                    }
                }
                document.add(content);
                contents = null;
                headFoot = null;
                content = null;
            }
            //End Default Header Content

            //System.out.println("After Heading --------------------------->");
        }
        String validUptoStr = null;
        String[] strDate = null;
        String[] effDate = null;
        String[] validDate = null;
        StringBuffer attentionTo = null;
        int mainDtlSize = mainDtl.size();
        for (int m = 0; m < mainDtlSize; m++) {

            finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            //formMailId             =   "webmaster@four-soft.com";
            ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                    .getAttribute("loginbean");
            eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
            //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());

            strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
            attentionTo = new StringBuffer("");

            if (headerDOB.getValidUpto() != null) {
                validDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getValidUpto());
                validUptoStr = validDate[0];
            }
            if (masterDOB.getCustContactNames() != null) {
                for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                    // Logger.info(FILE_NAME,"headerDOB.getAttentionTo()::"+masterDOB.getCustomerContacts()[i]);
                    attentionTo.append(
                            masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i]
                                    : "");
                    if (i != masterDOB.getCustContactNames().length)
                        attentionTo.append(",");
                }
            }
            partCountry = new Table(1, 5);
            partCountry.setBorderWidth(0);
            partCountry.setWidth(100);
            partCountry.setBorderColor(Color.black);
            //partCountry.setBackgroundColor(Color.ORANGE);
            partCountry.setPadding(1);
            partCountry.setBorder(0);//Modified by silpa.p on 3-06-11
            partCountry.setSpacing(0);
            partCountry.setAutoFillEmptyCells(true);
            //partCountry.setTableFitsPage(true);
            partCountry.setAlignment(partCountry.ALIGN_CENTER);
            // partCountry.setWidth(100.0f);

            String shipmentMode = "";
            if (finalDOB.getMasterDOB().getShipmentMode() == 1)
                shipmentMode = "AIR FREIGHT PROPOSAL";
            else if (finalDOB.getMasterDOB().getShipmentMode() == 2)
                shipmentMode = "SEA FREIGHT PROPOSAL";
            else if (finalDOB.getMasterDOB().getShipmentMode() == 4)
                shipmentMode = "TRUCK FREIGHT PROPOSAL";

            chk = new Chunk(shipmentMode, 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);
            //@@Modified for the WPBN Change Request-71229
            if ("MY".equalsIgnoreCase(masterDOB.getCountryId())) {
                chk = new Chunk(headerDOB.getOriginCountry() + " TO " + headerDOB.getDestinationCountry(),
                        FontFactory.getFont("ARIAL", 12, 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);

                chk = new Chunk(headerDOB.getCustomerName() == null ? "" : headerDOB.getCustomerName(),
                        FontFactory.getFont("ARIAL", 12, 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: " + toTitleCase(attentionTo.toString()),
                        FontFactory.getFont("ARIAL", 12, 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 {
                chk = new Chunk(headerDOB.getOriginCountry() + " TO " + headerDOB.getDestinationCountry(),
                        FontFactory.getFont("ARIAL", 12, 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);

                chk = new Chunk(headerDOB.getCustomerName() == null ? "" : headerDOB.getCustomerName(),
                        FontFactory.getFont("ARIAL", 12, 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: " + toTitleCase(attentionTo.toString()),
                        FontFactory.getFont("ARIAL", 12, 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);
            }
            //@@WPBN Change Request-71229
            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();

            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 hFlen = headFoot.length;
                for (int i = 0; i < hFlen; 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(6.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);
            }

            partCountry = new Table(2, 15);
            partCountry.setOffset(2);
            partCountry.setWidth(100);
            partCountry.setPadding(1);
            partCountry.setSpacing(0);
            partCountry.setBackgroundColor(Color.WHITE);
            partCountry.setBorderColor(Color.black);
            partCountry.setBorderWidth(1);
            //added by subrahmanyam for 182516
            partCountry.setTableFitsPage(true);
            partCountry.setCellsFitPage(true);
            //ended for 182516

            chk = new Chunk("SERVICE INFORMATION: ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellCountry = new Cell(chk);

            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Commented by subrahmanyam for the enhancement #146970 & #146971            
            /*chk = new Chunk("QUOTE ID:"+new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);*/
            //@@ Added by subrahmanyam for the enhancement #146970 & #146971            
            chk = new Chunk("QUOTE ID:" + masterDOB.getQuoteId(),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            /** chk = new Chunk("Origin : ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk); 
             cellCountry.setBackgroundColor(Color.lightGray);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);
                     
             chk = new Chunk("   "+(headerDOB.getOriginLocName()!=null?headerDOB.getOriginLocName():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);
                     
             chk = new Chunk("Destination : ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk); 
             cellCountry.setBackgroundColor(Color.lightGray);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);
                     
             chk = new Chunk("   "+(headerDOB.getDestLocName()!=null?headerDOB.getDestLocName():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);**/

            chk = new Chunk("Customer : ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getCustomerName() != null ? headerDOB.getCustomerName() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            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.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getAgent() != null ? headerDOB.getAgent() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Added by subrahmanyam for the WPBN ISSUE: 150460 ON 23/12/2008                

            //@@ Ended by subrahmanyam for the WPBN ISSUE: 150460 ON 23/12/2008  

            // @@Commented by subrahmanyam for the enhancement #148546 on 09/12/2008            
            /* chk = new Chunk("Routing: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setBackgroundColor(Color.lightGray);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);          
             chk = new Chunk("   "+(headerDOB.getRouting()!=null?headerDOB.getRouting():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);*/
            //@@ Ended by subrahmanyam for the enhanement #148546 on 09/12/2008 

            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //chk = new Chunk("   "+(headerDOB.getCommodity()!=null?toTitleCase(headerDOB.getCommodity()):""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));//commented by silpa.p on 21-06-11
            chk = new Chunk("   " + (headerDOB.getCommodity() != null ? (headerDOB.getCommodity()) : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));//modified by silpa.p on 21-06-11
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getTypeOfService() != null ? headerDOB.getTypeOfService() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Commented by subrahmanyam for WPBN ISSUE:-145510                                      
            /* chk = new Chunk("   "+(headerDOB.getNotes()!=null?headerDOB.getNotes().toUpperCase()+'\n'+"nnnnnnnnnn":""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            Commented by subrahmanyam for WPBN ISSUE:-145510   
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
                    
            partCountry.addCell(cellCountry);
            */
            //@@ Ended by subrahmanyam for WPBN ISSUE:-145510  
            //@@ Added by subrahmanyam for WPBN ISSUE:-145510  
            chk = new Chunk("   " + (headerDOB.getNotes() != null ? headerDOB.getNotes().toUpperCase() : " "),
                    FontFactory.getFont("ARIAL", 7, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);
            //@@ Ended by subrahmanyam for WPBN ISSUE:-145510   

            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + effDate[0], FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            document.add(partCountry);
            partCountry.complete();
        }
        int originCount = 0;
        int freightCount = 0;
        int destCount = 0;
        for (int m = 0; m < mainDtlSize; m++) {

            finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
            // added by kiran.v on 16/09/2011
            //added by Anusha V.
            session = request.getSession();
            session.setAttribute("finalDOBPdf", finalDOB);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            // System.out.println("After Page Country-------------------------------->");
            //Origin Charges

            costingMasterDOB = finalDOB.getCostingMasterDOB();

            ArrayList originCharges = (ArrayList) costingMasterDOB.getOriginList();

            int[] originIndices = finalDOB.getSelectedOriginChargesListIndices();
            int originChargesSize = 0;

            if (originCharges != null)
                originChargesSize = originCharges.size();
            else
                originChargesSize = 0;

            //Destination
            ArrayList destCharges = new ArrayList();
            int[] destIndices = finalDOB.getSelctedDestChargesListIndices();
            int destChargesSize = 0;
            if (destIndices != null)
                destChargesSize = destIndices.length;
            else
                destChargesSize = 0;

            ArrayList frieghtChargeDetails = new ArrayList();
            destCharges = (ArrayList) costingMasterDOB.getDestinationList();
            ArrayList costingLegDetailsList = new ArrayList();
            costingLegDetailsList = (ArrayList) costingMasterDOB.getCostingLegDetailsList();
            //////////////////////////////
            int orgChargSize = originCharges.size();
            for (int i = 0; i < orgChargSize; i++) {
                detailsDOB = (CostingChargeDetailsDOB) originCharges.get(i);
                rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                int rateDtlSize = rateDetails.size();
                for (int k = 0; k < rateDtlSize; k++) {
                    originCount++;
                }
            }
            int destChargSize = destCharges.size();
            for (int i = 0; i < destChargSize; i++) {
                detailsDOB = (CostingChargeDetailsDOB) destCharges.get(i);
                rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                int rateDtlSize = rateDetails.size();
                for (int k = 0; k < rateDtlSize; k++) {
                    destCount++;
                }
            }
            int costLegDtlSize = costingLegDetailsList.size();
            for (int s = 0; s < costLegDtlSize; s++) {
                legDetails = (CostingLegDetailsDOB) costingLegDetailsList.get(s);
                frieghtChargeDetails = (ArrayList) legDetails.getCostingChargeDetailList();
                int frtChargDtlSize = frieghtChargeDetails.size();
                for (int n = 0; n < frtChargDtlSize; n++) {
                    detailsDOB = (CostingChargeDetailsDOB) frieghtChargeDetails.get(n);
                    rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                    int rateDtlSize = rateDetails.size();
                    for (int j = 0; j < rateDtlSize; j++) {
                        freightCount++;
                    }
                }
            }

        }

        //////////////////////////////
        ArrayList charges = finalDOB.getLegDetails();
        int chargesSize = charges.size();
        if (originCount > 0) {
            Table chargeCountry = new Table(7, originCount);
            chargeCountry.setWidth(100);
            chargeCountry.setPadding(1);
            chargeCountry.setSpacing(0);
            chargeCountry.setOffset(25);
            chargeCountry.setBackgroundColor(Color.WHITE);
            chargeCountry.setBorderColor(Color.black);
            chargeCountry.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry.setTableFitsPage(true);
            chargeCountry.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell;
            String wBslab = "";
            chk = new Chunk("QUOTEID ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("CHARGE NAME ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("ORIGIN CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setColspan(7);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);
            for (int m = 0; m < mainDtlSize; m++) {

                finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();

                costingMasterDOB = finalDOB.getCostingMasterDOB();
                ArrayList originCharges = (ArrayList) costingMasterDOB.getOriginList();

                MultiQuoteCharges chargesDOB = null;
                ArrayList originChargeInfo = null;
                int originChargesInfoSize = 0;
                MultiQuoteChargeInfo chargeInfo = null;
                if (originCharges.size() > 0) {

                    int orgChargSize = originCharges.size();
                    for (int i = 0; i < orgChargSize; i++) {
                        detailsDOB = (CostingChargeDetailsDOB) originCharges.get(i);
                        rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();

                        originChargesInfoSize = rateDetails.size();
                        for (int k = 0; k < originChargesInfoSize; k++) {
                            CostingRateInfoDOB crateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(k);
                            if (k == 0) {
                                //@@ Commented by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008                    
                                /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                cell = new Cell(chk);
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true); cell.setLeading(8.0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);*/
                                //@@ Added by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    
                                chk = new Chunk(masterDOB.getQuoteId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell = new Cell(chk);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                chargeCountry.addCell(cell);
                                //@@ Ended by subrahmanyam for the enhanemenet #146971 and #146970 on 10/12/2008 

                                //@@ commented and modified by subrahmanyam for 181349  on 07-sep-09 & 202166 on 7-apr-10
                                // chk = new Chunk(detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(
                                        detailsDOB.getExternalName() != null ? detailsDOB.getExternalName()
                                                : detailsDOB.getChargeDescId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));//ended for 181349
                                cell = new Cell(chk);
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                // cell.setNoWrap(true); //commented for 181349
                                cell.setLeading(8.0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);
                            } else {
                                cell = new Cell("");
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                cell.setBorderWidth(0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);

                                cell = new Cell("");
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                cell.setBorderWidth(0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);
                            }
                            chk = new Chunk(crateDetailsDOB.getWeightBreakSlab(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setBackgroundColor(Color.lightGray);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(detailsDOB.getCurrency(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setBackgroundColor(Color.lightGray);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(crateDetailsDOB.getRate() + "",
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            //added by subrahmanyam for 183812
                            if (crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                    || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType())
                                            && "F".equalsIgnoreCase(crateDetailsDOB.getRateIndicator()))) {
                                wBslab = "MIN";
                            } else
                                wBslab = detailsDOB.getChargeBasisDesc();
                            // @@ Commented & Added by subrahmanyam for the wpbn id: 182516 on 10/09/09
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?" Per Shipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            chk = new Chunk(
                                    wBslab.equalsIgnoreCase("Min") ? " Per Shipment "
                                            : detailsDOB.getChargeBasisDesc(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(
                                    detailsDOB.getDensityRatio() == null ? "" : detailsDOB.getDensityRatio(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                        }
                    }
                }
            }
            document.add(chargeCountry);
        }
        if (freightCount > 0) {
            Table chargeCountry1 = new Table(7, freightCount);
            chargeCountry1.setWidth(100);
            chargeCountry1.setPadding(1);
            chargeCountry1.setSpacing(0);
            chargeCountry1.setOffset(25);
            chargeCountry1.setBackgroundColor(Color.WHITE);
            chargeCountry1.setBorderColor(Color.black);
            chargeCountry1.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry1.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry1.setTableFitsPage(true);
            chargeCountry1.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell1;
            chk = new Chunk(" QUOTEID", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);
            chk = new Chunk("CHARGE NAME ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            // cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            // cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("FREIGHT CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setColspan(7);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            cell1.setBackgroundColor(Color.ORANGE);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);
            //Freight Charges
            // System.out.println("After         Origin Charges --------------------------------->");
            int freightChargesSize = 0;
            int freightChargesInfoSize = 0;
            int[] frtIndices = null;
            MultiQuoteFreightLegSellRates legCharges = null;
            String wBSlab = "";//added by subrahmanyam for 182516 on 10-sep-09             
            int mDtlSize = mainDtl.size();
            for (int m = 0; m < mDtlSize; m++) {

                finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();
                ArrayList costingLegDetailsList = new ArrayList();
                costingMasterDOB = finalDOB.getCostingMasterDOB();
                costingLegDetailsList = (ArrayList) costingMasterDOB.getCostingLegDetailsList();
                ArrayList frieghtChargeDetails = new ArrayList();
                String rDescription = ""; // Added by subrahmanyam for 182516 on 10/09/09
                if (costingLegDetailsList.size() > 0) {

                    int costLegDtlSize = costingLegDetailsList.size();
                    for (int s = 0; s < costLegDtlSize; s++) {
                        legDetails = (CostingLegDetailsDOB) costingLegDetailsList.get(s);
                        frieghtChargeDetails = (ArrayList) legDetails.getCostingChargeDetailList();
                        int frtLegDtlSize = frieghtChargeDetails.size();
                        int frtChargDtlSize = frieghtChargeDetails.size();
                        for (int n = 0; n < frtChargDtlSize; n++) {
                            detailsDOB = (CostingChargeDetailsDOB) frieghtChargeDetails.get(n);
                            rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                            int rateDtlSize = rateDetails.size();
                            for (int j = 0; j < rateDtlSize; j++) {
                                rateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(j);

                                if (j == 0) {

                                    chk = new Chunk(legDetails.getOrigin() + "-" + legDetails.getDestination(),
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    cell1.setColspan(7);
                                    cell1.setBackgroundColor(Color.WHITE);
                                    cell1.setLeading(8.0f);
                                    chargeCountry1.addCell(cell1);

                                    //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
                                    /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                    cell1 = new Cell(chk);
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true); cell2.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);*/
                                    //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
                                    chk = new Chunk(masterDOB.getQuoteId(),
                                            FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);
                                    //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    
                                    // COMMENTED AND MODIFIED BY SUBRAHMANYAM FOR 182516
                                    //chk = new Chunk(detailsDOB.getChargeDescId()==null?"":detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                    chk = new Chunk(
                                            rateDetailsDOB.getRateDescription() == null ? ""
                                                    : rateDetailsDOB.getRateDescription(),
                                            FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);
                                    rDescription = rateDetailsDOB.getRateDescription();
                                } else {
                                    cell1 = new Cell("");
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBorderWidth(0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);

                                    //@@ Commented by subrahmanyam for 182516 on 10/09/09
                                    /*
                                     cell1 = new Cell("");
                                     //cell1.setRowspan(rateDetails.size());
                                     cell1.setNoWrap(true); cell1.setLeading(8.0f);
                                     cell1.setBackgroundColor(Color.lightGray);
                                     cell1.setBorderWidth(0f);
                                     chargeCountry1.addCell(cell1);
                                     */
                                    //@@ added by subrahmanyam for 182516 on 10/09/09
                                    if (rDescription.equalsIgnoreCase(rateDetailsDOB.getRateDescription())) {
                                        chk = new Chunk("",
                                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                        cell1 = new Cell(chk);
                                        //cell1.setRowspan(rateDetails.size());
                                        cell1.setNoWrap(true);
                                        cell1.setLeading(8.0f);
                                        cell1.setBackgroundColor(Color.lightGray);
                                        cell1.setBorderWidth(0f);
                                        chargeCountry1.addCell(cell1);
                                    } else {
                                        chk = new Chunk(
                                                rateDetailsDOB.getRateDescription() == null ? ""
                                                        : rateDetailsDOB.getRateDescription(),
                                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                        cell1 = new Cell(chk);
                                        //cell1.setRowspan(rateDetails.size());
                                        //cell1.setNoWrap(true);
                                        cell1.setLeading(8.0f);
                                        cell1.setBackgroundColor(Color.lightGray);
                                        chargeCountry1.addCell(cell1);
                                        rDescription = rateDetailsDOB.getRateDescription();
                                    }
                                    //ended by subrahmanyam for 182516 on 10/09/09

                                }
                                if ("FSBASIC".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSBASIC".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Basic Charge");
                                if ("FSMIN".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSMIN".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Minimum");
                                if ("FSKG".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSKG".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Flat Rate");

                                chk = new Chunk(rateDetailsDOB.getWeightBreakSlab(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                cell1.setBackgroundColor(Color.lightGray);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(detailsDOB.getCurrency(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                cell1.setBackgroundColor(Color.lightGray);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(rateDetailsDOB.getRate() + "",
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                                //@@ Added by subrahmanyam for wpbn id: 182516
                                // MODIFIED BY SUBRAHMANYAM FOR 183812
                                if (rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                        || rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Minimum")
                                        || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType()) && "FLAT"
                                                .equalsIgnoreCase(rateDetailsDOB.getRateIndicator()))) {
                                    wBSlab = "MIN";
                                } else {
                                    wBSlab = rateDetailsDOB.getWeightBreakSlab();
                                }
                                //@@ commented by subrahmanyam for wpbn id: 182516
                                //chk = new Chunk(rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                //@@ Added by subrahmanyam for wpbn id: 182516
                                chk = new Chunk(
                                        wBSlab.equalsIgnoreCase("Min") ? " Per Shipment "
                                                : detailsDOB.getChargeBasisDesc(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                //@@ Ended  for wpbn id: 182516
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(
                                        detailsDOB.getDensityRatio() == null ? ""
                                                : detailsDOB.getDensityRatio(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                            }
                        }
                    }
                }
            }
            document.add(chargeCountry1);
        }
        // System.out.println("After Charges--------------------------------->");
        ArrayList destChargeInfo = null;
        //int[]      destChargeInfo        =  null;
        int destChargesInfoSize = 0;
        if (destCount > 0) {
            Table chargeCountry2 = new Table(7, destCount);
            chargeCountry2.setWidth(100);
            chargeCountry2.setPadding(1);
            chargeCountry2.setSpacing(0);
            chargeCountry2.setOffset(25);
            chargeCountry2.setBackgroundColor(Color.WHITE);
            chargeCountry2.setBorderColor(Color.black);
            chargeCountry2.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry2.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry2.setTableFitsPage(true);
            chargeCountry2.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell2;
            String wBslab = "";
            chk = new Chunk("QUOTEID", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("CHARGE NAME", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("DESTINATION CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setColspan(7);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);
            int mDtlSize = mainDtl.size();
            for (int m = 0; m < mDtlSize; m++) {

                finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();
                costingMasterDOB = finalDOB.getCostingMasterDOB();
                ArrayList destCharges = (ArrayList) costingMasterDOB.getDestinationList();
                if (destCharges.size() > 0) {

                    int destChargSize = destCharges.size();

                    for (int i = 0; i < destChargSize; i++) {

                        detailsDOB = (CostingChargeDetailsDOB) destCharges.get(i);
                        rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();

                        //originChargesInfoSize   = rateDetails.size();
                        int rDtlSize = rateDetails.size();
                        for (int k = 0; k < rDtlSize; k++) {
                            CostingRateInfoDOB crateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(k);

                            if (k == 0) {

                                //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
                                /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                cell2 = new Cell(chk);
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true); cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);*/
                                //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
                                chk = new Chunk(masterDOB.getQuoteId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell2 = new Cell(chk);
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);
                                //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    

                                //  chk = new Chunk(detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                //@@ Added by subrahmanyam for the wpbn id: 181349  on 07-sep-09
                                chk = new Chunk(
                                        detailsDOB.getExternalName() != null ? detailsDOB.getExternalName()
                                                : detailsDOB.getChargeDescId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));//ended for 181349
                                cell2 = new Cell(chk);
                                //cell2.setRowspan(rateDetails.size());
                                //cell2.setNoWrap(true); //commented for 181349
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);
                            } else {
                                cell2 = new Cell("");
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                cell2.setBorderWidth(0f);
                                chargeCountry2.addCell(cell2);

                                cell2 = new Cell("");
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                cell2.setBorderWidth(0f);
                                chargeCountry2.addCell(cell2);
                            }
                            chk = new Chunk(crateDetailsDOB.getWeightBreakSlab(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            cell2.setBackgroundColor(Color.lightGray);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(detailsDOB.getCurrency(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            cell2.setBackgroundColor(Color.lightGray);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(crateDetailsDOB.getRate() + "",
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);

                            //@@ Commented & Added  by subrahmanyam for 182516 on 10/09/09
                            // chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            //ADDED BY SUBRAHMANYAM FOR 183812
                            if (crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                    || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType())
                                            && "F".equalsIgnoreCase(crateDetailsDOB.getRateIndicator()))) {
                                wBslab = "MIN";
                            } else
                                wBslab = detailsDOB.getChargeBasisDesc();
                            // COMMENTED & added FOR 183812 ON 24-09-09
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?" Per Shipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            chk = new Chunk(
                                    wBslab.equalsIgnoreCase("Min") ? " Per Shipment "
                                            : detailsDOB.getChargeBasisDesc(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(
                                    detailsDOB.getDensityRatio() == null ? "" : detailsDOB.getDensityRatio(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);
                        }
                    }
                }
            }
            document.add(chargeCountry2);
        }

        Table notes = new Table(2, mainDtl.size());
        boolean displayFlag = false;
        notes.setWidth(100);
        notes.setPadding(1);
        notes.setSpacing(0);
        notes.setOffset(5);
        notes.setBackgroundColor(Color.WHITE);
        notes.setBorderColor(Color.black);
        notes.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
        notes.setBorderWidth(1);
        notes.setTableFitsPage(true);// added by subrahmanyam for quoteGrouping issue 184848
        notes.setCellsFitPage(true);// added by subrahmanyam for quoteGrouping issue 184848

        Cell cell3;
        chk = new Chunk("QUOTEID ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
        cell3 = new Cell(chk);
        cell3.setNoWrap(true);
        cell3.setLeading(8.0f);
        cell3.setBackgroundColor(Color.ORANGE);
        //cell3.setVerticalAlignment(cell3.ALIGN_MIDDLE);
        //cell3.setBackgroundColor(Color.lightGray);
        notes.addCell(cell3);

        chk = new Chunk("NOTES", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
        cell3 = new Cell(chk);
        cell3.setNoWrap(true);
        cell3.setLeading(8.0f);
        cell3.setBackgroundColor(Color.ORANGE);
        //cell3.setVerticalAlignment(cell3.ALIGN_MIDDLE);

        notes.addCell(cell3);
        int mDtlSize = mainDtl.size();
        for (int m = 0; m < mDtlSize; m++) {

            finalDOB = (MultiQuoteFinalDOB) mainDtl.get(m);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            costingMasterDOB = finalDOB.getCostingMasterDOB();
            if (costingMasterDOB != null) {
            }
            //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
            /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cell3 = new Cell(chk);
            //cell3.setRowspan(rateDetails.size());
            cell3.setNoWrap(true); cell3.setLeading(8.0f);
            cell3.setBackgroundColor(Color.lightGray);
            notes.addCell(cell3);*/
            //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
            //commented by subrahmanyam for quote grouping issue
            /*
                 chk = new Chunk(masterDOB.getQuoteId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cell3 = new Cell(chk);
            cell3.setNoWrap(true); cell3.setLeading(8.0f);
            cell3.setBackgroundColor(Color.lightGray);
            notes.addCell(cell3);
                //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008
                    
            chk = new Chunk(" ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cell3 = new Cell(chk);
            //cell3.setRowspan();
            cell3.setNoWrap(true); cell3.setLeading(8.0f);
            cell3.setBackgroundColor(Color.lightGray);
            notes.addCell(cell3);
            */
            //@@ Added by subrahmanyam for Quote Grouping Issue 184848 on 30/sep/09
            if (finalDOB.getExternalNotes() != null && finalDOB.getExternalNotes().length > 0) {
                int notesLength = finalDOB.getExternalNotes().length;
                for (int n = 0; n < notesLength; n++) {
                    if (n == 0) {
                        chk = new Chunk(masterDOB.getQuoteId(),
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        cell3.setNoWrap(true);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                        //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008

                        chk = new Chunk(finalDOB.getExternalNotes()[n],
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        //cell3.setRowspan();
                        //cell3.setNoWrap(true);
                        cell3.setHorizontalAlignment(cell3.ALIGN_LEFT);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                    } else {
                        chk = new Chunk("", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        cell3.setNoWrap(true);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                        //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008

                        chk = new Chunk(finalDOB.getExternalNotes()[n],
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        //cell3.setRowspan();
                        // cell3.setNoWrap(true);
                        cell3.setHorizontalAlignment(cell3.ALIGN_LEFT);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                    }
                }
            } else {
                chk = new Chunk(masterDOB.getQuoteId(),
                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cell3 = new Cell(chk);
                cell3.setNoWrap(true);
                cell3.setLeading(8.0f);
                cell3.setBackgroundColor(Color.lightGray);
                notes.addCell(cell3);

                chk = new Chunk(" ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cell3 = new Cell(chk);
                //cell3.setRowspan();
                cell3.setNoWrap(true);
                cell3.setLeading(8.0f);
                cell3.setBackgroundColor(Color.lightGray);
                notes.addCell(cell3);
            }
            //@@ Ended by subrahmanyam for Quote Grouping Issue 184848 on 30/09/09

            contents = masterDOB.getContentOnQuote();
            levels = masterDOB.getLevels();
            aligns = masterDOB.getAlign();
            headFoot = masterDOB.getHeaderFooter();

            if (contents != null && contents.length > 0) {
                int hFLen = headFoot.length;
                for (int i = 0; i < hFLen; i++) {
                    if (headFoot[i] != null && "F".equalsIgnoreCase(headFoot[i])) {
                        displayFlag = true;
                        break;
                    }
                }
                if (displayFlag) {
                    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 = new Chunk("QUOTEID : " + masterDOB.getQuoteId(),
                            FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));
                    cellContent = new Cell(chk);
                    cellContent.setBorder(0);
                    cellContent.setLeading(6.0f);
                    cellContent.setHorizontalAlignment(cellContent.ALIGN_CENTER);
                    cellContent.setBackgroundColor(Color.ORANGE);
                    content.addCell(cellContent);
                    for (int i = 0; i < hFLen; i++) {
                        if (headFoot[i] != null && "F".equalsIgnoreCase(headFoot[i])) {
                            chk = new Chunk(contents[i] != null ? contents[i].toUpperCase() : "",
                                    FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));
                            cellContent = new Cell(chk);
                            cellContent.setBorder(0);
                            cellContent.setLeading(6.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);
                }
            }
        }
        document.add(notes);
        //Default Footer Content Starts
        contents = masterDOB.getDefaultContent();
        headFoot = masterDOB.getDefaultHeaderFooter();
        int hFLen = 0;
        if (headFoot != null)
            hFLen = headFoot.length;
        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;
            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));
                    cellContent = new Cell(chk);
                    cellContent.setBorder(0);
                    cellContent.setLeading(6.0f);
                    cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                    cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);//Default content is left aligned                                    
                    content.addCell(cellContent);

                }
            }
            document.add(content);
        }
        //End Default Footer Content

        // System.out.println("After     document Close----------------------------------------->");

        document.close();
        // Thread.sleep(100);
        //logger.info("thread");
        //String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime()+masterDOB.getQuoteId());  //@@ Commented by subrahmanyam for the Enhancement #146971 on 2/12/08
        // String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime()+Long.parseLong(masterDOB.getQuoteId()));  //@@ Added by subrahmanyam for the Enhancement #146971 on 2/12/08
        //Commenetd by Anusha V 
        //String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime())+masterDOB.getQuoteId(); //@@ Added by subrahmanyam for the Enhancement #146971 on 2/12/08
        //Added by Anusha V
        String file_tsmp = "" + new java.sql.Timestamp((new java.util.Date()).getTime());
        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" + file_tsmp + ".pdf");
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        baos.writeTo(fileOutputStream);
        fileOutputStream.close();
        //  logger.info("masterDOB.getUserId()"+masterDOB.getUserId());
        if ("on".equalsIgnoreCase(request.getParameter("print"))) {

            request.getSession().setAttribute("QuoteOuptutStream", f);
        }
        //  session.setAttribute("UserId",masterDOB.getUserId());

        int noOfQuotes = mainDtl.size();
        StringBuffer quoteIds = new StringBuffer("");
        String quoteType = "";
        String terminalAddress = "";
        String creatorDetails = "";
        String fromEmailId = "";
        String body = "";
        String countryCode = "";
        for (int i = 0; i < noOfQuotes; i++) {
            finalDOB = (MultiQuoteFinalDOB) mainDtl.get(i);
            /*  //@@Added for the WPBN issue-
              filesDOBList           =   finalDOB.getAttachmentDOBList(); 
              for(int j=0;j<filesDOBList.size();j++)
              {
               filesList.add(filesDOBList.get(j));
              } //@@Added for the WPBN issue-*/

            if (i == 0) {
                quoteType = "" + finalDOB.getMasterDOB().getShipmentMode();
                terminalAddress = finalDOB.getMasterDOB().getTerminalAddress();
                creatorDetails = finalDOB.getMasterDOB().getCreatorDetails();
                fromEmailId = finalDOB.getMasterDOB().getUserEmailId();
                countryCode = finalDOB.getHeaderDOB().getCustCountyCode();
                to_FaxIds = finalDOB.getHeaderDOB().getCustFaxNo();
                to_emailIds = finalDOB.getHeaderDOB().getCustEmailId();
            }
            quoteIds.append(finalDOB.getMasterDOB().getQuoteId());
            if (i != noOfQuotes - 1)
                quoteIds.append(",");

            contactPersons = finalDOB.getMasterDOB().getCustContactNames();
            if (contactPersons != null) {
                int contPersLen = contactPersons.length;
                for (int k = 0; k < contPersLen; k++) {
                    if (!contactList.contains(finalDOB.getMasterDOB().getCustContactNames()[k])) {
                        contactList.add(finalDOB.getMasterDOB().getCustContactNames()[k]);
                        contactEmailList.add(finalDOB.getMasterDOB().getCustomerContactsEmailIds()[k]);
                        contactFaxList.add(finalDOB.getMasterDOB().getCustomerContactsFax()[k]);
                    }
                }

            }

        }

        if ("1".equalsIgnoreCase(quoteType))
            quoteType = "Airfreight";
        else if ("2".equalsIgnoreCase(quoteType))
            quoteType = "Seafreight";
        else if ("4".equalsIgnoreCase(quoteType))
            quoteType = "Truckfreight";

        String subject = "DHL Global Forwarding Quotation, Multiple " + quoteType + ", Quote References "
                + quoteIds.toString();
        String message = "";
        //finalDOB.getFlagsDOB().setQuoteStatusFlag("PEN");//@@Quote is Pending
        //ReportsSessionBeanHome home      = (ReportsSessionBeanHome)LookUpBean.getEJBHome("ReportsSessionBean");
        //ReportsSession remote   = (ReportsSession)home.create();
        //if(contactList.size()==0)
        //{
        to_emailIds = to_emailIds.replaceAll(";", ",");
        /*message  = "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"+creatorDetails+"\n"+terminalAddress;*/
        //message   = "Dear Customer,\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+creatorDetails+"\n"+terminalAddress+"\n"+;       
        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 ("on".equalsIgnoreCase(request.getParameter("email"))) {
            try {
                sendMail(fromEmailId, to_emailIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                sentEmailsList.add(to_emailIds);
            } catch (FoursoftException fs) {
                //Logger.error(FILE_NAME,"Error While Sending Mail.."+fs.getMessage());
                logger.error(FILE_NAME + "Error While Sending Mail.." + fs.getMessage());
                fs.printStackTrace();
                unsentEmailsList.add(to_emailIds);
            }
        }
        if ("on".equalsIgnoreCase(request.getParameter("fax"))) {
            if ("SG".equalsIgnoreCase(countryCode))
                faxMailIds = "fax#" + to_FaxIds + "@tcdhl.com";
            else
                faxMailIds = "ifax#" + to_FaxIds + "@tcdhl.com";
            try {
                sendMail(fromEmailId, faxMailIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                sentFaxList.add(to_FaxIds);
            } catch (FoursoftException fs) {
                //Logger.error(FILE_NAME,"Error While Sending Fax.."+fs.getMessage());
                logger.error(FILE_NAME + "Error While Sending Fax.." + fs.getMessage());
                fs.printStackTrace();
                unsentFaxList.add(to_FaxIds);
            }
        }
        //}
        //else
        //{
        int contactSize = contactList.size();
        for (int i = 0; i < contactSize; i++) {
            contactName = (String) contactList.get(i);
            /*message = "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"+creatorDetails+"\n"+terminalAddress;*/
            // message = "Dear "+contactName+",\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+creatorDetails+"\n"+terminalAddress;         
            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 ("on".equalsIgnoreCase(request.getParameter("email"))) {
                try {
                    sendMail(fromEmailId, (String) contactEmailList.get(i), subject, message,
                            "Quote" + file_tsmp + ".pdf", null);
                    sentEmailsList.add(contactEmailList.get(i));
                } catch (FoursoftException fs) {
                    //Logger.error(FILE_NAME,"Error While Sending Mail.."+fs.getMessage());
                    logger.error(FILE_NAME + "Error While Sending Mail.." + fs.getMessage());
                    fs.printStackTrace();
                    unsentEmailsList.add(contactEmailList.get(i));
                }
            }
            if ("on".equalsIgnoreCase(request.getParameter("fax"))) {
                if ("SG".equalsIgnoreCase(countryCode))
                    to_FaxIds = "fax#" + contactFaxList.get(i) + "@tcdhl.com";
                else
                    to_FaxIds = "ifax#" + contactFaxList.get(i) + "@tcdhl.com";
                try {
                    sendMail(fromEmailId, to_FaxIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                    sentFaxList.add(contactFaxList.get(i));
                } catch (FoursoftException fs) {
                    //Logger.error(FILE_NAME,"Error While Sending Fax.."+fs.getMessage());
                    logger.error(FILE_NAME + "Error While Sending Fax.." + fs.getMessage());
                    fs.printStackTrace();
                    unsentFaxList.add(
                            contactFaxList.get(i) != null ? contactFaxList.get(i) : "No Fax Number Provided");
                }
            }
        }
        //}
        returnList.add(sentEmailsList);
        returnList.add(unsentEmailsList);
        returnList.add(sentFaxList);
        returnList.add(unsentFaxList);

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

        // System.out.println("End of mail sending and PDF Generation --------------------------------->");

    } 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());
        //return 0;
        //throw new Exception("Error while generating PDF format");
    }
    return returnList;
}

From source file:PRCR_Checkroll_Amalgamation.java

private void print() {
    Document document = new Document(PageSize.A4.rotate());
    try {//from  ww w  . j  a  v  a  2  s  .c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/Amalgamation.pdf"));

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(1800, 750);

        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 1800, 750);

        jTable1.print(g2);
        g2.setClip(oldClip);

        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:PRCR_Checkroll_Summar.java

private void print() {
    Document document = new Document(PageSize.A4);
    try {//  ww  w.j  av a2  s  .c om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/CheckrollSummary.pdf"));

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(600, 750);

        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 600, 750);

        jTable1.print(g2);
        g2.setClip(oldClip);

        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:displayStructureAsPDFTable.java

License:Open Source License

public void drawStructure(IAtomContainer mol, int cnt) {

    // do aromaticity detection
    try {/* ww  w. jav  a  2 s .co m*/
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
    } catch (CDKException cdke) {
        cdke.printStackTrace();
    }
    mol = addHeteroHydrogens(mol);
    r2dm = new Renderer2DModel();
    renderer = new Renderer2D(r2dm);
    Dimension screenSize = new Dimension(this.width, this.height);
    setPreferredSize(screenSize);
    r2dm.setBackgroundDimension(screenSize); // make sure it is synched with the JPanel size
    setBackground(r2dm.getBackColor());

    try {
        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        sdg.setMolecule((IMolecule) mol);
        sdg.generateCoordinates();
        this.mol = sdg.getMolecule();

        r2dm.setDrawNumbers(false);
        r2dm.setUseAntiAliasing(true);
        r2dm.setColorAtomsByType(doColor);
        r2dm.setShowAromaticity(true);
        r2dm.setShowAromaticityInCDKStyle(false);
        r2dm.setShowReactionBoxes(false);
        r2dm.setKekuleStructure(false);
        r2dm.setShowExplicitHydrogens(withH);
        r2dm.setShowImplicitHydrogens(true);
        GeometryTools.translateAllPositive(this.mol);
        GeometryTools.scaleMolecule(this.mol, getPreferredSize(), this.scale);
        GeometryTools.center(this.mol, getPreferredSize());
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    this.frame.getContentPane().add(this);
    this.frame.pack();

    String filename;
    if (cnt < 10)
        filename = this.odir + "/img00" + cnt + this.suffix;
    else if (cnt < 100)
        filename = this.odir + "/img0" + cnt + this.suffix;
    else
        filename = this.odir + "/img" + cnt + this.suffix;

    if (oformat.equalsIgnoreCase("png") || oformat.equalsIgnoreCase("jpeg")) {
        BufferedImage img;
        try {
            img = new BufferedImage(this.getSize().width, this.getSize().height, BufferedImage.TYPE_INT_RGB);
            //                img = (BufferedImage) createImage(this.getSize().width, this.getSize().height);
            Graphics2D snapGraphics = (Graphics2D) img.getGraphics();
            this.paint(snapGraphics);
            File graphicsFile = new File(filename);
            ImageIO.write(img, oformat, graphicsFile);
        } catch (NullPointerException e) {
            System.out.println(e.toString());
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
    } else if (oformat.equalsIgnoreCase("pdf")) {
        File file = new File(filename);
        Rectangle pageSize = new Rectangle(this.getSize().width, this.getSize().height);
        Document document = new Document(pageSize);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
            document.open();
            PdfContentByte cb = writer.getDirectContent();

            Image awtImage = createImage(this.getSize().width, this.getSize().height);
            Graphics snapGraphics = awtImage.getGraphics();
            paint(snapGraphics);

            com.lowagie.text.Image pdfImage = com.lowagie.text.Image.getInstance(awtImage, null);
            pdfImage.setAbsolutePosition(0, 0);
            cb.addImage(pdfImage);

        } catch (DocumentException de) {
            System.err.println(de.getMessage());
        } catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    } else if (oformat.equalsIgnoreCase("svg")) {
        /*
             try {
        SVGWriter cow = new SVGWriter(new FileWriter(filename));
        if (cow != null) {
            cow.writeAtomContainer(mol);
            cow.close();
        }
             } catch (IOException ioe) {
        ioe.printStackTrace();
             } catch (CDKException cdke) {
        cdke.printStackTrace();
             }
        */
    }
}

From source file:QMSQuoteController.java

License:Open Source License

private ArrayList doPDFGenerationForQuoteGroup(ArrayList mainDtl, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String[] contents = null;/*from w  ww  .j  ava 2  s .  c om*/
    String[] levels = null;
    String[] aligns = null;
    String[] headFoot = null;
    Table content = null;
    String[] contactPersons = null;
    String contactName = null;
    ArrayList contactList = new ArrayList();
    ArrayList contactEmailList = new ArrayList();
    ArrayList contactFaxList = new ArrayList();
    ArrayList returnList = new ArrayList();
    ArrayList sentEmailsList = new ArrayList();
    ArrayList unsentEmailsList = new ArrayList();
    ArrayList sentFaxList = new ArrayList();
    ArrayList unsentFaxList = new ArrayList();
    ArrayList filesDOBList = new ArrayList();
    ArrayList filesList = new ArrayList();
    HttpSession session = null;

    try {
        //System.out.println("PDF Generation Startd----------------------------------->");
        QuoteFinalDOB finalDOB = null;
        ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
        QuoteHeader headerDOB = null;
        QuoteMasterDOB masterDOB = null;
        CostingMasterDOB costingMasterDOB = null;
        CostingChargeDetailsDOB detailsDOB = null;
        CostingLegDetailsDOB legDetails = null;
        CostingRateInfoDOB rateDetailsDOB = null;
        ArrayList rateDetails = new ArrayList();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String formMailId = "";
        String to_emailIds = "";
        String to_FaxIds = "";
        String faxMailIds = "";
        Document document = new Document(PageSize.A4);
        String PDF_FILE_NAME = "Approved.pdf";
        document.addTitle("Approved Report");
        document.addSubject("Report PDF");
        document.addKeywords("Test, Key Words");
        document.addAuthor("DHL");
        document.addCreator("Auto Generated through 4S DHL");
        document.addCreationDate();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();
        Table partCountry;
        Chunk chk;
        Cell cellCountry;
        if (mainDtl != null && mainDtl.size() > 0) {

            finalDOB = (QuoteFinalDOB) mainDtl.get(0);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            formMailId = "webmaster@four-soft.com";
            ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                    .getAttribute("loginbean");
            eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
            //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());

            String[] strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            String[] effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
            String[] validDate;

            // System.out.println("Before Document Objec--------------------------->");

            //document.setMargins(10,10,10,10);

            Table mainT = new Table(8);
            mainT.setWidth(100);
            mainT.setBorderColor(Color.white);
            mainT.setPadding(1);
            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.setColspan(7);
            mainT.addCell(cellHeading);

            Cell imageCell = new Cell();
            java.net.URL url = getServletConfig().getServletContext().getResource("/images/DHLlogo.gif");
            Image img0 = Image.getInstance(url);
            imageCell.add(img0);
            imageCell.setHorizontalAlignment(imageCell.ALIGN_RIGHT);
            imageCell.setBorderWidth(0);
            imageCell.setNoWrap(true);
            mainT.addCell(imageCell);
            mainT.setAlignment(mainT.ALIGN_CENTER);
            document.add(mainT);

            //Default Header Content Starts
            contents = masterDOB.getDefaultContent();
            headFoot = masterDOB.getDefaultHeaderFooter();

            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 hFLen = headFoot.length;
                for (int i = 0; i < hFLen; 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(6.0f);
                        cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                        cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);//Default content is left aligned                                    
                        content.addCell(cellContent);
                    }
                }
                document.add(content);
                contents = null;
                headFoot = null;
                content = null;
            }
            //End Default Header Content

            //System.out.println("After Heading --------------------------->");
        }
        String validUptoStr = null;
        String[] strDate = null;
        String[] effDate = null;
        String[] validDate = null;
        StringBuffer attentionTo = null;
        int mainDtlSize = mainDtl.size();
        for (int m = 0; m < mainDtlSize; m++) {

            finalDOB = (QuoteFinalDOB) mainDtl.get(m);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            //formMailId             =   "webmaster@four-soft.com";
            ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                    .getAttribute("loginbean");
            eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
            //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());

            strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
            attentionTo = new StringBuffer("");

            if (headerDOB.getValidUpto() != null) {
                validDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getValidUpto());
                validUptoStr = validDate[0];
            }
            if (masterDOB.getCustContactNames() != null) {
                for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                    // Logger.info(FILE_NAME,"headerDOB.getAttentionTo()::"+masterDOB.getCustomerContacts()[i]);
                    attentionTo.append(
                            masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i]
                                    : "");
                    if (i != masterDOB.getCustContactNames().length)
                        attentionTo.append(",");
                }
            }
            partCountry = new Table(1, 5);
            partCountry.setBorderWidth(0);
            partCountry.setWidth(100);
            partCountry.setBorderColor(Color.black);
            //partCountry.setBackgroundColor(Color.ORANGE);
            partCountry.setPadding(1);
            partCountry.setSpacing(0);
            partCountry.setAutoFillEmptyCells(true);
            //partCountry.setTableFitsPage(true);
            partCountry.setAlignment(partCountry.ALIGN_CENTER);
            // partCountry.setWidth(100.0f);

            String shipmentMode = "";
            if (finalDOB.getMasterDOB().getShipmentMode() == 1)
                shipmentMode = "AIR FREIGHT PROPOSAL";
            else if (finalDOB.getMasterDOB().getShipmentMode() == 2)
                shipmentMode = "SEA FREIGHT PROPOSAL";
            else if (finalDOB.getMasterDOB().getShipmentMode() == 4)
                shipmentMode = "TRUCK FREIGHT PROPOSAL";

            chk = new Chunk(shipmentMode, 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);
            //@@Modified for the WPBN Change Request-71229
            if ("MY".equalsIgnoreCase(masterDOB.getCountryId())) {
                chk = new Chunk(headerDOB.getOriginCountry() + " TO " + headerDOB.getDestinationCountry(),
                        FontFactory.getFont("ARIAL", 12, 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);

                chk = new Chunk(headerDOB.getCustomerName() == null ? "" : headerDOB.getCustomerName(),
                        FontFactory.getFont("ARIAL", 12, 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", 12, 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 {
                chk = new Chunk(headerDOB.getOriginCountry() + " TO " + headerDOB.getDestinationCountry(),
                        FontFactory.getFont("ARIAL", 12, 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);

                chk = new Chunk(headerDOB.getCustomerName() == null ? "" : headerDOB.getCustomerName(),
                        FontFactory.getFont("ARIAL", 12, 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", 12, 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);
            }
            //@@WPBN Change Request-71229
            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();

            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 hFlen = headFoot.length;
                for (int i = 0; i < hFlen; 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(6.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);
            }

            partCountry = new Table(2, 15);
            partCountry.setOffset(2);
            partCountry.setWidth(100);
            partCountry.setPadding(1);
            partCountry.setSpacing(0);
            partCountry.setBackgroundColor(Color.WHITE);
            partCountry.setBorderColor(Color.black);
            partCountry.setBorderWidth(1);
            //added by subrahmanyam for 182516
            partCountry.setTableFitsPage(true);
            partCountry.setCellsFitPage(true);
            //ended for 182516

            chk = new Chunk("SERVICE INFORMATION: ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellCountry = new Cell(chk);

            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Commented by subrahmanyam for the enhancement #146970 & #146971            
            /*chk = new Chunk("QUOTE ID:"+new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);*/
            //@@ Added by subrahmanyam for the enhancement #146970 & #146971            
            chk = new Chunk("QUOTE ID:" + masterDOB.getQuoteId(),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            cellCountry.setBackgroundColor(Color.ORANGE);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Origin : ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getOriginLocName() != null ? headerDOB.getOriginLocName() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Destination : ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getDestLocName() != null ? headerDOB.getDestLocName() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Customer : ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getCustomerName() != null ? headerDOB.getCustomerName() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            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.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getAgent() != null ? headerDOB.getAgent() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Added by subrahmanyam for the WPBN ISSUE: 150460 ON 23/12/2008                
            if ("EXW".equalsIgnoreCase(headerDOB.getIncoTerms())
                    || "FAS".equalsIgnoreCase(headerDOB.getIncoTerms())
                    || "FCA".equalsIgnoreCase(headerDOB.getIncoTerms())
                    || "FOB".equalsIgnoreCase(headerDOB.getIncoTerms())) {
                chk = new Chunk("Place Of Acceptance: ",
                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cellCountry = new Cell(chk);
                cellCountry.setBackgroundColor(Color.lightGray);
                cellCountry.setNoWrap(true);
                cellCountry.setLeading(8.0f);
                partCountry.addCell(cellCountry);
            } else {
                chk = new Chunk("Place Of Delivery: ",
                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cellCountry = new Cell(chk);
                cellCountry.setBackgroundColor(Color.lightGray);
                cellCountry.setNoWrap(true);
                cellCountry.setLeading(8.0f);
                partCountry.addCell(cellCountry);
            }
            //@@ Ended by subrahmanyam for the WPBN ISSUE: 150460 ON 23/12/2008  

            chk = new Chunk("   " + (headerDOB.getCargoAcceptancePlace() != null
                    ? headerDOB.getCargoAcceptancePlace().toUpperCase()
                    : ""), FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Origin Port: ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   "
                    + ((headerDOB.getOriginPortName() != null
                            ? headerDOB.getOriginPortName().toUpperCase() + ", "
                            : ""))
                    + (headerDOB.getOriginPortCountry() != null ? headerDOB.getOriginPortCountry().toUpperCase()
                            : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Destination Port: ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   "
                    + ((headerDOB.getDestPortName() != null ? headerDOB.getDestPortName().toUpperCase() + ", "
                            : ""))
                    + (headerDOB.getDestPortCountry() != null ? headerDOB.getDestPortCountry().toUpperCase()
                            : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            // @@Commented by subrahmanyam for the enhancement #148546 on 09/12/2008            
            /* chk = new Chunk("Routing: ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setBackgroundColor(Color.lightGray);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);          
             chk = new Chunk("   "+(headerDOB.getRouting()!=null?headerDOB.getRouting():""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
             cellCountry = new Cell(chk);
             cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
             partCountry.addCell(cellCountry);*/
            //@@ Ended by subrahmanyam for the enhanement #148546 on 09/12/2008 

            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getCommodity() != null ? headerDOB.getCommodity() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getTypeOfService() != null ? headerDOB.getTypeOfService() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("Incoterms: ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setBackgroundColor(Color.lightGray);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + (headerDOB.getIncoTerms() != null ? headerDOB.getIncoTerms() : ""),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            //@@ Commented by subrahmanyam for WPBN ISSUE:-145510                                      
            /* chk = new Chunk("   "+(headerDOB.getNotes()!=null?headerDOB.getNotes().toUpperCase()+'\n'+"nnnnnnnnnn":""),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            Commented by subrahmanyam for WPBN ISSUE:-145510   
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true); cellCountry.setLeading(8.0f);
                    
            partCountry.addCell(cellCountry);
            */
            //@@ Ended by subrahmanyam for WPBN ISSUE:-145510  
            //@@ Added by subrahmanyam for WPBN ISSUE:-145510  
            chk = new Chunk("   " + (headerDOB.getNotes() != null ? headerDOB.getNotes().toUpperCase() : " "),
                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setLeading(8.0f);
            partCountry.addCell(cellCountry);
            //@@ Ended by subrahmanyam for WPBN ISSUE:-145510   

            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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk("   " + effDate[0], FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
            cellCountry = new Cell(chk);
            cellCountry.setNoWrap(true);
            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.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.setLeading(8.0f);
            partCountry.addCell(cellCountry);

            document.add(partCountry);
            partCountry.complete();
        }
        int originCount = 0;
        int freightCount = 0;
        int destCount = 0;
        for (int m = 0; m < mainDtlSize; m++) {

            finalDOB = (QuoteFinalDOB) mainDtl.get(m);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            // System.out.println("After Page Country-------------------------------->");
            //Origin Charges

            costingMasterDOB = finalDOB.getCostingMasterDOB();

            ArrayList originCharges = (ArrayList) costingMasterDOB.getOriginList();

            int[] originIndices = finalDOB.getSelectedOriginChargesListIndices();
            int originChargesSize = 0;

            if (originCharges != null)
                originChargesSize = originCharges.size();
            else
                originChargesSize = 0;

            //Destination
            ArrayList destCharges = new ArrayList();
            int[] destIndices = finalDOB.getSelctedDestChargesListIndices();
            int destChargesSize = 0;
            if (destIndices != null)
                destChargesSize = destIndices.length;
            else
                destChargesSize = 0;

            ArrayList frieghtChargeDetails = new ArrayList();
            destCharges = (ArrayList) costingMasterDOB.getDestinationList();
            ArrayList costingLegDetailsList = new ArrayList();
            costingLegDetailsList = (ArrayList) costingMasterDOB.getCostingLegDetailsList();
            //////////////////////////////
            int orgChargSize = originCharges.size();
            for (int i = 0; i < orgChargSize; i++) {
                detailsDOB = (CostingChargeDetailsDOB) originCharges.get(i);
                rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                int rateDtlSize = rateDetails.size();
                for (int k = 0; k < rateDtlSize; k++) {
                    originCount++;
                }
            }
            int destChargSize = destCharges.size();
            for (int i = 0; i < destChargSize; i++) {
                detailsDOB = (CostingChargeDetailsDOB) destCharges.get(i);
                rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                int rateDtlSize = rateDetails.size();
                for (int k = 0; k < rateDtlSize; k++) {
                    destCount++;
                }
            }
            int costLegDtlSize = costingLegDetailsList.size();
            for (int s = 0; s < costLegDtlSize; s++) {
                legDetails = (CostingLegDetailsDOB) costingLegDetailsList.get(s);
                frieghtChargeDetails = (ArrayList) legDetails.getCostingChargeDetailList();
                int frtChargDtlSize = frieghtChargeDetails.size();
                for (int n = 0; n < frtChargDtlSize; n++) {
                    detailsDOB = (CostingChargeDetailsDOB) frieghtChargeDetails.get(n);
                    rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                    int rateDtlSize = rateDetails.size();
                    for (int j = 0; j < rateDtlSize; j++) {
                        freightCount++;
                    }
                }
            }

        }

        //////////////////////////////
        ArrayList charges = finalDOB.getLegDetails();
        int chargesSize = charges.size();
        if (originCount > 0) {
            Table chargeCountry = new Table(7, originCount);
            chargeCountry.setWidth(100);
            chargeCountry.setPadding(1);
            chargeCountry.setSpacing(0);
            chargeCountry.setOffset(25);
            chargeCountry.setBackgroundColor(Color.WHITE);
            chargeCountry.setBorderColor(Color.black);
            chargeCountry.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry.setTableFitsPage(true);
            chargeCountry.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell;
            String wBslab = "";
            chk = new Chunk("QUOTEID ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("CHARGE NAME ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);

            chk = new Chunk("ORIGIN CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell = new Cell(chk);
            cell.setColspan(7);
            cell.setBackgroundColor(Color.ORANGE);
            cell.setNoWrap(true);
            cell.setLeading(8.0f);
            // cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
            chargeCountry.addCell(cell);
            for (int m = 0; m < mainDtlSize; m++) {

                finalDOB = (QuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();

                costingMasterDOB = finalDOB.getCostingMasterDOB();
                ArrayList originCharges = (ArrayList) costingMasterDOB.getOriginList();

                QuoteCharges chargesDOB = null;
                ArrayList originChargeInfo = null;
                int originChargesInfoSize = 0;
                QuoteChargeInfo chargeInfo = null;
                if (originCharges.size() > 0) {

                    int orgChargSize = originCharges.size();
                    for (int i = 0; i < orgChargSize; i++) {
                        detailsDOB = (CostingChargeDetailsDOB) originCharges.get(i);
                        rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();

                        originChargesInfoSize = rateDetails.size();
                        for (int k = 0; k < originChargesInfoSize; k++) {
                            CostingRateInfoDOB crateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(k);
                            if (k == 0) {
                                //@@ Commented by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008                    
                                /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                cell = new Cell(chk);
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true); cell.setLeading(8.0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);*/
                                //@@ Added by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    
                                chk = new Chunk(masterDOB.getQuoteId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell = new Cell(chk);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                chargeCountry.addCell(cell);
                                //@@ Ended by subrahmanyam for the enhanemenet #146971 and #146970 on 10/12/2008 

                                //@@ commented and modified by subrahmanyam for 181349  on 07-sep-09 & 202166 on 7-apr-10
                                // chk = new Chunk(detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                chk = new Chunk(
                                        detailsDOB.getExternalName() != null ? detailsDOB.getExternalName()
                                                : detailsDOB.getChargeDescId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));//ended for 181349
                                cell = new Cell(chk);
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                // cell.setNoWrap(true); //commented for 181349
                                cell.setLeading(8.0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);
                            } else {
                                cell = new Cell("");
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                cell.setBorderWidth(0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);

                                cell = new Cell("");
                                //cell.setRowspan(originChargesInfoSize);
                                cell.setBackgroundColor(Color.lightGray);
                                cell.setNoWrap(true);
                                cell.setLeading(8.0f);
                                cell.setBorderWidth(0f);
                                //cell.setVerticalAlignment(cell.ALIGN_MIDDLE);
                                chargeCountry.addCell(cell);
                            }
                            chk = new Chunk(crateDetailsDOB.getWeightBreakSlab(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setBackgroundColor(Color.lightGray);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(detailsDOB.getCurrency(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setBackgroundColor(Color.lightGray);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(crateDetailsDOB.getRate() + "",
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            //added by subrahmanyam for 183812
                            if (crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                    || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType())
                                            && "F".equalsIgnoreCase(crateDetailsDOB.getRateIndicator()))) {
                                wBslab = "MIN";
                            } else
                                wBslab = detailsDOB.getChargeBasisDesc();
                            // @@ Commented & Added by subrahmanyam for the wpbn id: 182516 on 10/09/09
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?" Per Shipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            chk = new Chunk(
                                    wBslab.equalsIgnoreCase("Min") ? " Per Shipment "
                                            : detailsDOB.getChargeBasisDesc(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                            chk = new Chunk(
                                    detailsDOB.getDensityRatio() == null ? "" : detailsDOB.getDensityRatio(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell = new Cell(chk);
                            cell.setNoWrap(true);
                            cell.setLeading(8.0f);
                            chargeCountry.addCell(cell);

                        }
                    }
                }
            }
            document.add(chargeCountry);
        }
        if (freightCount > 0) {
            Table chargeCountry1 = new Table(7, freightCount);
            chargeCountry1.setWidth(100);
            chargeCountry1.setPadding(1);
            chargeCountry1.setSpacing(0);
            chargeCountry1.setOffset(25);
            chargeCountry1.setBackgroundColor(Color.WHITE);
            chargeCountry1.setBorderColor(Color.black);
            chargeCountry1.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry1.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry1.setTableFitsPage(true);
            chargeCountry1.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell1;
            chk = new Chunk(" QUOTEID", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);
            chk = new Chunk("CHARGE NAME ", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            // cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setBackgroundColor(Color.ORANGE);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            // cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);

            chk = new Chunk("FREIGHT CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell1 = new Cell(chk);
            cell1.setColspan(7);
            cell1.setNoWrap(true);
            cell1.setLeading(8.0f);
            cell1.setBackgroundColor(Color.ORANGE);
            //cell1.setVerticalAlignment(cell1.ALIGN_MIDDLE);
            chargeCountry1.addCell(cell1);
            //Freight Charges
            // System.out.println("After         Origin Charges --------------------------------->");
            int freightChargesSize = 0;
            int freightChargesInfoSize = 0;
            int[] frtIndices = null;
            QuoteFreightLegSellRates legCharges = null;
            String wBSlab = "";//added by subrahmanyam for 182516 on 10-sep-09             
            int mDtlSize = mainDtl.size();
            for (int m = 0; m < mDtlSize; m++) {

                finalDOB = (QuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();
                ArrayList costingLegDetailsList = new ArrayList();
                costingMasterDOB = finalDOB.getCostingMasterDOB();
                costingLegDetailsList = (ArrayList) costingMasterDOB.getCostingLegDetailsList();
                ArrayList frieghtChargeDetails = new ArrayList();
                String rDescription = ""; // Added by subrahmanyam for 182516 on 10/09/09
                if (costingLegDetailsList.size() > 0) {

                    int costLegDtlSize = costingLegDetailsList.size();
                    for (int s = 0; s < costLegDtlSize; s++) {
                        legDetails = (CostingLegDetailsDOB) costingLegDetailsList.get(s);
                        frieghtChargeDetails = (ArrayList) legDetails.getCostingChargeDetailList();
                        int frtLegDtlSize = frieghtChargeDetails.size();
                        int frtChargDtlSize = frieghtChargeDetails.size();
                        for (int n = 0; n < frtChargDtlSize; n++) {
                            detailsDOB = (CostingChargeDetailsDOB) frieghtChargeDetails.get(n);
                            rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();
                            int rateDtlSize = rateDetails.size();
                            for (int j = 0; j < rateDtlSize; j++) {
                                rateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(j);

                                if (j == 0) {

                                    chk = new Chunk(legDetails.getOrigin() + "-" + legDetails.getDestination(),
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    cell1.setColspan(7);
                                    cell1.setBackgroundColor(Color.WHITE);
                                    cell1.setLeading(8.0f);
                                    chargeCountry1.addCell(cell1);

                                    //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
                                    /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                    cell1 = new Cell(chk);
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true); cell2.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);*/
                                    //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
                                    chk = new Chunk(masterDOB.getQuoteId(),
                                            FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);
                                    //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    
                                    // COMMENTED AND MODIFIED BY SUBRAHMANYAM FOR 182516
                                    //chk = new Chunk(detailsDOB.getChargeDescId()==null?"":detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                    chk = new Chunk(
                                            rateDetailsDOB.getRateDescription() == null ? ""
                                                    : rateDetailsDOB.getRateDescription(),
                                            FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                    cell1 = new Cell(chk);
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);
                                    rDescription = rateDetailsDOB.getRateDescription();
                                } else {
                                    cell1 = new Cell("");
                                    //cell1.setRowspan(rateDetails.size());
                                    cell1.setNoWrap(true);
                                    cell1.setLeading(8.0f);
                                    cell1.setBorderWidth(0f);
                                    cell1.setBackgroundColor(Color.lightGray);
                                    chargeCountry1.addCell(cell1);

                                    //@@ Commented by subrahmanyam for 182516 on 10/09/09
                                    /*
                                     cell1 = new Cell("");
                                     //cell1.setRowspan(rateDetails.size());
                                     cell1.setNoWrap(true); cell1.setLeading(8.0f);
                                     cell1.setBackgroundColor(Color.lightGray);
                                     cell1.setBorderWidth(0f);
                                     chargeCountry1.addCell(cell1);
                                     */
                                    //@@ added by subrahmanyam for 182516 on 10/09/09
                                    if (rDescription.equalsIgnoreCase(rateDetailsDOB.getRateDescription())) {
                                        chk = new Chunk("",
                                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                        cell1 = new Cell(chk);
                                        //cell1.setRowspan(rateDetails.size());
                                        cell1.setNoWrap(true);
                                        cell1.setLeading(8.0f);
                                        cell1.setBackgroundColor(Color.lightGray);
                                        cell1.setBorderWidth(0f);
                                        chargeCountry1.addCell(cell1);
                                    } else {
                                        chk = new Chunk(
                                                rateDetailsDOB.getRateDescription() == null ? ""
                                                        : rateDetailsDOB.getRateDescription(),
                                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                        cell1 = new Cell(chk);
                                        //cell1.setRowspan(rateDetails.size());
                                        //cell1.setNoWrap(true);
                                        cell1.setLeading(8.0f);
                                        cell1.setBackgroundColor(Color.lightGray);
                                        chargeCountry1.addCell(cell1);
                                        rDescription = rateDetailsDOB.getRateDescription();
                                    }
                                    //ended by subrahmanyam for 182516 on 10/09/09

                                }
                                if ("FSBASIC".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSBASIC".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Basic Charge");
                                if ("FSMIN".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSMIN".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Minimum");
                                if ("FSKG".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab())
                                        || "SSKG".equalsIgnoreCase(rateDetailsDOB.getWeightBreakSlab()))
                                    rateDetailsDOB.setWeightBreakSlab("Flat Rate");

                                chk = new Chunk(rateDetailsDOB.getWeightBreakSlab(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                cell1.setBackgroundColor(Color.lightGray);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(detailsDOB.getCurrency(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                cell1.setBackgroundColor(Color.lightGray);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(rateDetailsDOB.getRate() + "",
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                                //@@ Added by subrahmanyam for wpbn id: 182516
                                // MODIFIED BY SUBRAHMANYAM FOR 183812
                                if (rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                        || rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Minimum")
                                        || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType()) && "FLAT"
                                                .equalsIgnoreCase(rateDetailsDOB.getRateIndicator()))) {
                                    wBSlab = "MIN";
                                } else {
                                    wBSlab = rateDetailsDOB.getWeightBreakSlab();
                                }
                                //@@ commented by subrahmanyam for wpbn id: 182516
                                //chk = new Chunk(rateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                //@@ Added by subrahmanyam for wpbn id: 182516
                                chk = new Chunk(
                                        wBSlab.equalsIgnoreCase("Min") ? " Per Shipment "
                                                : detailsDOB.getChargeBasisDesc(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                //@@ Ended  for wpbn id: 182516
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                                chk = new Chunk(
                                        detailsDOB.getDensityRatio() == null ? ""
                                                : detailsDOB.getDensityRatio(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell1 = new Cell(chk);
                                cell1.setNoWrap(true);
                                cell1.setLeading(8.0f);
                                chargeCountry1.addCell(cell1);

                            }
                        }
                    }
                }
            }
            document.add(chargeCountry1);
        }
        // System.out.println("After Charges--------------------------------->");
        ArrayList destChargeInfo = null;
        //int[]      destChargeInfo        =  null;
        int destChargesInfoSize = 0;
        if (destCount > 0) {
            Table chargeCountry2 = new Table(7, destCount);
            chargeCountry2.setWidth(100);
            chargeCountry2.setPadding(1);
            chargeCountry2.setSpacing(0);
            chargeCountry2.setOffset(25);
            chargeCountry2.setBackgroundColor(Color.WHITE);
            chargeCountry2.setBorderColor(Color.black);
            chargeCountry2.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
            chargeCountry2.setBorderWidth(1);
            //@@ Added by subrahmanyam for wpbn id: 181349 on 07-sep-09
            chargeCountry2.setTableFitsPage(true);
            chargeCountry2.setCellsFitPage(true);
            // @@ Ended for wpbn id: 181349 on 07-sep-09

            Cell cell2;
            String wBslab = "";
            chk = new Chunk("QUOTEID", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("CHARGE NAME", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("BREAKPOINT", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("CURRENCY", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("RATE", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("BASIS", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("RATIO", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);

            chk = new Chunk("DESTINATION CHARGES", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cell2 = new Cell(chk);
            cell2.setNoWrap(true);
            cell2.setLeading(8.0f);
            cell2.setColspan(7);
            cell2.setBackgroundColor(Color.ORANGE);
            //cell2.setVerticalAlignment(cell2.ALIGN_MIDDLE);
            chargeCountry2.addCell(cell2);
            int mDtlSize = mainDtl.size();
            for (int m = 0; m < mDtlSize; m++) {

                finalDOB = (QuoteFinalDOB) mainDtl.get(m);
                headerDOB = finalDOB.getHeaderDOB();
                masterDOB = finalDOB.getMasterDOB();
                costingMasterDOB = finalDOB.getCostingMasterDOB();
                ArrayList destCharges = (ArrayList) costingMasterDOB.getDestinationList();
                if (destCharges.size() > 0) {

                    int destChargSize = destCharges.size();

                    for (int i = 0; i < destChargSize; i++) {

                        detailsDOB = (CostingChargeDetailsDOB) destCharges.get(i);
                        rateDetails = (ArrayList) detailsDOB.getCostingRateInfoDOB();

                        //originChargesInfoSize   = rateDetails.size();
                        int rDtlSize = rateDetails.size();
                        for (int k = 0; k < rDtlSize; k++) {
                            CostingRateInfoDOB crateDetailsDOB = (CostingRateInfoDOB) rateDetails.get(k);

                            if (k == 0) {

                                //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
                                /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                cell2 = new Cell(chk);
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true); cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);*/
                                //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
                                chk = new Chunk(masterDOB.getQuoteId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                                cell2 = new Cell(chk);
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);
                                //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008    

                                //  chk = new Chunk(detailsDOB.getChargeDescId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                                //@@ Added by subrahmanyam for the wpbn id: 181349  on 07-sep-09
                                chk = new Chunk(
                                        detailsDOB.getExternalName() != null ? detailsDOB.getExternalName()
                                                : detailsDOB.getChargeDescId(),
                                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));//ended for 181349
                                cell2 = new Cell(chk);
                                //cell2.setRowspan(rateDetails.size());
                                //cell2.setNoWrap(true); //commented for 181349
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                chargeCountry2.addCell(cell2);
                            } else {
                                cell2 = new Cell("");
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                cell2.setBorderWidth(0f);
                                chargeCountry2.addCell(cell2);

                                cell2 = new Cell("");
                                //cell2.setRowspan(rateDetails.size());
                                cell2.setNoWrap(true);
                                cell2.setLeading(8.0f);
                                cell2.setBackgroundColor(Color.lightGray);
                                cell2.setBorderWidth(0f);
                                chargeCountry2.addCell(cell2);
                            }
                            chk = new Chunk(crateDetailsDOB.getWeightBreakSlab(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            cell2.setBackgroundColor(Color.lightGray);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(detailsDOB.getCurrency(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            cell2.setBackgroundColor(Color.lightGray);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(crateDetailsDOB.getRate() + "",
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);

                            //@@ Commented & Added  by subrahmanyam for 182516 on 10/09/09
                            // chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?"Pershipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            //ADDED BY SUBRAHMANYAM FOR 183812
                            if (crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")
                                    || ("BOTH".equalsIgnoreCase(detailsDOB.getRateType())
                                            && "F".equalsIgnoreCase(crateDetailsDOB.getRateIndicator()))) {
                                wBslab = "MIN";
                            } else
                                wBslab = detailsDOB.getChargeBasisDesc();
                            // COMMENTED & added FOR 183812 ON 24-09-09
                            //chk = new Chunk(crateDetailsDOB.getWeightBreakSlab().equalsIgnoreCase("Min")?" Per Shipment ":detailsDOB.getChargeBasisDesc(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
                            chk = new Chunk(
                                    wBslab.equalsIgnoreCase("Min") ? " Per Shipment "
                                            : detailsDOB.getChargeBasisDesc(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);

                            chk = new Chunk(
                                    detailsDOB.getDensityRatio() == null ? "" : detailsDOB.getDensityRatio(),
                                    FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                            cell2 = new Cell(chk);
                            cell2.setNoWrap(true);
                            cell2.setLeading(8.0f);
                            chargeCountry2.addCell(cell2);
                        }
                    }
                }
            }
            document.add(chargeCountry2);
        }

        Table notes = new Table(2, mainDtl.size());
        boolean displayFlag = false;
        notes.setWidth(100);
        notes.setPadding(1);
        notes.setSpacing(0);
        notes.setOffset(5);
        notes.setBackgroundColor(Color.WHITE);
        notes.setBorderColor(Color.black);
        notes.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
        notes.setBorderWidth(1);
        notes.setTableFitsPage(true);// added by subrahmanyam for quoteGrouping issue 184848
        notes.setCellsFitPage(true);// added by subrahmanyam for quoteGrouping issue 184848

        Cell cell3;
        chk = new Chunk("QUOTEID ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
        cell3 = new Cell(chk);
        cell3.setNoWrap(true);
        cell3.setLeading(8.0f);
        cell3.setBackgroundColor(Color.ORANGE);
        //cell3.setVerticalAlignment(cell3.ALIGN_MIDDLE);
        //cell3.setBackgroundColor(Color.lightGray);
        notes.addCell(cell3);

        chk = new Chunk("NOTES", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
        cell3 = new Cell(chk);
        cell3.setNoWrap(true);
        cell3.setLeading(8.0f);
        cell3.setBackgroundColor(Color.ORANGE);
        //cell3.setVerticalAlignment(cell3.ALIGN_MIDDLE);

        notes.addCell(cell3);
        int mDtlSize = mainDtl.size();
        for (int m = 0; m < mDtlSize; m++) {

            finalDOB = (QuoteFinalDOB) mainDtl.get(m);
            headerDOB = finalDOB.getHeaderDOB();
            masterDOB = finalDOB.getMasterDOB();
            costingMasterDOB = finalDOB.getCostingMasterDOB();
            if (costingMasterDOB != null) {
            }
            //@@ Commented by subrahmanyam for the enhancement #146971 and 1469710 on 10/12/2008                      
            /*chk = new Chunk(new Long(masterDOB.getQuoteId()).toString(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cell3 = new Cell(chk);
            //cell3.setRowspan(rateDetails.size());
            cell3.setNoWrap(true); cell3.setLeading(8.0f);
            cell3.setBackgroundColor(Color.lightGray);
            notes.addCell(cell3);*/
            //@@ Added by subrahmanyam for the enhancement #146971 and #146970 on 10/12/2008
            //commented by subrahmanyam for quote grouping issue
            /*
            chk = new Chunk(masterDOB.getQuoteId(),FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
              cell3 = new Cell(chk);
              cell3.setNoWrap(true); cell3.setLeading(8.0f);
              cell3.setBackgroundColor(Color.lightGray);
              notes.addCell(cell3);
                //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008
                    
            chk = new Chunk(" ",FontFactory.getFont("ARIAL", 8, Font.NORMAL,Color.BLACK));
            cell3 = new Cell(chk);
            //cell3.setRowspan();
            cell3.setNoWrap(true); cell3.setLeading(8.0f);
            cell3.setBackgroundColor(Color.lightGray);
            notes.addCell(cell3);
            */
            //@@ Added by subrahmanyam for Quote Grouping Issue 184848 on 30/sep/09
            if (finalDOB.getExternalNotes() != null && finalDOB.getExternalNotes().length > 0) {
                int notesLength = finalDOB.getExternalNotes().length;
                for (int n = 0; n < notesLength; n++) {
                    if (n == 0) {
                        chk = new Chunk(masterDOB.getQuoteId(),
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        cell3.setNoWrap(true);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                        //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008

                        chk = new Chunk(finalDOB.getExternalNotes()[n],
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        //cell3.setRowspan();
                        //cell3.setNoWrap(true);
                        cell3.setHorizontalAlignment(cell3.ALIGN_LEFT);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                    } else {
                        chk = new Chunk("", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        cell3.setNoWrap(true);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                        //@@ Ended by subrahmanyam for the enhancement #146971 and 146970 on 10/12/2008

                        chk = new Chunk(finalDOB.getExternalNotes()[n],
                                FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                        cell3 = new Cell(chk);
                        //cell3.setRowspan();
                        // cell3.setNoWrap(true);
                        cell3.setHorizontalAlignment(cell3.ALIGN_LEFT);
                        cell3.setLeading(8.0f);
                        cell3.setBackgroundColor(Color.lightGray);
                        notes.addCell(cell3);
                    }
                }
            } else {
                chk = new Chunk(masterDOB.getQuoteId(),
                        FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cell3 = new Cell(chk);
                cell3.setNoWrap(true);
                cell3.setLeading(8.0f);
                cell3.setBackgroundColor(Color.lightGray);
                notes.addCell(cell3);

                chk = new Chunk(" ", FontFactory.getFont("ARIAL", 8, Font.NORMAL, Color.BLACK));
                cell3 = new Cell(chk);
                //cell3.setRowspan();
                cell3.setNoWrap(true);
                cell3.setLeading(8.0f);
                cell3.setBackgroundColor(Color.lightGray);
                notes.addCell(cell3);
            }
            //@@ Ended by subrahmanyam for Quote Grouping Issue 184848 on 30/09/09

            contents = masterDOB.getContentOnQuote();
            levels = masterDOB.getLevels();
            aligns = masterDOB.getAlign();
            headFoot = masterDOB.getHeaderFooter();

            if (contents != null && contents.length > 0) {
                int hFLen = headFoot.length;
                for (int i = 0; i < hFLen; i++) {
                    if (headFoot[i] != null && "F".equalsIgnoreCase(headFoot[i])) {
                        displayFlag = true;
                        break;
                    }
                }
                if (displayFlag) {
                    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 = new Chunk("QUOTEID : " + masterDOB.getQuoteId(),
                            FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));
                    cellContent = new Cell(chk);
                    cellContent.setBorder(0);
                    cellContent.setLeading(6.0f);
                    cellContent.setHorizontalAlignment(cellContent.ALIGN_CENTER);
                    cellContent.setBackgroundColor(Color.ORANGE);
                    content.addCell(cellContent);
                    for (int i = 0; i < hFLen; i++) {
                        if (headFoot[i] != null && "F".equalsIgnoreCase(headFoot[i])) {
                            chk = new Chunk(contents[i] != null ? contents[i].toUpperCase() : "",
                                    FontFactory.getFont("ARIAL", 7, Font.ITALIC, Color.BLACK));
                            cellContent = new Cell(chk);
                            cellContent.setBorder(0);
                            cellContent.setLeading(6.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);
                }
            }
        }
        document.add(notes);
        //Default Footer Content Starts
        contents = masterDOB.getDefaultContent();
        //Added by Anusha V
        int hFLen = 0;
        headFoot = masterDOB.getDefaultHeaderFooter();
        //if(headFoot.length>0){
        //hFLen   =   headFoot.length;}
        //Commented by Anusha V
        //int hFLen = headFoot.length;
        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;

            for (int i = 0; i < headFoot.length; i++) {
                if (headFoot[i] != null && "F".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(6.0f);
                    cellContent.setBackgroundColor(Color.LIGHT_GRAY);
                    cellContent.setHorizontalAlignment(cellContent.ALIGN_LEFT);//Default content is left aligned                                    
                    content.addCell(cellContent);

                }
            }
            document.add(content);
        }
        //End Default Footer Content

        // System.out.println("After     document Close----------------------------------------->");

        document.close();
        // Thread.sleep(100);
        //logger.info("thread");
        //String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime()+masterDOB.getQuoteId());  //@@ Commented by subrahmanyam for the Enhancement #146971 on 2/12/08
        // String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime()+Long.parseLong(masterDOB.getQuoteId()));  //@@ Added by subrahmanyam for the Enhancement #146971 on 2/12/08
        //Commented by Anusha V
        //String file_tsmp = ""+new java.sql.Timestamp((new java.util.Date()).getTime())+masterDOB.getQuoteId();//@@ Added by subrahmanyam for the Enhancement #146971 on 2/12/08
        //Added by Anusha V
        String file_tsmp = "" + new java.sql.Timestamp((new java.util.Date()).getTime());
        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" + file_tsmp + ".pdf");
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        baos.writeTo(fileOutputStream);
        fileOutputStream.close();
        //  logger.info("masterDOB.getUserId()"+masterDOB.getUserId());
        if ("on".equalsIgnoreCase(request.getParameter("print"))) {

            request.getSession().setAttribute("QuoteOuptutStream", f);
        }
        //  session.setAttribute("UserId",masterDOB.getUserId());

        int noOfQuotes = mainDtl.size();
        StringBuffer quoteIds = new StringBuffer("");
        String quoteType = "";
        String terminalAddress = "";
        String creatorDetails = "";
        String fromEmailId = "";
        String body = "";
        String countryCode = "";
        for (int i = 0; i < noOfQuotes; i++) {
            finalDOB = (QuoteFinalDOB) mainDtl.get(i);
            /*  //@@Added for the WPBN issue-
              filesDOBList           =   finalDOB.getAttachmentDOBList(); 
              for(int j=0;j<filesDOBList.size();j++)
              {
               filesList.add(filesDOBList.get(j));
              } //@@Added for the WPBN issue-*/

            if (i == 0) {
                quoteType = "" + finalDOB.getMasterDOB().getShipmentMode();
                terminalAddress = finalDOB.getMasterDOB().getTerminalAddress();
                creatorDetails = finalDOB.getMasterDOB().getCreatorDetails();
                fromEmailId = finalDOB.getMasterDOB().getUserEmailId();
                countryCode = finalDOB.getHeaderDOB().getCustCountyCode();
                to_FaxIds = finalDOB.getHeaderDOB().getCustFaxNo();
                to_emailIds = finalDOB.getHeaderDOB().getCustEmailId();
            }
            quoteIds.append(finalDOB.getMasterDOB().getQuoteId());
            if (i != noOfQuotes - 1)
                quoteIds.append(",");

            contactPersons = finalDOB.getMasterDOB().getCustContactNames();
            if (contactPersons != null) {
                int contPersLen = contactPersons.length;
                for (int k = 0; k < contPersLen; k++) {
                    if (!contactList.contains(finalDOB.getMasterDOB().getCustContactNames()[k])) {
                        contactList.add(finalDOB.getMasterDOB().getCustContactNames()[k]);
                        contactEmailList.add(finalDOB.getMasterDOB().getCustomerContactsEmailIds()[k]);
                        contactFaxList.add(finalDOB.getMasterDOB().getCustomerContactsFax()[k]);
                    }
                }

            }

        }

        if ("1".equalsIgnoreCase(quoteType))
            quoteType = "Airfreight";
        else if ("2".equalsIgnoreCase(quoteType))
            quoteType = "Seafreight";
        else if ("4".equalsIgnoreCase(quoteType))
            quoteType = "Truckfreight";

        String subject = "DHL Global Forwarding Quotation, Multiple " + quoteType + ", Quote References "
                + quoteIds.toString();
        String message = "";
        //finalDOB.getFlagsDOB().setQuoteStatusFlag("PEN");//@@Quote is Pending
        //ReportsSessionBeanHome home      = (ReportsSessionBeanHome)LookUpBean.getEJBHome("ReportsSessionBean");
        //ReportsSession remote   = (ReportsSession)home.create();
        //if(contactList.size()==0)
        //{
        to_emailIds = to_emailIds.replaceAll(";", ",");
        /*message  = "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"+creatorDetails+"\n"+terminalAddress;*/
        //message   = "Dear Customer,\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+creatorDetails+"\n"+terminalAddress+"\n"+;       
        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 ("on".equalsIgnoreCase(request.getParameter("email"))) {
            try {
                sendMail(fromEmailId, to_emailIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                sentEmailsList.add(to_emailIds);
            } catch (FoursoftException fs) {
                //Logger.error(FILE_NAME,"Error While Sending Mail.."+fs.getMessage());
                logger.error(FILE_NAME + "Error While Sending Mail.." + fs.getMessage());
                fs.printStackTrace();
                unsentEmailsList.add(to_emailIds);
            }
        }
        if ("on".equalsIgnoreCase(request.getParameter("fax"))) {
            if ("SG".equalsIgnoreCase(countryCode))
                faxMailIds = "fax#" + to_FaxIds + "@tcdhl.com";
            else
                faxMailIds = "ifax#" + to_FaxIds + "@tcdhl.com";
            try {
                sendMail(fromEmailId, faxMailIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                sentFaxList.add(to_FaxIds);
            } catch (FoursoftException fs) {
                //Logger.error(FILE_NAME,"Error While Sending Fax.."+fs.getMessage());
                logger.error(FILE_NAME + "Error While Sending Fax.." + fs.getMessage());
                fs.printStackTrace();
                unsentFaxList.add(to_FaxIds);
            }
        }
        //}
        //else
        //{
        int contactSize = contactList.size();
        for (int i = 0; i < contactSize; i++) {
            contactName = (String) contactList.get(i);
            /*message = "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"+creatorDetails+"\n"+terminalAddress;*/
            // message = "Dear "+contactName+",\n\n"+finalDOB.getEmailText()+"\n\n\nRegards,\n"+creatorDetails+"\n"+terminalAddress;         
            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 ("on".equalsIgnoreCase(request.getParameter("email"))) {
                try {
                    sendMail(fromEmailId, (String) contactEmailList.get(i), subject, message,
                            "Quote" + file_tsmp + ".pdf", null);
                    sentEmailsList.add(contactEmailList.get(i));
                } catch (FoursoftException fs) {
                    //Logger.error(FILE_NAME,"Error While Sending Mail.."+fs.getMessage());
                    logger.error(FILE_NAME + "Error While Sending Mail.." + fs.getMessage());
                    fs.printStackTrace();
                    unsentEmailsList.add(contactEmailList.get(i));
                }
            }
            if ("on".equalsIgnoreCase(request.getParameter("fax"))) {
                if ("SG".equalsIgnoreCase(countryCode))
                    to_FaxIds = "fax#" + contactFaxList.get(i) + "@tcdhl.com";
                else
                    to_FaxIds = "ifax#" + contactFaxList.get(i) + "@tcdhl.com";
                try {
                    sendMail(fromEmailId, to_FaxIds, subject, message, "Quote" + file_tsmp + ".pdf", null);
                    sentFaxList.add(contactFaxList.get(i));
                } catch (FoursoftException fs) {
                    //Logger.error(FILE_NAME,"Error While Sending Fax.."+fs.getMessage());
                    logger.error(FILE_NAME + "Error While Sending Fax.." + fs.getMessage());
                    fs.printStackTrace();
                    unsentFaxList.add(
                            contactFaxList.get(i) != null ? contactFaxList.get(i) : "No Fax Number Provided");
                }
            }
        }
        //}
        returnList.add(sentEmailsList);
        returnList.add(unsentEmailsList);
        returnList.add(sentFaxList);
        returnList.add(unsentFaxList);

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

        // System.out.println("End of mail sending and PDF Generation --------------------------------->");

    } 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());
        //return 0;
        //throw new Exception("Error while generating PDF format");
    }
    return returnList;
}

From source file:ExamplePdfPrinter.java

License:Open Source License

public static void main(String[] args) throws Exception {
    SpooledFile spooledFile = null; // TODO: provide your spool file!
    final IScsDataProvider dp = As400ScsDataProviderFactory.getPrintObjectDataProvider(spooledFile);
    final ReaderConfig rcfg = ReaderConfig.getDefault();
    final SCSStreamReader reader = new SCSStreamReader(dp, rcfg);

    PrinterConfig pcfg = PrinterConfig.getDefault();
    float FONT_SIZE = 9.0F;
    float leading = FONT_SIZE * 1.05F;

    // calculate font, font size, and margins for the PDF
    final Font monoSpacedFont = FontFactory.getFont(BaseFont.COURIER, FONT_SIZE);
    final Font monoSpacedFontBold = FontFactory.getFont(BaseFont.COURIER_BOLD, Font.BOLD);
    Rectangle pageSize = new Rectangle(PageSize.A4);
    final Document pdfdoc = new Document(pageSize);

    final FileOutputStream fos = new FileOutputStream("test.pdf");
    final PdfWriter pdfwriter = PdfWriter.getInstance(pdfdoc, fos);
    pdfdoc.open();/*from  w ww . j  a  v  a  2 s.c  om*/

    PdfPrinter pdfprinter = new PdfPrinter(pcfg, pdfdoc, monoSpacedFont, monoSpacedFontBold, leading);

    try {
        while (reader.hasNext()) {
            final IPrinterMicroCommand event = reader.next();
            if (event == null)
                break;
            pdfprinter.runMicroCommand(event);
        }
    } catch (EndOfFileSignal e) {
        System.out.println("eof.");
    }

    pdfprinter.finish();
    pdfdoc.close();
    pdfwriter.close();
}

From source file:ambit2.core.processors.ProcessorFileExport.java

public FileOutputState process(Content content) throws AmbitException {
    if (content == null)
        throw new AmbitException("Workbook not assigned!");
    Document document = new Document(PageSize.A4.rotate());
    try {// w w  w. j a va  2  s .  com
        File file = getOutput().getFile();
        if (file.getName().endsWith(FileOutputState.extensions[FileOutputState.SDF_INDEX])) {
            writeSDF(content, new FileOutputStream(file));
            return getOutput();
        } else if (file.getName().endsWith(FileOutputState.extensions[FileOutputState.PDF_INDEX]))
            writePDF(document, new FileOutputStream(file));
        else if (file.getName().endsWith(FileOutputState.extensions[FileOutputState.RTF_INDEX]))
            writeRTF(document, new FileOutputStream(file));
        else if (file.getName().endsWith(FileOutputState.extensions[FileOutputState.HTML_INDEX]))
            writeHTML(document, new FileOutputStream(file));
        else if (file.getName().endsWith(FileOutputState.extensions[FileOutputState.XLS_INDEX])) {
            writeXLS(content, new FileOutputStream(file));
            return getOutput();
        }
        document.open();
        write(document, content);
        return getOutput();
    } catch (DocumentException e) {
        throw new AmbitException(e);
    } catch (FileNotFoundException e) {
        throw new AmbitException(e);
    } finally {
        document.close();
    }
}

From source file:appli_etudiants.ExportPDF.java

public static void main(Etudiants etudiant)
        throws SQLException, FileNotFoundException, BadElementException, IOException {
    try {/*  ww w. java  2  s .c o m*/
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/tesPDF.pdf"));
        document.open();
        PdfContentByte canvas = writer.getDirectContentUnder();
        Image image = Image.getInstance("c:/fond_cv.jpg");
        image.setAbsolutePosition(0, 80);
        canvas.saveState();
        PdfGState state = new PdfGState();
        state.setFillOpacity(0.6f);
        canvas.setGState(state);
        canvas.addImage(image);
        canvas.restoreState();

        LineSeparator lineSepa = new LineSeparator();
        lineSepa.setLineColor(new Color(21, 96, 189));
        Paragraph para1 = new Paragraph();
        Paragraph para2 = new Paragraph(etudiant.getAdresse_rue());
        Paragraph para3 = new Paragraph(etudiant.getAdresse_cp() + " " + etudiant.getAdresse_ville());
        Paragraph para4 = new Paragraph(etudiant.getCourriel(),
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)));
        Paragraph para5 = new Paragraph(etudiant.getTel_personnel());
        Paragraph para6 = new Paragraph(etudiant.getTel_professionnel());
        Paragraph para7 = new Paragraph(etudiant.getSite_web());
        para1.add(new Chunk(etudiant.getPrenom(),
                FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD, new Color(21, 96, 189))));
        para1.add(
                new Chunk(" " + etudiant.getNom(), FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD)));

        Image image1 = Image.getInstance(DaoS4.getPhoto());
        image1.scalePercent(50);
        image1.setAlignment(Image.RIGHT | Image.TEXTWRAP);
        image1.scaleAbsolute(94, 94);
        document.add(image1);

        document.add(para1);
        document.add(para2);
        document.add(para3);
        document.add(para4);
        document.add(para5);
        document.add(para6);
        para7.setSpacingAfter(25f);
        document.add(para7);
        Paragraph para8 = new Paragraph(DaoS4.getLibelleTitre());
        para8.setSpacingBefore(25f);
        para8.setSpacingAfter(20f);
        document.add(para8);

        Paragraph para9 = new Paragraph(new Chunk("EXPERIENCE PROFESSIONELLE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para9.setSpacingBefore(15f);
        para9.setSpacingAfter(15f);
        document.add(para9);
        document.add(lineSepa);
        Paragraph para10 = new Paragraph(DaoS4.getLibelleExpPro());
        para10.setSpacingAfter(15f);
        document.add(para10);

        Paragraph para11 = new Paragraph(new Chunk("FORMATION",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para11.setSpacingBefore(15f);
        para11.setSpacingAfter(15f);
        document.add(para11);
        document.add(lineSepa);
        Paragraph para12 = new Paragraph(DaoS4.getLibelleFormation());
        para12.setSpacingAfter(15f);
        document.add(para12);

        Paragraph para13 = new Paragraph(new Chunk("INFORMATIQUE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para13.setSpacingBefore(15f);
        para13.setSpacingAfter(15f);
        document.add(para13);
        document.add(lineSepa);
        Paragraph para14 = new Paragraph(DaoS4.getLibelleInformatique());
        para14.setSpacingAfter(15f);
        document.add(para14);

        Paragraph para15 = new Paragraph(new Chunk("LANGUE",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para15.setSpacingBefore(15f);
        para15.setSpacingAfter(15f);
        document.add(para15);
        document.add(lineSepa);
        Paragraph para16 = new Paragraph(DaoS4.getLibelleLangue());
        para16.setSpacingAfter(15f);
        document.add(para16);

        Paragraph para17 = new Paragraph(new Chunk("CENTRES D'INTERET",
                FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))));
        para17.setSpacingBefore(15f);
        para17.setSpacingAfter(15f);
        document.add(para17);
        document.add(lineSepa);
        Paragraph para18 = new Paragraph(DaoS4.getLibelleInteret());
        para18.setSpacingAfter(15f);
        document.add(para18);

        document.close();
    } catch (DocumentException ex) {
        Logger.getLogger(ExportPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:at.granul.mason.collector.ChartFileScalarDataWriter.java

License:Open Source License

public static void exportGraph(XYChartGenerator chart, String prefix, int width, int height) {
    try {//  www. jav a2 s .com
        Document document = new Document(new com.lowagie.text.Rectangle(width, height));

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".pdf")));

        document.addAuthor("MASON");
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        //PdfTemplate tp = cb.createTemplate(width, height);

        //Write the chart with all datasets
        chart.addLegend();
        /*LegendTitle title = new LegendTitle(chart.getChart().getPlot());
        title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0,8,0,4));
        chart.addLegend(title);*/
        LegendTitle legendTitle = chart.getChart().getLegend();
        legendTitle.setPosition(RectangleEdge.BOTTOM);

        Graphics2D g2 = cb.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);
        chart.getChart().draw(g2, rectangle2D);
        g2.dispose();

        //PNG Output
        ChartUtilities.saveChartAsJPEG(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".png"),
                chart.getChart(), width, height);

        chart.getChart().removeLegend();
        //tp = cb.createTemplate(width, height);

        //All invisible
        final XYItemRenderer renderer = chart.getChartPanel().getChart().getXYPlot().getRenderer();
        for (int a = 0; a < chart.getSeriesCount(); a++) {
            renderer.setSeriesVisible(a, false);
        }

        final Dataset seriesDataset = chart.getSeriesDataset();
        XYSeriesCollection series = ((XYSeriesCollection) seriesDataset);
        for (int a = 0; a < chart.getSeriesCount(); a++) {
            renderer.setSeriesVisible(a, true);
            final String seriesName = series.getSeries(a).getKey() + "";
            chart.setYAxisLabel(seriesName);
            document.newPage();
            g2 = cb.createGraphics(width, height * (a + 2), new DefaultFontMapper());
            g2.translate(0, height * (a + 1));
            chart.getChart().draw(g2, rectangle2D);
            g2.dispose();

            //PNG Output
            ChartUtilities.saveChartAsJPEG(
                    new File(prefix + "_" + seriesName + DataWriter.DF.format(new Date()) + ".png"),
                    chart.getChart(), width, height);

            renderer.setSeriesVisible(a, false);
        }
        //cb.addTemplate(tp, 0, 0);

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}