Example usage for com.lowagie.text Document add

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

Introduction

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

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:QMSQuoteController.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 a  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:AppletViewer.java

License:Open Source License

/**
 * Metodo que crea un PDF a partir del archivo TIF con sus anotaciones
 * @param docid//from w ww .  j  a v  a 2 s  .  c o m
 */
public void convertDocument(String docid) {
    try {
        File dir = new File(descargados);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        dir = new File(transferencias);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        // CARGAR TIF CON ANOTACIONES
        String tmpFileName = "TMP" + String.valueOf(System.currentTimeMillis()) + ".tif";
        OutputStream output = new FileOutputStream(descargados + File.separator + tmpFileName);
        myGenDocViewer.exportDocument(output, true, false, "image/tiff");
        output.close();

        // CONVERTIR TIF A PDF
        RandomAccessFileOrArray myTiffFile = new RandomAccessFileOrArray(
                descargados + File.separator + tmpFileName);
        int numberOfPages = TiffImage.getNumberOfPages(myTiffFile);
        Document TifftoPDF = new Document();
        TifftoPDF.setMargins(0, 0, 0, 0);
        PdfWriter.getInstance(TifftoPDF,
                new FileOutputStream(transferencias + File.separator + type + "-AN.pdf"));
        TifftoPDF.open();
        for (int i = 1; i <= numberOfPages; i++) {
            Image tempImage = TiffImage.getTiffImage(myTiffFile, i);
            float dpiX = tempImage.getDpiX() == 0 ? 200 : tempImage.getDpiX();
            float dpiY = tempImage.getDpiY() == 0 ? 200 : tempImage.getDpiY();
            float factorX = 72 / dpiX;
            float factorY = 72 / dpiY;
            tempImage.scaleAbsolute(factorX * tempImage.getWidth(), factorY * tempImage.getHeight());
            TifftoPDF.add(tempImage);
        }
        myTiffFile.close();
        TifftoPDF.close();

        // BORRAR EL TIFF
        File file = new File(descargados + File.separator + tmpFileName);
        if (file.delete()) {
            System.out.println(file.getName() + " eliminado");
        } else {
            file.deleteOnExit();
            ;
            System.out.println("Eliminacion fallo");
        }

        System.out.println("Fin de la creacion del PDF con anotaciones");

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

}

From source file:ITextHelloWorld.java

License:Open Source License

public ITextHelloWorld() throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
    document.open();/*from www  . ja va  2  s.  c o  m*/
    document.add(new Paragraph("Hello World"));
    document.close();

}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsName(Airport airport, Document document) {
    // FIRST ROW//from w  w  w.  j  a  va2 s.c o m
    // AIRPORT NAME     DATE        FLIGHTGEAR

    notifyAction("createSheetsName");

    PdfPTable table = new PdfPTable(3);
    {

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        Paragraph p = new Paragraph(airport.getName().toUpperCase(), font);

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        //cell.setColspan(3);
        table.addCell(cell);
    }

    {

        DateFormat dateFormat = new SimpleDateFormat("dd MMM yy", Locale.US);
        Date date = new Date();
        String dateString = dateFormat.format(date).toUpperCase();

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                com.lowagie.text.Font.NORMAL);
        PdfPCell cell = new PdfPCell(new Paragraph(dateString, font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.COURIER,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        PdfPCell cell = new PdfPCell(new Paragraph("FLIGHTGEAR", font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    float[] widths2 = { 2f, 1f, 1f };
    try {
        table.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsAircraftTypes(Airport airport, Document document) {
    // AIRPORT NAME     Aircrafts pictures
    notifyAction("createSheetsAircraftTypes");
    PdfPTable table = new PdfPTable(2);
    {// w ww.  j  a  va2  s  .  co  m

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL);
        Paragraph p = new Paragraph(airport.getId(), font);

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

        table.addCell(cell);
    }

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.COURIER,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        PdfPCell cell = new PdfPCell(new Paragraph("FLIGHTGEAR", font));
        cell.setBorderWidth(borderWidth);
        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsFreqs(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsFreqs");
    PdfPTable table = new PdfPTable(2);
    {//w  ww .j  a va 2s .c  om
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);

        {
            if (_airport.getAtises().size() > 0) {
                String freq = "";
                for (final Atis atis : _airport.getAtises()) {
                    freq = freq + new Double(atis.getFreq()).toString() + " ";
                }

                Paragraph p = createTinyParagraph("ATIS ", freq);
                cell.addElement(p);
            }
        }

        {

            String[] reqs = { "50", "51", "52", "53", "54", "55", "56" };
            for (String req : reqs) {

                List<ATCFreq> tempFreqs = _airport.getATCFreqs(req);
                if (tempFreqs.size() > 0) {
                    String freq = "";
                    for (final ATCFreq tower : tempFreqs) {
                        freq = freq + tower.getFreq() + " ";
                    }

                    Paragraph p = createTinyParagraph(ATCFreq.typeNames.get(req) + " ", freq);
                    cell.addElement(p);

                }
            }

        }

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_TOP);

        table.addCell(cell);
    }

    {
        PdfPCell cell = new PdfPCell();
        {
            Paragraph p = new Paragraph("Nearest Navaid:", new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL));
            cell.addElement(p);
        }

        {
            Paragraph p = new Paragraph(getNEarestBeaconString(airport), new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 10, com.lowagie.text.Font.NORMAL));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);
        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsAddSvg(Airport airport, PdfWriter writer, Document document, String imageFileName) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsAddSvg");
    PdfPTable table = new PdfPTable(1);
    {// w w  w  .ja  v  a  2s .  co m
        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(height);

        {
            Paragraph p = new Paragraph();
            com.lowagie.text.Font fontWarning = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                    com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
            p.add(new Chunk(" ", fontWarning));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsFakeShops(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsFakeShops");
    PdfPTable table = new PdfPTable(1);
    {//w w  w.  j av  a2  s .com
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setMinimumHeight(20);

        boolean addWorker = false;
        for (final Runway runway : airport.getRunways()) {
            if (runway.getLength() > 1200 / FEET_PER_METER) {
                addWorker = true;
            }
        }

        boolean addFork = (airport.hasTower());

        Paragraph p = new Paragraph();
        p.setLeading((p.leading() / 2) + 4);
        if (addWorker) {
            try {
                p.add(new Chunk("   "));
                p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_work.png")), 0,
                        -3));
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (addFork) {
            try {
                p.add(new Chunk("   "));
                p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_fork.png")), 0,
                        -3));
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        cell.addElement(p);

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_TOP);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsLights(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsLights");
    PdfPTable table = new PdfPTable(1);
    {//from  w  w w. j  av  a  2 s .co m
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setMinimumHeight(20);

        Paragraph p = new Paragraph();
        p.setLeading((p.leading() / 2) + 4);
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10,
                com.lowagie.text.Font.NORMAL);

        oneLightDone = false;

        try {
            p.add(new Chunk("   ", font));
            p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "light.png")), 0, 0));
            p.add(new Chunk("   ", font));
        } catch (BadElementException ex) {
            Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
        }

        boolean addABN = airport.hasBeacon();
        if (addABN) {
            p.add(addOneLight("ABN", font));
        }

        boolean addALS = false;
        boolean addPAPI = false;
        for (final Runway runway : airport.getRunways()) {
            if ((runway.hasALSF_I(false) || runway.hasALSF_I(true))
                    || (runway.hasALSF_II(false) || runway.hasALSF_II(true))) {
                addALS = true;
            }

            if ((runway.hasPapi(false) || runway.hasPapi(true))) {
                addPAPI = true;
            }
        }
        if (addALS) {
            p.add(addOneLight("ALS", font));
        }

        if (addPAPI) {
            p.add(addOneLight("PAPI ", font));
            String separ = "";
            for (final Runway runway : airport.getRunways()) {
                if (runway.hasPapi(false)) {
                    p.add(new Chunk(separ + runway.getNumber() + " (3.5)" + degrees + " ", font));
                    separ = ", ";
                }
                if (runway.hasPapi(true)) {
                    p.add(new Chunk(separ + runway.getOppositeNumber() + " (3.5)" + degrees + " ", font));
                    separ = ", ";
                }
            }
        }

        cell.addElement(p);

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsRunways(Airport airport, Document document) {
    notifyAction("createSheetsRunways");

    PdfPTable table = new PdfPTable(6);

    // titles//from w  w  w .j av  a2s .c  om
    com.lowagie.text.Font fontTitle = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
            com.lowagie.text.Font.NORMAL);
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidth);
        Paragraph p = new Paragraph("RWY N" + degrees, fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Dimension (ft) - Surface", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("TORA (ft)", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("LDA (ft)", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Strength", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);

    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidth);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Lights", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }

    // data
    com.lowagie.text.Font fontData = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10,
            com.lowagie.text.Font.NORMAL);
    int rc = 0;
    for (final Runway runway : airport.getRunways()) {
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidth);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph(runway.getNumber() + "\r\n" + runway.getOppositeNumber(), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            String runwayLength = new Integer(runway.getLength()).toString() + " x "
                    + new Integer(runway.getWidth()).toString() + " " + runway.getSurfaceName();
            Paragraph p = new Paragraph(runwayLength, fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);

        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph(runway.getLength() + "\r\n" + runway.getLength(), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph((runway.getLength() - runway.getDisplacement()) + "\r\n"
                    + (runway.getLength() - runway.getDisplacementOpposite()), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph("to do...", fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            cell.setBorderWidthRight(borderWidth);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            Paragraph p = new Paragraph();
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            try {
                if (runway.hasALSF_I(true) || runway.hasALSF_I(false) || runway.hasALSF_II(true)
                        || runway.hasALSF_II(false) || runway.hasPapi(true) || runway.hasPapi(false)
                        || runway.hasSALSF(true) || runway.hasSALSF(false) || runway.hasSSLP(true)
                        || runway.hasSSLP(false) || runway.hasVasi(true) || runway.hasVasi(false)) {
                    p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "light.png")), 0,
                            0));
                } else {
                    p.add(new Chunk("--", fontData));
                }
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
            cell.addElement(p);
            table.addCell(cell);
        }

        rc++;

    }

    float[] widths2 = { 1f, 2f, 1f, 1f, 2f, 1f };
    try {
        table.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

}