Example usage for com.lowagie.text Document newPage

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

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:QMSMultiQuoteController.java

License:Open Source License

private int doGenerateCartagePDF(String fileName, MultiQuoteFinalDOB finalDOB, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try { //System.out.println("Starting zone PDF Generation------------------------------>");
        DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
        // Added By Kishore Podili For Multi Zone Codes
        MultiQuoteCartageRates pickQuoteCartageRates = null;
        MultiQuoteCartageRates deliQuoteCartageRates = null;
        ArrayList pickUpQuoteCartageRates = null;
        ArrayList deliveryQuoteCartageRates = null;
        Set pickBreaks = null;/*from  www. ja v a  2  s  .  c om*/
        Set deliBreaks = null;
        Set pickUpZoneCodeSet = null;
        Set deliveryZoneCodeSet = null;
        HashMap pickUpZoneCodeMap = null;
        HashMap deliveryZoneCodeMap = null;
        HashMap pickUpZoneZipMap = null;
        HashMap deliveryZoneZipMap = null;
        ArrayList zipList = null;
        ArrayList pickupWeightBreaks = null;
        ArrayList delWeightBreaks = null;
        Iterator zones = null;
        Iterator breaksSet = null;
        int pickupWeightBreaksSize = 0;
        int delWeightBreaksSize = 0;
        HttpSession session = null;
        MultiQuoteFreightLegSellRates legDestCharges = null;
        ArrayList destLaneCharges = finalDOB.getLegDetails();
        int noOfLanes = destLaneCharges.size();
        MultiQuoteMasterDOB masterDOB = finalDOB.getMasterDOB();

        //Added by Kishore For Multiple Zip and Zone Codes

        Document document = null;
        ByteArrayOutputStream baos = null;
        PdfWriter writer = null;

        MultiQuoteHeader headerDOB = finalDOB.getHeaderDOB();

        ArrayList pickupChargeBasisList = null;
        ArrayList delChargeBasisList = null;
        int pickupChargeBasisSize = 0;
        int delChargeBasisSize = 0;

        for (int dc = 0; dc < noOfLanes; dc++) {
            legDestCharges = (MultiQuoteFreightLegSellRates) destLaneCharges.get(dc);
            //Added by Anil.k kishore for Quote Charges
            //if(!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())){//END
            //Added By Kishore Podili For CartagePDF Quote Add
            //if((masterDOB.getShipperZipCode()!=null && (masterDOB.getShipperZipCode()[dc]==null || "".equals(masterDOB.getShipperZipCode()[dc])))||( masterDOB.getConsigneeZipCode()!=null && (masterDOB.getConsigneeZipCode()[dc]==null || "".equals(masterDOB.getConsigneeZipCode()[dc]))))
            //{
            //Commented By Kishore Podili
            if ((legDestCharges.getPickZoneZipMap() != null && legDestCharges.getPickZoneZipMap().size() > 0)
                    || (legDestCharges.getDeliveryZoneZipMap() != null
                            && legDestCharges.getDeliveryZoneZipMap().size() > 0)) {

                pickUpQuoteCartageRates = legDestCharges.getPickUpCartageRatesList();

                deliveryQuoteCartageRates = legDestCharges.getDeliveryCartageRatesList();
                //Modified By Kishore For MultiZoneCodes
                pickupWeightBreaks = legDestCharges.getPickupWeightBreaks(); //finalDOB.getPickupWeightBreaks();
                delWeightBreaks = legDestCharges.getDeliveryWeightBreaks(); //finalDOB.getDeliveryWeightBreaks();

                if (pickupWeightBreaks != null)
                    pickupWeightBreaksSize = pickupWeightBreaks.size();
                if (delWeightBreaks != null)
                    delWeightBreaksSize = delWeightBreaks.size();

                pickupChargeBasisList = legDestCharges.getPickupChargeBasisList(); //finalDOB.getPickupWeightBreaks();
                delChargeBasisList = legDestCharges.getDelChargeBasisList(); //finalDOB.getDeliveryWeightBreaks();

                if (pickupChargeBasisList != null)
                    pickupChargeBasisSize = pickupChargeBasisList.size();
                if (delChargeBasisList != null)
                    delChargeBasisSize = delChargeBasisList.size();

                //Commented By Kishroe Podili

                //MultiQuoteHeader    headerDOB   =    finalDOB.getHeaderDOB();

                //MultiQuoteMasterDOB masterDOB  =   finalDOB.getMasterDOB();
                ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
                ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                        .getAttribute("loginbean");
                eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
                //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());
                //@@ Commented and added by subrahmanyam for the pbn issue 212006 on #26-jul-10
                /*          String[] strDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
                String[] effDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
                */
                String[] strDate = null;
                String[] effDate = null;
                if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                    if ("PDF".equalsIgnoreCase(request.getParameter("PDF"))) {
                        strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                        effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getEffDate());
                    } else {
                        strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                        effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getCreatedDate());
                    }

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

                }

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

                StringBuffer attentionTo = new StringBuffer("");
                if (masterDOB.getCustContactNames() != null) {
                    for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                        //Logger.info(FILE_NAME,"masterDOB.getCustContactNames()[i]::"+masterDOB.getCustomerContacts()[i]);
                        attentionTo.append(
                                masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i]
                                        : "");
                        if (i != (masterDOB.getCustContactNames().length - 1))
                            attentionTo.append(",");
                    }
                }

                String chargeRate = null;

                //System.out.println("After getting data------------------------------>"+pickUpQuoteCartageRates.size());

                //Added By Kishore For MultiZone Codes
                Cell cellCountry;
                Chunk chk;
                if (dc == 0) {

                    //document = new Document(PageSize.A4,54f,54f,68.4f,68.4f);//@@ 36 points represent 0.5 inch  
                    document = new Document(PageSize.A4, 10f, 10f, 20f, 20f); //added by silpa on 27-06-11
                    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();

                    baos = new ByteArrayOutputStream();
                    writer = PdfWriter.getInstance(document, baos);
                    //added by silpa on 27-06-11
                    document.open();
                    PdfContentByte cb = writer.getDirectContent();
                    cb.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                            document.top() - document.bottom());
                    cb.stroke();//ended

                    int[] widths = { 10, 10, 10, 10, 10, 10, 12, 28 };

                    Table mainT = new Table(8);
                    mainT.setWidth(100);
                    mainT.setWidths(widths);
                    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);
                    //img0.scalePercent(75);
                    imageCell.add(img0);
                    imageCell.setHorizontalAlignment(imageCell.ALIGN_RIGHT);
                    imageCell.setBorderWidth(0);
                    imageCell.setNoWrap(true);
                    imageCell.setColspan(1);
                    mainT.addCell(imageCell);
                    mainT.setAlignment(mainT.ALIGN_CENTER);
                    document.add(mainT);

                    //pickBreaks = pickQuoteCartageRates.getRates().keySet();
                    //System.out.println("After Heading ----------------pickBreaks----------->");            
                    Table partCountry = new Table(1, 4);
                    partCountry.setBorderWidth(0);
                    partCountry.setWidth(100);
                    partCountry.setBorderColor(Color.black);
                    //partCountry.setBackgroundColor(Color.ORANGE);
                    partCountry.setPadding(1);
                    partCountry.setSpacing(1);
                    partCountry.setAutoFillEmptyCells(true);
                    //partCountry.setTableFitsPage(true);
                    partCountry.setAlignment(partCountry.ALIGN_CENTER);
                    // partCountry.setWidth(100.0f);
                    /*Cell cellCountry;
                    Chunk chk;*/

                    chk = new Chunk("ANNEXURE", 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);

                    if ("MY".equalsIgnoreCase(masterDOB.getCountryId())) {
                        chk = new Chunk((headerDOB.getOriginCountry() != null
                                ? headerDOB.getOriginCountry()[dc].toUpperCase()
                                : "")
                                + " TO "
                                + (headerDOB.getDestinationCountry() != null
                                        ? headerDOB.getDestinationCountry()[dc].toUpperCase()
                                        : ""),
                                FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);

                        chk = new Chunk(headerDOB.getCustomerName(),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setHeader(true);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);
                        //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

                        chk = new Chunk("ATTENTION TO: " + toTitleCase(attentionTo.toString()),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);
                    } else {
                        chk = new Chunk((headerDOB.getOriginCountry() != null
                                ? headerDOB.getOriginCountry()[dc].toUpperCase()
                                : "")
                                + " TO "
                                + (headerDOB.getDestinationCountry() != null
                                        ? headerDOB.getDestinationCountry()[dc].toUpperCase()
                                        : ""),
                                FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);

                        chk = new Chunk(headerDOB.getCustomerName(),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setHeader(true);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);
                        //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

                        chk = new Chunk("ATTENTION TO: " + toTitleCase(attentionTo.toString()),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);
                    }
                    chk = new Chunk("QUOTE REFERENCE: " + masterDOB.getQuoteId(),
                            FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    cellCountry = new Cell(chk);
                    cellCountry.setWidth("100");
                    cellCountry.setBorderWidth(0);
                    cellCountry.setNoWrap(true);
                    cellCountry.setLeading(10.0f);
                    cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                    partCountry.addCell(cellCountry);
                    chk = new Chunk("DATE OF QUOTATION: " + strDate[0],
                            FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    cellCountry = new Cell(chk);
                    cellCountry.setWidth("100");
                    cellCountry.setBorderWidth(0);
                    cellCountry.setNoWrap(true);
                    cellCountry.setLeading(10.0f);
                    cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                    partCountry.addCell(cellCountry);

                    document.add(partCountry);

                }

                if (dc > 0) {
                    document.newPage();

                }

                Table partZone = null;
                Cell cellZone;

                if (pickUpQuoteCartageRates != null && pickUpQuoteCartageRates.size() > 0) {
                    /*Set keys = null;            
                    for(int i=0;i<pickUpQuoteCartageRates.size();i++)
                    {              
                      if(i==0)
                      { 
                        pickBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
                      }
                      pickQuoteCartageRates = (QuoteCartageRates) pickUpQuoteCartageRates.get(i);
                      keys = pickQuoteCartageRates.getRates().keySet();
                      pickBreaks.addAll(keys);
                    }*/

                    //if(pickBreaks!=null && pickBreaks.size()>0)
                    //if(pickupWeightBreaks != null && pickupWeightBreaksSize>0)
                    partZone = new Table(pickupWeightBreaksSize + 2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setAutoFillEmptyCells(true);
                    partZone.setWidth(100);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 09/12/2008
                    chk = new Chunk("PICKUP CARTAGE RATES AT: " + headerDOB.getOriginLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setLeading(10.0f);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setColspan(pickupWeightBreaksSize + 2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 09/12/2008
                    chk = new Chunk("PICKUP CARTAGE RATES",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setLeading(10.0f);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setColspan(pickupWeightBreaksSize + 2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    //cellZone.setNoWrap(true);
                    cellZone.setLeading(8.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setLeading(8.0f);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    //breaksSet = pickBreaks.iterator();  // logger.info("breaksSetbreaksSet::"+breaksSet);
                    /*while(breaksSet.hasNext())
                    {              
                      chk = new Chunk((String)breaksSet.next(),FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                      cellZone = new Cell(chk);              
                      cellZone.setNoWrap(true);
                      cellZone.setHeader(true);
                      partZone.addCell(cellZone);
                    }*/
                    //if(pickupWeightBreaks!=null)
                    //{
                    //logger.info("pickupWeightBreaks"+pickupWeightBreaks);
                    for (int i = 0; i < pickupWeightBreaksSize; i++) {
                        chk = new Chunk((String) pickupWeightBreaks.get(i),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }
                    //}
                    partZone.endHeaders();

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    // cellZone.setHeader(true);
                    // cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    for (int i = 0; i < pickupChargeBasisSize; i++) {
                        chk = new Chunk(toTitleCase((String) pickupChargeBasisList.get(i)),
                                FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }

                    int pikupQuoteCartRatSize = pickUpQuoteCartageRates.size();
                    label0: for (int i = 0; i < pikupQuoteCartRatSize; i++) {
                        pickQuoteCartageRates = (MultiQuoteCartageRates) pickUpQuoteCartageRates.get(i); // By Kishore For Multiple Zone Code
                        chk = new Chunk(pickQuoteCartageRates.getZone(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        chk = new Chunk(pickQuoteCartageRates.getCurrency(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        pickUpZoneCodeMap = pickQuoteCartageRates.getRates();

                        /*breaksSet = pickBreaks.iterator();
                        while(breaksSet.hasNext())
                         {
                           String wBreak = (String)breaksSet.next();
                           if(pickUpZoneCodeMap.containsKey(wBreak))
                           {
                            chargeRate = (String)pickUpZoneCodeMap.get(wBreak);
                            chargeRate  = df.format(Double.parseDouble(chargeRate));
                           }
                           else
                           {
                            chargeRate = "--";              
                           }
                          chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                          cellZone = new Cell(chk);
                          cellZone.setNoWrap(true);            
                          partZone.addCell(cellZone); 
                         }*/

                        // ------------------------------------------------------  //added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
                        if (pickupWeightBreaks == null) {
                            continue;
                        }
                        String wBreak = null;
                        int k = 0;
                        do {
                            if (k >= pickupWeightBreaksSize) {
                                continue label0;
                            }
                            wBreak = (String) pickupWeightBreaks.get(k);
                            if (wBreak != null && pickUpZoneCodeMap.containsKey(wBreak)) {
                                chargeRate = (String) pickUpZoneCodeMap.get(wBreak);
                                chargeRate = df.format(Double.parseDouble(chargeRate));
                            } else {
                                chargeRate = "--";
                            }
                            chk = new Chunk(chargeRate, FontFactory.getFont("ARIAL", 8F, 1, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8F);
                            partZone.addCell(cellZone);
                            k++;
                        } while (true);
                    }
                    document.add(partZone);
                }
                if (deliveryQuoteCartageRates != null && deliveryQuoteCartageRates.size() > 0) {
                    /*Set dkeys         = null;
                    for(int i=0;i<deliveryQuoteCartageRates.size();i++)
                    {       
                     if(i==0)
                     { 
                       deliBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
                     }
                     deliQuoteCartageRates = (QuoteCartageRates) deliveryQuoteCartageRates.get(i);
                     dkeys = deliQuoteCartageRates.getRates().keySet();
                     deliBreaks.addAll(dkeys);
                     //System.out.println("Before zone header------------------------------>"+deliBreaks);
                     //System.out.println("Before zone header------------------------------>"+deliBreaks.size());              
                    }*/

                    partZone = new Table(delWeightBreaksSize + 2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setWidth(100);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CARTAGE RATES AT: " + headerDOB.getDestLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setLeading(10.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(delWeightBreaksSize + 2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CARTAGE RATES",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setLeading(10.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(delWeightBreaksSize + 2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    //breaksSet = deliBreaks.iterator();

                    /*while(breaksSet.hasNext())
                    {              
                      String breaks = (String)breaksSet.next();
                            
                      chk = new Chunk(breaks,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                      cellZone = new Cell(chk);              
                      cellZone.setNoWrap(true);
                      cellZone.setHeader(true);
                      partZone.addCell(cellZone);
                    }*/
                    for (int i = 0; i < delWeightBreaksSize; i++) {
                        chk = new Chunk((String) delWeightBreaks.get(i),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);
                        cellZone.setHeader(true);
                        cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }
                    partZone.endHeaders();

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    for (int i = 0; i < delChargeBasisSize; i++) {
                        chk = new Chunk(toTitleCase((String) delChargeBasisList.get(i)),
                                FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }

                    int delQuoteCartRtSize = deliveryQuoteCartageRates.size();
                    for (int i = 0; i < delQuoteCartRtSize; i++) {
                        deliQuoteCartageRates = (MultiQuoteCartageRates) deliveryQuoteCartageRates.get(i); // By Kishore For Multiple Zone Code

                        chk = new Chunk(deliQuoteCartageRates.getZone(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        chk = new Chunk(deliQuoteCartageRates.getCurrency(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);
                        // String charge_type=deliQuoteCartageRates.getBuyOrSellRate();  //@@Added by kiran.v

                        deliveryZoneCodeMap = deliQuoteCartageRates.getRates();

                        //breaksSet = deliBreaks.iterator();
                        /*while(breaksSet.hasNext())
                         {
                           String wBreak = (String)breaksSet.next();
                           if(deliveryZoneCodeMap.containsKey(wBreak))
                           {
                            chargeRate = (String)deliveryZoneCodeMap.get(wBreak);  
                            chargeRate  = df.format(Double.parseDouble(chargeRate));
                           }
                           else
                           {
                            chargeRate = "--";              
                           }
                          chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                          cellZone = new Cell(chk);
                          cellZone.setNoWrap(true);            
                          partZone.addCell(cellZone); 
                         }*/
                        String wBreak = null;
                        for (int k = 0; k < delWeightBreaksSize; k++) {
                            wBreak = (String) delWeightBreaks.get(k);
                            if (wBreak != null && deliveryZoneCodeMap.containsKey(wBreak)) {
                                chargeRate = (String) deliveryZoneCodeMap.get(wBreak);
                                chargeRate = df.format(Double.parseDouble(chargeRate));
                            } else {
                                chargeRate = "--";
                            }
                            chk = new Chunk(chargeRate,
                                    FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8.0f);
                            //cellZone.setNoWrap(true);            
                            partZone.addCell(cellZone);
                        }
                    }
                    //System.out.println("After zone header------------------------------>");
                    document.add(partZone);

                }

                pickUpZoneZipMap = legDestCharges.getPickZoneZipMap();
                //@@For Sorting the Zone Codes in an Order.
                List list = new ArrayList();
                Set zoneSet;
                //@@End of Declarations - Sorting
                if (pickUpZoneZipMap != null && pickUpZoneZipMap.size() > 0) {
                    //System.out.println("Before zipCode header--------Set size------->"+pickUpZoneZipMap.keySet().size());
                    //@@Sorting the Zone Codes (as TreeSet implements java.util.SortedSet)
                    list.addAll(pickUpZoneZipMap.keySet());
                    zoneSet = new TreeSet(list);
                    //@@End of Sorting- Added by Yuvraj

                    zones = zoneSet.iterator();

                    partZone = new Table(2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setWidth(100);
                    //partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("PICKUP CHARGES AT: " + headerDOB.getOriginLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    //@@ Ended by subrahmanyam for the enhancement #147062 on  08/12/2008
                    chk = new Chunk("PICKUP ZONE ZIP MAPPING",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    partZone.addCell(cellZone);
                    partZone.endHeaders();
                    // System.out.println("Before zipCode Body------------------------------>");

                    while (zones.hasNext()) {
                        String zone = (String) zones.next();
                        // System.out.println("zone------------------------------>"+zone);
                        zipList = (ArrayList) pickUpZoneZipMap.get(zone);
                        //System.out.println("zipList--------------------------->"+zipList);
                        int zipListSize = zipList.size();
                        for (int i = 0; i < zipListSize; i++) {
                            //System.out.println("zone for ------------------------------>"+zone);
                            if (zone != null && !zone.equals("null") && zipList.get(i) != null
                                    && !((String) zipList.get(i)).equals("null")) {
                                chk = new Chunk(zone, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                cellZone = new Cell(chk);
                                cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                                cellZone.setLeading(8.0f);
                                //cellZone.setNoWrap(true);            
                                partZone.addCell(cellZone);
                                //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                                chk = new Chunk((String) zipList.get(i),
                                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                cellZone = new Cell(chk);
                                cellZone.setLeading(8.0f);
                                cellZone.setNoWrap(true);
                                partZone.addCell(cellZone);
                            }
                        }
                    }
                    document.add(partZone);
                }

                deliveryZoneZipMap = legDestCharges.getDeliveryZoneZipMap();

                list = new ArrayList();
                zoneSet = null;

                if (deliveryZoneZipMap != null && deliveryZoneZipMap.size() > 0) {
                    //System.out.println("Before zipCode header--------Set size------->"+deliveryZoneZipMap.keySet().size());
                    list.addAll(deliveryZoneZipMap.keySet());
                    zoneSet = new TreeSet(list);
                    zones = zoneSet.iterator();

                    partZone = new Table(2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setWidth(100);
                    //partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CHARGES AT: " + headerDOB.getDestLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008 
                    chk = new Chunk("DELIVERY ZONE ZIP MAPPING",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);

                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    partZone.addCell(cellZone);
                    partZone.endHeaders();
                    //System.out.println("Before zipCode Body------------------------------>");

                    while (zones.hasNext()) {
                        String zone = (String) zones.next();
                        //System.out.println("zone------------------------------>"+zone);
                        zipList = (ArrayList) deliveryZoneZipMap.get(zone);
                        if (zipList != null) {
                            //System.out.println("zipList--------------------------->"+zipList);
                            //logger.info("zipList--------------------------->"+zipList);
                            int zipListSize = zipList.size();
                            for (int i = 0; i < zipListSize; i++) {
                                //System.out.println("zone for ------------------------------>"+zone);
                                if (zone != null && !zone.equals("null") && zipList.get(i) != null
                                        && !((String) zipList.get(i)).equals("null")) {
                                    chk = new Chunk(zone,
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cellZone = new Cell(chk);
                                    cellZone.setLeading(8.0f);
                                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                                    cellZone.setNoWrap(true);
                                    partZone.addCell(cellZone);
                                    //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                                    chk = new Chunk((String) zipList.get(i),
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cellZone = new Cell(chk);
                                    cellZone.setLeading(8.0f);
                                    cellZone.setNoWrap(true);
                                    partZone.addCell(cellZone);
                                }
                            }
                        }
                    }
                    document.add(partZone);
                }

                // Commmented by Kishore to move the code after the for loop for Multiple lanes 

                //System.out.println("After zipCode header------------------------------>");

                /*document.close();
                //System.out.println("After     document Close----------------------------------------->");               
                File f = new File("Cartage.pdf");
                FileOutputStream  fileOutputStream= new FileOutputStream(f);
                baos.writeTo(fileOutputStream);
                fileOutputStream.close();//added by sanjay on 20/03/2006
                //@@Added by Kameswari for the WPBN issue-80440
                PdfReader reader = new PdfReader("Cartage.pdf");
                int n = reader.getNumberOfPages();
                File fs = new File(fileName);
                String   space = " ";
                // we create a stamper that will copy the document to a new file
                PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));
                        
                // adding some metadata
                // adding content to each page
                        
                int k = 0;
                PdfContentByte under;
                PdfContentByte over=null;
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
                while (k < n) {
                k++;
                   over = stamp.getOverContent(k);
                over.beginText();
                over.setFontAndSize(bf, 8);
                over.setTextMatrix(15, 15);
                over.showText("page " + k+" of "+n);
                        
                if(k>1)
                {
                over.setFontAndSize(bf, 7);
                over.showText("                                                                                                       QUOTE REFERENCE:"+masterDOB.getQuoteId());
                //@@Added by subrahmanyam for the WPBN:146452 on 12/12/2008
                over.endText();
                over.beginText();
                over.showText("                                                                                                                                    CUSTOMER NAME: "+headerDOB.getCustomerName());//subrahmanyam 12/12/2008
                //@@ Ended by subrahmanyam for the WPBM:146452 on 12/12/2008               
                }
                over.endText();
                }
                stamp.close();
                //@@WPBN issue-80440    
                //@@ Commented by subrahmanyam for 146460         
                if("on".equalsIgnoreCase(request.getParameter("print")))
                {
                        
                   request.getSession().setAttribute("CartageOuptutStream",fs);
                }
                //@@ Added by subrahmanyam for  146460                
                        
                 if("on".equalsIgnoreCase(request.getParameter("print"))||"PDF".equalsIgnoreCase(request.getParameter("pdf")))
                {
                           
                   request.getSession().setAttribute("CartageOuptutStream",fs);
                }
                        
                //@@ Ended by subrahmanyam for 146460
                //f.delete();
                baos.close();*/
                //}
            }
            //} //Added by Anil.k   kishore Charges
        }
        //System.out.println("End of generation header------------------------------>");
        //Added By Kishore Podili fpr multiple Zone Codes
        if (document != null) {

            document.close();
            // System.out.println("After document
            // Close----------------------------------------->");
            File f = new File("Cartage.pdf");
            FileOutputStream fileOutputStream = new FileOutputStream(f);
            baos.writeTo(fileOutputStream);
            fileOutputStream.close();// added by sanjay on 20/03/2006
            // @@Added by Kameswari for the WPBN issue-80440
            PdfReader reader = new PdfReader("Cartage.pdf");
            int n = reader.getNumberOfPages();
            File fs = new File(fileName);
            String space = " ";
            // we create a stamper that will copy the document to a new file
            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));

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

            int k = 0;
            PdfContentByte under;
            PdfContentByte over = null;
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
            while (k < n) {
                k++;
                over = stamp.getOverContent(k);
                //jyothi
                //over.rectangle(30, 30, 550, 800);
                over.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                        document.top() - document.bottom());
                over.stroke();
                //jyothi
                over.beginText();
                over.setFontAndSize(bf, 8);
                over.setTextMatrix(15, 15);
                over.showText("page " + k + " of " + n);

                if (k > 1) {
                    over.setFontAndSize(bf, 7);
                    over.showText("QUOTE REFERENCE:" + masterDOB.getQuoteId());
                    // @@Added by subrahmanyam for the WPBN:146452 on
                    // 12/12/2008
                    over.endText();
                    over.beginText();
                    over.showText("CUSTOMER NAME: " + headerDOB.getCustomerName());// subrahmanyam
                    // 12/12/2008
                    // @@ Ended by subrahmanyam for the WPBM:146452 on
                    // 12/12/2008
                }
                over.endText();
            }
            stamp.close();
            // @@WPBN issue-80440
            // @@ Commented by subrahmanyam for 146460
            /*
             * if("on".equalsIgnoreCase(request.getParameter("print"))) {
             * 
             * request.getSession().setAttribute("CartageOuptutStream",fs); }
             */
            // @@ Added by subrahmanyam for 146460
            if ("on".equalsIgnoreCase(request.getParameter("print"))
                    || "PDF".equalsIgnoreCase(request.getParameter("pdf"))) {

                request.getSession().setAttribute("CartageOuptutStream", fs);
            }

            // @@ Ended by subrahmanyam for 146460
            // f.delete();
            baos.close();

            // Added by Kishore Podili For Cartage PDF Attachement in the MAIL.  
            FileInputStream fis = new FileInputStream(fileName);
            // PdfReader preader = new PdfReader()
            ArrayList attachmentDOBList = finalDOB.getAttachmentDOBList();

            if (attachmentDOBList == null)
                attachmentDOBList = new ArrayList();

            MultiQuoteAttachmentDOB attachementDOB = new MultiQuoteAttachmentDOB();
            attachementDOB.setFileName(fileName);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            attachementDOB.setPdfFile(buffer);

            attachmentDOBList.add(attachementDOB);
            finalDOB.setAttachmentDOBList(attachmentDOBList);
            fis.close();
        }

        // System.out.println("End of generation
        // header------------------------------>");
    } 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());
        throw new Exception("Error while generating PDF format");
    }
    return 1;
}

From source file:FirstPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//w  ww  . j ava 2  s  .c o  m
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));
    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));
    addEmptyLine(preface, 8);
    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.de ;-).",
            redFont));
    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheets1(Airport airport, PdfWriter writer, Document document, String pdfName,
        boolean drawObjectsInMap, boolean drawTerrainInMap) {
    // doing PDF now
    try {/*from w  w w.  j  av  a  2  s  .  co  m*/

        //PdfWriter pdfwriter = PdfWriter.getInstance(document, new FileOutputStream(pdfName));

        // step 3: we open the document
        //document.open();

        // step 4: we add some paragraphs to the document
        //document.add(
        //new Paragraph(airport.getId()+" - "+airport.getName())
        //);

        createSheetsName(airport, document);
        createSheetsAircraftTypes(airport, document);
        createSheetsFreqs(airport, document);
        //createSheetsAddImage(airport,document,pngName1);
        createSheetsAddSvg(airport, writer, document, pdfName);
        createSheetsFakeShops(airport, document);
        createSheetsLights(airport, document);
        createSheetsRunways(airport, document);
        createSheetsNotes(airport, document);

        // part 2
        document.newPage();

        createSheets2Name(airport, document);
        createSheets2Freqs(airport, document);
        createSheets2ILS(airport, document);
        //createSheets2AddImage(airport,document,pngName2,keepPng);

        createSheets2AddSvg(airport, writer, document, drawObjectsInMap, drawTerrainInMap);

        /*table.setWidthPercentage(50);
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);
        document.add(table);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        document.add(table);
        */

        // step 5: we close the document
        document.close();

        notifyAction("");

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

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void xml2pdf(InputSource xml, OutputStream pdf) {

    try {//from w w w.  j  a va 2 s  .c  o m
        Document document = new Document(PageSize.A4, 80, 50, 30, 65);

        PdfWriter writer = PdfWriter.getInstance(document, pdf);
        //writer.setViewerPreferences(PdfWriter.HideMenubar| PdfWriter.HideToolbar);
        writer.setViewerPreferences(PdfWriter.PageModeUseThumbs | PdfWriter.PageModeUseOutlines);
        //PdfOutline root = writer.getDirectContent().getRootOutline();
        //new PdfOutline(root, new PDFAction("http://nina.acad.bg/qmrf"), "a bookmark");

        //writer.addFileAttachment(arg0, arg1, arg2, arg3)

        if (docBuilder == null)
            docBuilder = docBuilderFactory.newDocumentBuilder();
        docBuilder.setErrorHandler(new SimpleErrorHandler(getClass().getName()));
        QMRFSchemaResolver resolver = new QMRFSchemaResolver("http://ambit.acad.bg/qmrf/qmrf.dtd", null);
        resolver.setIgnoreSystemID(true);
        docBuilder.setEntityResolver(resolver);

        org.w3c.dom.Document doc = null;
        try {
            doc = docBuilder.parse(xml);
        } catch (Exception x) {
            document.addCreationDate();
            document.addCreator(getClass().getName());
            document.open();
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        document.addCreationDate();
        document.addCreator(getClass().getName());
        document.addKeywords(replaceTags(findNodeValue("keywords", doc)));
        document.addTitle(replaceTags(findNodeValue("QSAR_title", doc)));

        try {
            NodeList info = doc.getElementsByTagName("QMRF");
            for (int i = 0; i < info.getLength(); i++)
                document.addSubject(findAttributeValue("name", info.item(i)) + '.'
                        + findAttributeValue("version", info.item(i)));
        } catch (Exception x) {
            document.addSubject("QMRF");
        }
        try {
            document.addAuthor(listNodeAttributes(doc, "qmrf_authors", "author_ref", "author", att_author,
                    new Boolean(true)));
        } catch (Exception x) {
            document.addAuthor(getClass().getName());
        }

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

        try {
            headerTable(document, doc);
        } catch (Exception x) {
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        PdfOutline root = writer.getDirectContent().getRootOutline();

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

            try {
                int align = Paragraph.ALIGN_LEFT;
                if (Mode.chapter == (Mode) subchapters[i][2]) {
                    document.add(new Paragraph(new Chunk('\n')));
                    PdfPTable table = new PdfPTable(1);

                    table.setWidthPercentage(100);

                    StringBuffer b = new StringBuffer();
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                    b.append('.');
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                    String bookmark = b.toString();

                    Chunk title = new Chunk(bookmark);
                    title.setLocalDestination(bookmark);
                    title.setFont(bfont);

                    PdfDestination destination = new PdfDestination(PdfDestination.FITH);
                    PdfOutline outline = new PdfOutline(root, destination, bookmark);

                    Paragraph p = new Paragraph(title);

                    PdfPCell cell = new PdfPCell(p);
                    cell.setBackgroundColor(chapterColor);
                    table.addCell(cell);
                    document.add(table);
                    float pos = writer.getVerticalPosition(false);
                    if (pos < 90)
                        document.newPage();
                } else {
                    Phrase phrase = new Phrase();
                    switch ((Mode) subchapters[i][2]) {
                    case title: {
                        StringBuffer b = new StringBuffer();
                        String cn = findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter,
                                doc);
                        if (cn == null)
                            break;

                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                        b.append('.');
                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                        String subchapterBookmark = b.toString();
                        b.append(':');

                        Chunk title = new Chunk(b.toString());
                        title.setLocalDestination(subchapterBookmark);
                        title.setFont(bfont);
                        phrase.add(title);

                        PdfDestination destination = new PdfDestination(PdfDestination.FITBH);
                        PdfOutline outline = new PdfOutline(root, destination, subchapterBookmark);

                        break;

                    }
                    case text: {
                        createNodePhrase(subchapters[i][0].toString(), doc, phrase, font);
                        align = Paragraph.ALIGN_JUSTIFIED;
                        break;
                    }
                    case answer: {
                        String a = findAnswer(subchapters[i][0].toString(), doc);
                        if (a != null) {
                            Chunk answer = new Chunk(a);
                            answer.setFont(font);
                            phrase.add(answer);
                        }
                        break;
                    }
                    case dataset: {
                        StringBuffer b = new StringBuffer();
                        b.append(findDataAvailable(subchapters[i][0].toString(), doc));
                        Chunk dataset = new Chunk(b.toString());
                        dataset.setFont(font);
                        phrase.add(dataset);
                        break;
                    }
                    case attachments: {
                        PdfPTable table = getAttachmentsAsTable(doc, "attachment_training_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Training set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_validation_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Test set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_documents");
                        if (table != null) {
                            phrase.add(new Paragraph("Supporting information"));
                            phrase.add(table);
                        }
                        break;
                        /*
                        StringBuffer b = new StringBuffer();
                        b.append("Training set(s)\n");
                         b.append(listAttachments(doc,"attachment_training_data"));
                         b.append("Test set(s)\n");
                         b.append(listAttachments(doc,"attachment_validation_data"));
                         b.append("Supporting information\n");
                         b.append(listAttachments(doc,"attachment_documents"));
                        Chunk attachments = new Chunk(b.toString());
                        attachments.setFont(font);
                        phrase.add(attachments);
                                
                        break;
                        */
                    }
                    case reference: {
                        try {
                            String value = listNodeAttributes(doc, subchapters[i][0].toString(),
                                    subchapters[i][3].toString(), subchapters[i][4].toString(),
                                    (String[]) subchapters[i][5], (Boolean) subchapters[i][6]);

                            Chunk reference = new Chunk(value);
                            reference.setFont(font);
                            align = Paragraph.ALIGN_JUSTIFIED;
                            phrase.add(reference);
                        } catch (Exception x) {

                        }
                        break;

                    }
                    }

                    Paragraph p = new Paragraph(phrase);
                    p.setAlignment(align);
                    document.add(p);
                    float pos = writer.getVerticalPosition(false);
                    /*
                    cb.moveTo(0, pos);
                    cb.lineTo(PageSize.A4.width(), pos);
                    cb.stroke();
                    */
                    if (pos < 90)
                        document.newPage();
                }
            } catch (Exception x) {
                x.printStackTrace();
            }

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
}

From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void xml2pdf(InputSource xml, OutputStream pdf) {

    try {/*  ww  w  . j av a  2 s .c om*/
        Document document = new Document(PageSize.A4, 80, 50, 30, 65);

        PdfWriter writer = PdfWriter.getInstance(document, pdf);
        //writer.setViewerPreferences(PdfWriter.HideMenubar| PdfWriter.HideToolbar);
        writer.setViewerPreferences(PdfWriter.PageModeUseThumbs | PdfWriter.PageModeUseOutlines);
        //PdfOutline root = writer.getDirectContent().getRootOutline();
        //new PdfOutline(root, new PDFAction("http://nina.acad.bg/qmrf"), "a bookmark");

        //writer.addFileAttachment(arg0, arg1, arg2, arg3)

        if (docBuilder == null)
            docBuilder = docBuilderFactory.newDocumentBuilder();
        docBuilder.setErrorHandler(new SimpleErrorHandler(getClass().getName()));
        QMRFSchemaResolver resolver = new QMRFSchemaResolver("http://ambit2.acad.bg/qmrf/qmrf.dtd", null);
        resolver.setIgnoreSystemID(true);
        docBuilder.setEntityResolver(resolver);

        org.w3c.dom.Document doc = null;
        try {
            doc = docBuilder.parse(xml);
        } catch (Exception x) {
            document.addCreationDate();
            document.addCreator(getClass().getName());
            document.open();
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        document.addCreationDate();
        document.addCreator(getClass().getName());
        document.addKeywords(replaceTags(findNodeValue("keywords", doc)));
        document.addTitle(replaceTags(findNodeValue("QSAR_title", doc)));

        try {
            NodeList info = doc.getElementsByTagName("QMRF");
            for (int i = 0; i < info.getLength(); i++)
                document.addSubject(findAttributeValue("name", info.item(i)) + '.'
                        + findAttributeValue("version", info.item(i)));
        } catch (Exception x) {
            document.addSubject("QMRF");
        }
        try {
            document.addAuthor(listNodeAttributes(doc, "qmrf_authors", "author_ref", "author", att_author,
                    new Boolean(true)));
        } catch (Exception x) {
            document.addAuthor(getClass().getName());
        }

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

        try {
            headerTable(document, doc);
        } catch (Exception x) {
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        PdfOutline root = writer.getDirectContent().getRootOutline();

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

            try {
                int align = Paragraph.ALIGN_LEFT;
                if (Mode.chapter == (Mode) subchapters[i][2]) {
                    document.add(new Paragraph(new Chunk('\n')));
                    PdfPTable table = new PdfPTable(1);

                    table.setWidthPercentage(100);

                    StringBuffer b = new StringBuffer();
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                    b.append('.');
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                    String bookmark = b.toString();

                    Chunk title = new Chunk(bookmark);
                    title.setLocalDestination(bookmark);
                    title.setFont(bfont);

                    PdfDestination destination = new PdfDestination(PdfDestination.FITH);
                    PdfOutline outline = new PdfOutline(root, destination, bookmark);

                    Paragraph p = new Paragraph(title);

                    PdfPCell cell = new PdfPCell(p);
                    cell.setBackgroundColor(chapterColor);
                    table.addCell(cell);
                    document.add(table);
                    float pos = writer.getVerticalPosition(false);
                    if (pos < 90)
                        document.newPage();
                } else {
                    Phrase phrase = new Phrase();
                    switch ((Mode) subchapters[i][2]) {
                    case title: {
                        StringBuffer b = new StringBuffer();
                        String cn = findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter,
                                doc);
                        if (cn == null)
                            break;

                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                        b.append('.');
                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                        String subchapterBookmark = b.toString();
                        b.append(':');

                        Chunk title = new Chunk(b.toString());
                        title.setLocalDestination(subchapterBookmark);
                        title.setFont(bfont);
                        phrase.add(title);

                        PdfDestination destination = new PdfDestination(PdfDestination.FITBH);
                        PdfOutline outline = new PdfOutline(root, destination, subchapterBookmark);

                        break;

                    }
                    case text: {
                        createNodePhrase(subchapters[i][0].toString(), doc, phrase, font);
                        align = Paragraph.ALIGN_JUSTIFIED;
                        break;
                    }
                    case answer: {
                        String a = findAnswer(subchapters[i][0].toString(), doc);
                        if (a != null) {
                            Chunk answer = new Chunk(a);
                            answer.setFont(font);
                            phrase.add(answer);
                        }
                        break;
                    }
                    case dataset: {
                        StringBuffer b = new StringBuffer();
                        b.append(findDataAvailable(subchapters[i][0].toString(), doc));
                        Chunk dataset = new Chunk(b.toString());
                        dataset.setFont(font);
                        phrase.add(dataset);
                        break;
                    }
                    case attachments: {
                        PdfPTable table = getAttachmentsAsTable(doc, "attachment_training_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Training set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_validation_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Test set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_documents");
                        if (table != null) {
                            phrase.add(new Paragraph("Supporting information"));
                            phrase.add(table);
                        }
                        break;
                        /*
                        StringBuffer b = new StringBuffer();
                        b.append("Training set(s)\n");
                         b.append(listAttachments(doc,"attachment_training_data"));
                         b.append("Test set(s)\n");
                         b.append(listAttachments(doc,"attachment_validation_data"));
                         b.append("Supporting information\n");
                         b.append(listAttachments(doc,"attachment_documents"));
                        Chunk attachments = new Chunk(b.toString());
                        attachments.setFont(font);
                        phrase.add(attachments);
                                
                        break;
                        */
                    }
                    case reference: {
                        try {
                            String value = listNodeAttributes(doc, subchapters[i][0].toString(),
                                    subchapters[i][3].toString(), subchapters[i][4].toString(),
                                    (String[]) subchapters[i][5], (Boolean) subchapters[i][6]);

                            Chunk reference = new Chunk(value);
                            reference.setFont(font);
                            align = Paragraph.ALIGN_JUSTIFIED;
                            phrase.add(reference);
                        } catch (Exception x) {

                        }
                        break;

                    }
                    }

                    Paragraph p = new Paragraph(phrase);
                    p.setAlignment(align);
                    document.add(p);
                    float pos = writer.getVerticalPosition(false);
                    /*
                    cb.moveTo(0, pos);
                    cb.lineTo(PageSize.A4.width(), pos);
                    cb.stroke();
                    */
                    if (pos < 90)
                        document.newPage();
                }
            } catch (Exception x) {
                x.printStackTrace();
            }

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
}

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

License:Open Source License

public static void exportGraph(XYChartGenerator chart, String prefix, int width, int height) {
    try {//  w  ww  . ja v a2 s  . co  m
        Document document = new Document(new com.lowagie.text.Rectangle(width, height));

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

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

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

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

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

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

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

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

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

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

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

From source file:at.tugraz.sss.serv.SSFileU.java

License:Apache License

public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws Exception {

    OutputStream out = null;/*from w  ww .j a va2 s.c om*/
    BufferedReader br = null;

    try {

        out = openOrCreateFileWithPathForWrite(pdfFilePath);

        final Document document = new Document();
        final PdfWriter writer = PdfWriter.getInstance(document, out);
        String line;

        document.open();
        writer.setPageEmpty(true);
        document.newPage();
        writer.setPageEmpty(true);

        br = new BufferedReader(new FileReader(new File(textFilePath)));

        while ((line = br.readLine()) != null) {
            document.add(new Paragraph(line));
        }

        document.close();

    } catch (Exception error) {

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

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

From source file:at.tugraz.sss.serv.SSFileU.java

License:Apache License

public static void writePDFFromDoc(final String docFilePath, final String pdfFilePath) throws Exception {

    final Document document = new Document();
    final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath));
    final HWPFDocument word = new HWPFDocument(fs);
    final WordExtractor we = new WordExtractor(word);
    final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath);
    final PdfWriter writer = PdfWriter.getInstance(document, out);
    final Range range = word.getRange();

    document.open();/*from   w  w  w .j a v  a2s  . co  m*/
    writer.setPageEmpty(true);
    document.newPage();
    writer.setPageEmpty(true);

    String[] paragraphs = we.getParagraphText();

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

        org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i);
        // CharacterRun run = pr.getCharacterRun(i);
        // run.setBold(true);
        // run.setCapitalized(true);
        // run.setItalic(true);
        paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
        System.out.println("Length:" + paragraphs[i].length());
        System.out.println("Paragraph" + i + ": " + paragraphs[i].toString());

        // add the paragraph to the document
        document.add(new Paragraph(paragraphs[i]));
    }

    document.close();
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

License:Apache License

public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws SSErr {

    OutputStream out = null;/*from   w  ww.  jav  a  2 s .c o m*/
    BufferedReader br = null;

    try {

        out = openOrCreateFileWithPathForWrite(pdfFilePath);

        final Document document = new Document();
        final PdfWriter writer = PdfWriter.getInstance(document, out);
        String line;

        document.open();
        writer.setPageEmpty(true);
        document.newPage();
        writer.setPageEmpty(true);

        br = new BufferedReader(new FileReader(new File(textFilePath)));

        while ((line = br.readLine()) != null) {
            document.add(new Paragraph(line));
        }

        document.close();

    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }

        if (br != null) {
            try {
                br.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }
    }
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

License:Apache License

public static void writePDFFromDoc(final String docFilePath, final String pdfFilePath) throws SSErr {

    try {//  www  .j a  va 2s  .  c om
        final Document document = new Document();
        final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath));
        final HWPFDocument word = new HWPFDocument(fs);
        final WordExtractor we = new WordExtractor(word);
        final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath);
        final PdfWriter writer = PdfWriter.getInstance(document, out);
        final Range range = word.getRange();

        document.open();
        writer.setPageEmpty(true);
        document.newPage();
        writer.setPageEmpty(true);

        String[] paragraphs = we.getParagraphText();

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

            org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i);
            // CharacterRun run = pr.getCharacterRun(i);
            // run.setBold(true);
            // run.setCapitalized(true);
            // run.setItalic(true);
            paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
            System.out.println("Length:" + paragraphs[i].length());
            System.out.println("Paragraph" + i + ": " + paragraphs[i].toString());

            // add the paragraph to the document
            document.add(new Paragraph(paragraphs[i]));
        }

        document.close();
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
    }
}