Example usage for com.itextpdf.text.pdf PdfPCell setColspan

List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setColspan.

Prototype

public void setColspan(int colspan) 

Source Link

Document

Setter for property colspan.

Usage

From source file:com.icebreak.p2p.front.controller.trade.download.InvestReceiptPDFCreator.java

/**
 * ???/* ww w. j  a  va  2 s .c o m*/
 * @param tradeId
 * @param detailId
 * @param servletPath
 * @return ?  byte[]
 * @throws Exception
 */
public byte[] creatFileData4Receipt(long tradeId, long detailId, String servletPath) throws Exception {

    FileInputStream fis = null;
    BufferedInputStream buff = null;

    String fileKey = tradeId + "_" + detailId;//System.currentTimeMillis() + "";
    String filePath = servletPath + "/resources/pdf/investReceipt_" + fileKey + ".pdf";
    this.receiptFilePath = filePath;

    File file = new File(filePath);

    if (!file.exists()) {

        String timeLimit = "";
        String interestRate = "";
        String guaranteeName = "";
        String investFlowCode = null;
        String investor = "";
        String investorReal = "";
        String investorCertNo = "";
        String loanner = "";
        String loannerReal = "";
        String loannerCertNo = "";
        String investAmount = "";
        String totalAmountStr = "";
        String effectiveDate = "";
        String expireDate = "";

        Trade trade = tradeService.getByTradeId(tradeId);
        effectiveDate = DateUtil.simpleFormat(trade.getEffectiveDateTime());
        expireDate = DateUtil.simpleFormat(trade.getExpireDateTime());
        LoanDemandDO loanDemand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        guaranteeName = loanDemand.getGuaranteeName();
        if ("W".equals(loanDemand.getTimeLimitUnit()) || "M".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else if ("Y".equals(loanDemand.getTimeLimitUnit())) {
            timeLimit = loanDemand.getTimeLimit() + "";
        } else {
            timeLimit = loanDemand.getTimeLimit() + "";
        }
        interestRate = CommonUtil.mul(loanDemand.getInterestRate(), 100) + "%";
        List<UserInvestEntry> userInvests = tradeService.getEntriesByTradeIdAndDetailId(tradeId, detailId);
        long totalAmount = 0;
        if (userInvests != null && userInvests.size() > 0) {
            UserInvestEntry tradeItem = userInvests.get(0);
            investAmount = MoneyUtil.getFormatAmount(tradeItem.getAmount());
            long investorId = userInvests.get(0).getInvestorId();
            long loannerId = userInvests.get(0).getLoanerId();
            investorCertNo = getCertNoByUserId(investorId);
            loannerCertNo = getCertNoByUserId(loannerId);
            investor = userInvests.get(0).getInvestorUserName();
            investorReal = userInvests.get(0).getInvestorRealName();
            loannerReal = userInvests.get(0).getLoanerRealName();
            loanner = userInvests.get(0).getLoanerUserName();
            totalAmount = userInvests.get(0).getAmount();
        }

        //?
        /*interest = caculateInterest(new Money(totalAmount), loanDemand.getInterestRate(),
        loanDemand.getTimeLimit(), loanDemand.getTimeLimitUnit());*/

        long divisionAmount = 0;
        long profitAmount = 0;
        List<TradeDetail> details = tradeService.getInvestProfitTrade(detailId);
        if (details != null && details.size() > 0) {
            for (TradeDetail detail : details) {
                divisionAmount += detail.getAmount();
                if (detail.getProfitType() > 0) {
                    profitAmount += detail.getAmount();
                }
            }
        }
        totalAmount += divisionAmount;

        TradeFlowCode tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(detailId);
        if (tradeFlow != null) {
            investFlowCode = tradeFlow.getTradeFlowCode();
        }

        String guaranteeLicenseNo = "";
        Map<String, Object> cond = new HashMap<String, Object>();
        cond.put("roleId", 8L);

        cond.put("tradeId", trade.getId());
        List<TradeQueryDetail> det = loanDemandManager.getTradeDetailByConditions(cond);
        if (det != null && det.size() > 0) {
            tradeFlow = tradeService.queryInvestFlowCodesByTradeDetailId(det.get(0).getId());
            if (tradeFlow != null) {
                guaranteeLicenseNo = tradeFlow.getTradeFlowCode();
            }
        }

        LoanDemandDO demand = loanDemandManager.queryLoanDemandByDemandId(trade.getDemandId());
        long divisionTemplateId = demand.getDivisionTemplateId();
        DivisionTemplateLoanDO divisionTemplateLoan = divisionTemplateLoanService
                .getByBaseId(divisionTemplateId);
        List<DivsionRuleRole> investRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getInvestTemplateId()));
        List<DivsionRuleRole> repayRolelist = divisionService
                .getRuleRole(String.valueOf(divisionTemplateLoan.getRepayTemplateId()));
        //??
        double totalAnnualInterest = 0;
        investRolelist.addAll(repayRolelist);
        if (investRolelist != null && investRolelist.size() > 0) {
            for (DivsionRuleRole druleRole : investRolelist) {
                if (DivisionPhaseEnum.INVESET_PHASE.code().equals(druleRole.getPhase())) {
                    if ("11".equals(String.valueOf(druleRole.getRoleId()))) {
                        totalAnnualInterest += druleRole.getRule();
                    }

                }
            }
        }

        totalAmountStr = MoneyUtil.getFormatAmount(totalAmount);
        String divisionAmountStr = MoneyUtil.getFormatAmount(divisionAmount);

        FileOutputStream fos = null;
        Document doc = new Document(PageSize.A4, 20, 20, 140, 20);
        try {
            fos = new FileOutputStream(filePath);
            PdfWriter writer = PdfWriter.getInstance(doc, fos);
            doc.open();
            //   
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            Font titleChinese = new Font(bfChinese, 20, Font.BOLD); // ?     
            Paragraph title = new Paragraph(AppConstantsUtil.getProductName() + "?", titleChinese);// 
            title.setAlignment(Element.ALIGN_CENTER); // 
            title.setLeading(1f);//?//?
            doc.add(title);

            Font fontZH = new Font(bfChinese, 12, Font.NORMAL);
            float[] widths = { 20f, 30f, 25f, 25f };
            PdfPTable table = new PdfPTable(widths);

            table.setSpacingBefore(20f);// ?
            table.setTotalWidth(500);// 
            table.setWidthPercentage(100);//%100
            // table.getDefaultCell().setBorder(0);//
            PdfPCell cell;
            //               cell = new PdfPCell(new Paragraph("?",fontZH));
            //               cell.setColspan(4);
            //               table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(AppConstantsUtil.getPlatformName(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getRepayDivisionWayMsg(), fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(interestRate, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(timeLimit, fontZH));
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(guaranteeName, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Paragraph(StringUtil.nullToEmpty(loanDemand.getGuaranteeLicenseNo()), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph((loanDemand.getLoanAmount() / 100) + "", fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(loanDemand.getLoanPurpose(), fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(investFlowCode, fontZH));
            cell.setColspan(3);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("?", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph("??", fontZH));
            cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
            cell.setColspan(2);

            table.addCell(cell);
            Paragraph iparas = new Paragraph("??" + investor, fontZH);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + investorReal);
            iparas.add(Chunk.NEWLINE);
            iparas.add("??" + StringUtil.subString(investorCertNo, 7, "****"));
            iparas.add(Chunk.NEWLINE);
            iparas.add("?" + effectiveDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("" + expireDate);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + investAmount);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + divisionAmountStr);
            iparas.add(Chunk.NEWLINE);
            iparas.add("()" + totalAmountStr);

            cell = new PdfPCell(iparas);
            cell.setColspan(2);
            cell.setRowspan(8);

            cell.setMinimumHeight(120);
            table.addCell(cell);
            Paragraph paras = new Paragraph("??" + loanner, fontZH);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + loannerReal);
            paras.add(Chunk.NEWLINE);
            paras.add("??" + StringUtil.subString(loannerCertNo, 7, "****"));
            paras.add(Chunk.NEWLINE);
            paras.add("?" + effectiveDate);
            paras.add(Chunk.NEWLINE);
            paras.add("" + expireDate);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add(Chunk.NEWLINE);
            paras.add("()" + totalAmountStr);
            cell = new PdfPCell(paras);
            cell.setColspan(2);
            cell.setRowspan(8);
            table.addCell(cell);
            doc.add(table);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            Paragraph tips = new Paragraph("  ?? ?"
                    + AppConstantsUtil.getPlatformName() + "", fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            doc.add(Chunk.NEWLINE);
            tips = new Paragraph("  ??" + AppConstantsUtil.getPlatformAddress(), fontZH);// 
            tips.setLeading(1f);//?//?
            doc.add(tips);
            //               XMLWorkerHelper.getInstance().parseXHtml(writer, doc,
            //                     new ByteArrayInputStream(str.getBytes()));
            doc.close();
            logger.info("?");

        } catch (Exception e) {
            logger.error("?", e);
            throw new Exception("?:" + e.getMessage());
        } finally {

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

    byte[] data = new byte[1024];

    file = new File(filePath);
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] temp = new byte[1024];
        int size = 0;

        fis = new FileInputStream(file);
        buff = new BufferedInputStream(fis);

        int i = 0;

        while ((size = buff.read(temp)) != -1) {
            out.write(temp, 0, size);
            i += 1;
        }

        data = out.toByteArray();

        buff.close();
        fis.close();
        //file.delete();

        if (i == 0 && size == -1) { //PDF
            file.delete();
        }
    } catch (FileNotFoundException e) {
        logger.error("?", e);
    } catch (IOException e) {
        logger.error("delete file", e);
    } finally {
        if (fis != null) {
            fis.close();
        }
    }

    return data;
}

From source file:com.jslsolucoes.tagria.lib.grid.exporter.impl.PdfExporter.java

License:Apache License

private void title(PdfPTable pdf) {
    PdfPCell cell = new PdfPCell(new Phrase(table.getTitle(), smallBold));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setColspan(table.getHeaders().size());
    pdf.addCell(cell);/*from   w w w. j a va  2s.  c  o  m*/
}

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)/*from  www . ja  v a  2  s  .c o  m*/
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String mpsrID = request.getParameter("MPSR_ID");
    if (null == mpsrID)
        return;

    MPSRProjectInfo basicInfo = MPSRProjectInfo.getInstance(mpsrID);
    MPSRExecutiveSummary exeSummary = MPSRExecutiveSummary.getInstance(mpsrID);
    MPSRStatusSummary statusSummary = MPSRStatusSummary.getInstance(mpsrID);
    MPSRFunctionPerformance funcPerform = MPSRFunctionPerformance.getInstance(mpsrID);
    MPSRCostPerformance costPerform = MPSRCostPerformance.getInstance(mpsrID);
    MPSRSchedulePerformance[] schedulePerform = MPSRSchedulePerformance.getInstance(mpsrID);
    MPSRSafety safety = MPSRSafety.getInstance(mpsrID);
    MPSRAuthorization auth = MPSRAuthorization.getInstance(mpsrID);
    MPSRBudget budget = MPSRBudget.getInstance(mpsrID);
    MPSRCostReport[] costRpt = MPSRCostReport.getInstance(mpsrID);
    MPSRSchedule schedule = MPSRSchedule.getInstance(mpsrID);
    MPSRMilestone[] milestones = MPSRMilestone.getInstance(mpsrID);
    MPSRLPE lpe = MPSRLPE.getInstance(mpsrID);
    MPSRInsidePlantDesign[] ipds = MPSRInsidePlantDesign.getInstance(mpsrID);
    MPSROutsidePlantDesign[] opds = MPSROutsidePlantDesign.getInstance(mpsrID);
    MPSRProcure procure = MPSRProcure.getInstance(mpsrID);
    MPSRApprovedChanges[] approvedChanges = MPSRApprovedChanges.getInstance(mpsrID);
    MPSRPendingChanges[] pendingChanges = MPSRPendingChanges.getInstance(mpsrID);
    MPSRInsidePlantConstruction[] ipcs = MPSRInsidePlantConstruction.getInstance(mpsrID);
    MPSROutsidePlantConstruction[] opcs = MPSROutsidePlantConstruction.getInstance(mpsrID);
    MPSRAppendix[] appendixs = MPSRAppendix.getInstance(mpsrID);
    MPSRAttachment[] attachments = MPSRAttachment.getInstance(mpsrID);

    // response.setContentType("application/pdf");
    // response.setHeader("Content-Disposition",
    // "attachment; filename=\"test.pdf\"");

    Font fontNormal = null;
    Font fontCoverTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD);
    Font fontCoverTableHeader = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
    Font fontCoverTableContent = new Font(FontFamily.HELVETICA, 16);
    Font fontChapterHeader = new Font(FontFamily.HELVETICA, 18, Font.BOLD);
    Font fontSection1Header = new Font(FontFamily.HELVETICA, 16, Font.BOLD);
    Font fontSection2Header = new Font(FontFamily.HELVETICA, 14, Font.BOLD);
    Font fontWork = new Font(FontFamily.HELVETICA, 12, Font.UNDERLINE);

    Font fontTableCaption = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Font fontTableColumnHeader = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    Font fontTableColumnHeaderYellow = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    fontTableColumnHeaderYellow.setColor(BaseColor.YELLOW);
    Font fontTableRowTitle = new Font(FontFamily.HELVETICA, 12, Font.ITALIC);
    Font fontTableCellBold = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    Font fontTableNote = new Font(FontFamily.HELVETICA, 10, Font.ITALIC);
    Font fontImageCaption = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD);

    Font fontPOTableHeader = new Font(FontFamily.HELVETICA, 10, Font.BOLD);
    fontPOTableHeader.setColor(BaseColor.YELLOW);
    Font fontPOTable = new Font(FontFamily.HELVETICA, 9);
    Font fontPOTableSummary = new Font(FontFamily.HELVETICA, 9, Font.BOLD);

    Font fontPageHeader = new Font(FontFamily.HELVETICA, 8);
    Font fontPageFooter = new Font(FontFamily.HELVETICA, 10);

    Phrase[] headerTexts = new Phrase[] { new Phrase("ELECTRIC DELIVERY", fontPageHeader),
            new Phrase("DELIVERY PROJECTS & CONSTRUCTION (DP&C)", fontPageHeader),
            new Phrase("PROJECT MONTHLY REPORT", fontPageHeader) };

    Paragraph paragraph = null;
    PdfPTable table = null;
    PdfPCell cell = null;

    Document document = new Document(DEFAULT_PAGE_SIZE, 36, 36, 9 * 10, 36);
    ByteArrayOutputStream baosOrig = new ByteArrayOutputStream();
    XMLWorkerHelper xmlWorker = XMLWorkerHelper.getInstance();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, baosOrig);
        writer.setStrictImageSequence(true);
        writer.setLinearPageMode();
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines | PdfWriter.FitWindow);

        Image icon = getEmbeddedImage(getServletContext(), "/resource/image/company_logo.png");

        document.open();

        PdfOutline root = writer.getRootOutline();

        // *******************************************************************************************//

        // addOutline(root, writer, MPSRUI.TREE_0);

        for (int i = 0; i < 2; i++) {
            document.add(new Paragraph(" "));
        }

        String[] titles = { " DELIVERY PROJECTS & CONSTRUCTION", "MONTHLY REPORT",
                basicInfo.getReportMonthYear(), basicInfo.getProjectTitle(),
                "PROJECT No. " + basicInfo.getProjectDefinition() };
        int[] spaceingAfters = { 48, 48, 48, 24, 48 };
        for (int i = 0; i < titles.length; i++) {
            paragraph = new Paragraph();
            paragraph.setSpacingAfter(spaceingAfters[i]);
            paragraph.setFont(fontCoverTitle);
            paragraph.setAlignment(Element.ALIGN_CENTER);
            paragraph.add(new Chunk(titles[i]));
            document.add(paragraph);
        }

        addCoverImage(document, MPSRUI.getFilePath(mpsrID, basicInfo.getFileName()));

        document.add(new Paragraph(" "));

        table = new PdfPTable(2);
        table.addCell(new Phrase("Client", fontCoverTableHeader));
        table.addCell(new Phrase(basicInfo.getProjectManager(), fontCoverTableContent));
        table.addCell(new Phrase("Location", fontCoverTableHeader));
        table.addCell(new Phrase(basicInfo.getProjectDirector(), fontCoverTableContent));
        document.add(table);

        // *******************************************************************************************//

        document.resetPageCount();
        document.add(Chunk.NEXTPAGE);
        writer.setPageEvent(new MPSRPageEventHelper(icon, headerTexts, fontPageFooter));

        // *******************************************************************************************//

        PdfOutline outline1 = addOutline(root, writer, MPSRUI.TREE_1);
        addSectionTitle(document, MPSRUI.TREE_1, fontChapterHeader, 0, 0, 12);

        PdfOutline outline2 = addOutline(outline1, writer, "1.1");

        addOutline(outline2, writer, MPSRUI.TREE_1_1_1);
        addSectionTitle(document, MPSRUI.TREE_1_1_1, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_2);
        addSectionTitle(document, MPSRUI.TREE_1_1_2, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_2(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_3);
        addSectionTitle(document, MPSRUI.TREE_1_1_3, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_3(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_1_4);
        addSectionTitle(document, MPSRUI.TREE_1_1_4, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_1_4(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 1.2 Status Summary
        // *******************************************************************************************//

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_2);
        addSectionTitle(document, MPSRUI.TREE_1_2, fontSection1Header, 6, 12, 12);

        paragraph = new Paragraph();
        paragraph.add(basicInfo.getProjectTitle());
        paragraph.setSpacingAfter(4);
        document.add(paragraph);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1 });

        cell = new PdfPCell(
                new Phrase("Project #: " + basicInfo.getProjectDefinition(), fontTableColumnHeader));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
        String[] headers = { "Status", "Approved (Include RnC)", "To Date", "At Completion" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        String[][] cellValues = {
                { "Budget ($M)", statusSummary.getBudgetStatus(),
                        !"".equals(statusSummary.getBudgetApproved()) ? CURRENCY_FORMATTER
                                .format(Double.parseDouble(statusSummary.getBudgetApproved())) : "",
                        !"".equals(statusSummary.getBudgetToDate())
                                ? CURRENCY_FORMATTER.format(Double.parseDouble(statusSummary.getBudgetToDate()))
                                : "",
                        !"".equals(statusSummary.getBudgetAtCompletion()) ? CURRENCY_FORMATTER
                                .format(Double.parseDouble(statusSummary.getBudgetAtCompletion())) : "" },
                { "Schedule - Duration (months)", statusSummary.getScheduleStatus(),
                        statusSummary.getScheduleApproved(), statusSummary.getScheduleToDate(),
                        statusSummary.getScheduleAtCompletion() },
                { "In-Service Date", statusSummary.getInServiceDateStatus(),
                        statusSummary.getInServiceDateApproved(), statusSummary.getInServiceDateToDate(),
                        statusSummary.getInServiceDateAtCompletion() } };
        for (int i = 0; i < cellValues.length; i++) {
            table.addCell(new Phrase(cellValues[i][0]));
            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setBackgroundColor(getBackgroundColor(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            for (int j = 2; j < 5; j++) {
                cell = new PdfPCell(new Phrase(cellValues[i][j]));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.addCell(cell);
            }
        }

        document.add(table);

        // -------------------------------------------------------------------//

        paragraph = new Paragraph("Legend:");
        paragraph.setSpacingAfter(4);
        paragraph.setIndentationLeft(25);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(240);
        table.setLockedWidth(true);
        table.setHorizontalAlignment(Element.ALIGN_LEFT);
        String[] legends = { "On Target", "At Risk", "Off Target" };
        for (String legend : legends) {
            cell = new PdfPCell(new Phrase(legend));
            cell.setBackgroundColor(getBackgroundColor(legend));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            cell.setMinimumHeight(18);
            cell.setPadding(0);
            table.addCell(cell);
        }

        paragraph = new Paragraph();
        paragraph.add(table);
        paragraph.setIndentationLeft(25);
        document.add(paragraph);

        // *******************************************************************************************//
        // 1.2.1 Functional Area Performance Indicators
        // *******************************************************************************************//

        addOutline(outline2, writer, MPSRUI.TREE_1_2_1);
        addSectionTitle(document, MPSRUI.TREE_1_2_1, fontSection2Header, 12, 12, 12);

        table = new PdfPTable(4);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 4, 1, 1, 4 });

        headers = new String[] { "Activities", "Current Status", "Trend",
                "Comments (main performance drives)" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        Image imgArrowUp = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Up.png");
        Image imgArrowDown = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Down.png");
        Image imgArrowEven = getEmbeddedImage(getServletContext(), "/VAADIN/themes/MPSR/img/Arrow_Even.png");
        Image[] images = { imgArrowUp, imgArrowDown, imgArrowEven };
        for (Image image : images) {
            image.scaleToFit(12, 12);
        }

        cellValues = new String[][] {
                { "Project - " + basicInfo.getProjectTitle(), funcPerform.getProjectStatus(),
                        funcPerform.getProjectTrend(), funcPerform.getProjectComment() },
                { "  Target Budget", funcPerform.getTargetBudgetStatus(), funcPerform.getTargetBudgetTrend(),
                        funcPerform.getTargetBudgetComment() },
                { "  Safety", funcPerform.getSafetyStatus(), funcPerform.getSafetyTrend(),
                        funcPerform.getSafetyComment() },
                { "  Licensing & Permitting", funcPerform.getLicensingStatus(), funcPerform.getLicensingTrend(),
                        funcPerform.getLicensingComment() },
                { "  Corporate Properties", funcPerform.getCorporateStatus(), funcPerform.getCorporateTrend(),
                        funcPerform.getCorporateComment() },
                { "  Inside Plant Design & Engineering", funcPerform.getIPDEStatus(),
                        funcPerform.getIPDETrend(), funcPerform.getIPDEComment() },
                { "  Public Outreach", funcPerform.getOutreachStatus(), funcPerform.getOutreachTrend(),
                        funcPerform.getOutreachComment() },
                { "  Procurement", funcPerform.getProcureStatus(), funcPerform.getProcureTrend(),
                        funcPerform.getProcureComment() },
                { "  Construction", funcPerform.getConstructionStatus(), funcPerform.getConstructionTrend(),
                        funcPerform.getConstructionComment() },
                { "  Environmental - Resource Recovery", funcPerform.getEnviromentStatus(),
                        funcPerform.getEnviromentTrend(), funcPerform.getEnviromentComment() },
                { "  Salvage", funcPerform.getSalvageStatus(), funcPerform.getSalvageTrend(),
                        funcPerform.getSalvageComment() },
                { "  Withdrawal", funcPerform.getWithdrawalStatus(), funcPerform.getWithdrawalTrend(),
                        funcPerform.getWithdrawalComment() } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setBackgroundColor(getBackgroundColor(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);

            if ("Up".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowUp);
            } else if ("Down".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowDown);
            } else if ("Even".equals(cellValues[i][2])) {
                cell = new PdfPCell(imgArrowEven);
            } else {
                cell = new PdfPCell();
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][3]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//

        document.setPageSize(DEFAULT_PAGE_SIZE.rotate());
        document.add(Chunk.NEXTPAGE);

        addOutline(outline2, writer, MPSRUI.TREE_1_2_2);
        addSectionTitle(document, MPSRUI.TREE_1_2_2, fontSection2Header, 12, 12, 12);
        addImage(document, MPSRUI.getFilePath(mpsrID, costPerform.getFileName()));

        // *******************************************************************************************//
        // 1.2.3 Schedule Performance
        // *******************************************************************************************//

        document.add(Chunk.NEXTPAGE);

        addOutline(outline2, writer, MPSRUI.TREE_1_2_3);
        addSectionTitle(document, MPSRUI.TREE_1_2_3, fontSection2Header, 12, 12, 12);

        table = new PdfPTable(9);
        table.setTotalWidth(750);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "WBS", "Original Duration", "Remaining Duration", "Baseline Start Date",
                "Baseline Finish Date", "Start Date", "Finish Date", "Total Float", "Status" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < schedulePerform.length; i++) {
            cell = new PdfPCell(new Phrase(schedulePerform[i].getWBS()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getOriginalDuration())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(Double.toString(schedulePerform[i].getRemainingDuration())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedStartDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getPlannedFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getStartDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getTotalFloat()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(schedulePerform[i].getStatus()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        table.setHeaderRows(1);

        document.add(table);

        // *******************************************************************************************//
        // 1.3 Project Change Control
        // *******************************************************************************************//

        document.setPageSize(DEFAULT_PAGE_SIZE);
        document.add(Chunk.NEXTPAGE);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_1_3);
        addSectionTitle(document, MPSRUI.TREE_1_3, fontSection1Header, 6, 12, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_3_1);
        addSectionTitle(document, MPSRUI.TREE_1_3_1, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_1_3_2);
        addSectionTitle(document, MPSRUI.TREE_1_3_2, fontSection2Header, 12, 12, 0);
        addParagraph(document, writer, xmlWorker, exeSummary.getDesc_1_3_2(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 2 Safety
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_2);
        addSectionTitle(document, MPSRUI.TREE_2, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, safety.getDesc1(), fontNormal, 12, 0, 12);

        paragraph = new Paragraph("Table 2.1 Project Safety Summary", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(300);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell = new PdfPCell(new Phrase("Total Work Hours", fontTableColumnHeaderYellow));
        cell.setColspan(3);
        cell.setBackgroundColor(BaseColor.BLUE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);

        headers = new String[] { "Current Period", "Calendar YTD", "Project To Date" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cellValues = new String[][] { { INTEGER_FORMATTER.format(safety.getTotalWorkHoursCurrent()),
                INTEGER_FORMATTER.format(safety.getTotalWorkHoursYTD()),
                INTEGER_FORMATTER.format(safety.getTotalWorkHoursPTD()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][2], fontTableCellBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // -----------------------------------

        table = new PdfPTable(4);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);

        cell = new PdfPCell(new Phrase("Incidents", fontTableColumnHeaderYellow));
        cell.setColspan(4);
        cell.setBackgroundColor(BaseColor.BLUE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);

        cellValues = new String[][] {
                { "OSHA Recordable", INTEGER_FORMATTER.format(safety.getOshaRecordableCurrent()),
                        INTEGER_FORMATTER.format(safety.getOshaRecordableYTD()),
                        INTEGER_FORMATTER.format(safety.getOshaRecordablePTD()) },
                { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid1Current()),
                        INTEGER_FORMATTER.format(safety.getFirstAid1YTD()),
                        INTEGER_FORMATTER.format(safety.getFirstAid1PTD()) },
                { "Near Miss", INTEGER_FORMATTER.format(safety.getNearMissCurrent()),
                        INTEGER_FORMATTER.format(safety.getNearMissYTD()),
                        INTEGER_FORMATTER.format(safety.getNearMissPTD()) },
                { "First Aid", INTEGER_FORMATTER.format(safety.getFirstAid2Current()),
                        INTEGER_FORMATTER.format(safety.getFirstAid2YTD()),
                        INTEGER_FORMATTER.format(safety.getFirstAid2PTD()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0], fontTableRowTitle));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][2]));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][3], fontTableCellBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cell = new PdfPCell(new Phrase("*Note - " + safety.getNote(), fontTableNote));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // *******************************************************************************************//
        // 3 Project Authorization
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_3);
        addSectionTitle(document, MPSRUI.TREE_3, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, auth.getDesc1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(10);
        table.setSpacingBefore(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1, 1, 1, 1, 1, 2, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "$ Millions", "Prior", auth.getHeaderYear0(), auth.getHeaderYear1(),
                auth.getHeaderYear2(), auth.getHeaderYear3(), auth.getHeaderYear4(), auth.getHeaderPostYear(),
                "Total", "Auth" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeader));
            cell.setBackgroundColor(BaseColor.YELLOW);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        cellValues = new String[][] { { "Base", NUMBER_FORMATTER.format(auth.getBasePriorYear()),
                NUMBER_FORMATTER.format(auth.getBaseYear0()), NUMBER_FORMATTER.format(auth.getBaseYear1()),
                NUMBER_FORMATTER.format(auth.getBaseYear2()), NUMBER_FORMATTER.format(auth.getBaseYear3()),
                NUMBER_FORMATTER.format(auth.getBaseYear4()), NUMBER_FORMATTER.format(auth.getBasePostYear()),
                NUMBER_FORMATTER.format(auth.getBaseTotal()), "" },
                { "Risk & Contingency", NUMBER_FORMATTER.format(auth.getRnCPriorYear()),
                        NUMBER_FORMATTER.format(auth.getRnCYear0()),
                        NUMBER_FORMATTER.format(auth.getRnCYear1()),
                        NUMBER_FORMATTER.format(auth.getRnCYear2()),
                        NUMBER_FORMATTER.format(auth.getRnCYear3()),
                        NUMBER_FORMATTER.format(auth.getRnCYear4()),
                        NUMBER_FORMATTER.format(auth.getRnCPostYear()),
                        NUMBER_FORMATTER.format(auth.getRnCTotal()), "" },
                { "Total Project " + auth.getTotalProjectDate(), NUMBER_FORMATTER.format(auth.getPriorTotal()),
                        NUMBER_FORMATTER.format(auth.getYear0Total()),
                        NUMBER_FORMATTER.format(auth.getYear1Total()),
                        NUMBER_FORMATTER.format(auth.getYear2Total()),
                        NUMBER_FORMATTER.format(auth.getYear3Total()),
                        NUMBER_FORMATTER.format(auth.getYear4Total()),
                        NUMBER_FORMATTER.format(auth.getPostTotal()),
                        NUMBER_FORMATTER.format(auth.getTotalTotal()), "" },
                { "Current Request " + auth.getReq0RequestDate(),
                        NUMBER_FORMATTER.format(auth.getReq0PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq0Year0()),
                        NUMBER_FORMATTER.format(auth.getReq0Year1()),
                        NUMBER_FORMATTER.format(auth.getReq0Year2()),
                        NUMBER_FORMATTER.format(auth.getReq0Year3()),
                        NUMBER_FORMATTER.format(auth.getReq0Year4()),
                        NUMBER_FORMATTER.format(auth.getReq0PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq0Total()),
                        NUMBER_FORMATTER.format(auth.getReq0Authorization()) },
                { "Request Date " + auth.getReq1RequestDate(), NUMBER_FORMATTER.format(auth.getReq1PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq1Year0()),
                        NUMBER_FORMATTER.format(auth.getReq1Year1()),
                        NUMBER_FORMATTER.format(auth.getReq1Year2()),
                        NUMBER_FORMATTER.format(auth.getReq1Year3()),
                        NUMBER_FORMATTER.format(auth.getReq1Year4()),
                        NUMBER_FORMATTER.format(auth.getReq1PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq1Total()),
                        NUMBER_FORMATTER.format(auth.getReq1Authorization()) },
                { "Request Date " + auth.getReq2RequestDate(), NUMBER_FORMATTER.format(auth.getReq2PriorYear()),
                        NUMBER_FORMATTER.format(auth.getReq2Year0()),
                        NUMBER_FORMATTER.format(auth.getReq2Year1()),
                        NUMBER_FORMATTER.format(auth.getReq2Year2()),
                        NUMBER_FORMATTER.format(auth.getReq2Year3()),
                        NUMBER_FORMATTER.format(auth.getReq2Year4()),
                        NUMBER_FORMATTER.format(auth.getReq2PostYear()),
                        NUMBER_FORMATTER.format(auth.getReq2Total()),
                        NUMBER_FORMATTER.format(auth.getReq2Authorization()) },
                { "Target Budget", "", "", "", "", "", "", "", auth.getTargetBudget(), "" } };
        for (int i = 0; i < cellValues.length; i++) {

            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            for (int j = 1; j < cellValues[i].length; j++) {
                cell = new PdfPCell(new Phrase(cellValues[i][j]));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                table.addCell(cell);
            }
        }

        document.add(table);

        // *******************************************************************************************//
        // 4 Project Budget
        // *******************************************************************************************//

        addOutline(root, writer, MPSRUI.TREE_4);
        addSectionTitle(document, MPSRUI.TREE_4, fontChapterHeader, 0, 24, 12);
        addParagraph(document, writer, xmlWorker, budget.getDesc1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(2);
        table.setSpacingBefore(6);
        table.setTotalWidth(350);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 5, 2 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cellValues = new String[][] {
                { "Current Approved Budget (Base + RnC)",
                        CURRENCY_FORMATTER.format(budget.getPMBudget()) + "M" },
                { "Approved Phase Funding", CURRENCY_FORMATTER.format(budget.getPMActual()) + "M" },
                { "Expended To Date", CURRENCY_FORMATTER.format(budget.getPMCommitment()) + "M" },
                { "At Completion", CURRENCY_FORMATTER.format(budget.getPMAdditionalCost()) + "M" } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // ----------------------------------------------------
        // table 4.1
        // ----------------------------------------------------

        paragraph = new Paragraph("Table 4.1 Cost Report Summary", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1, 1, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Work Element", "Description", "Estimate", "Actual", "EAC" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < costRpt.length; i++) {
            cell = new PdfPCell(new Phrase(costRpt[i].getWbs()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(costRpt[i].getWbsDesc()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEstimate())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getActual())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(formatNumberString(costRpt[i].getEAC())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 5 Project Schedule
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_5);
        addSectionTitle(document, MPSRUI.TREE_5, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_1);
        addSectionTitle(document, MPSRUI.TREE_5_1, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_1(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_2);
        addSectionTitle(document, MPSRUI.TREE_5_2, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_2(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_3);
        addSectionTitle(document, MPSRUI.TREE_5_3, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_3(), fontNormal, 12, 0, 12);

        addOutline(outline1, writer, MPSRUI.TREE_5_4);
        addSectionTitle(document, MPSRUI.TREE_5_4, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, schedule.getDesc_5_4(), fontNormal, 12, 0, 12);

        // ----------------------------------------------------
        // table 5.1
        // ----------------------------------------------------

        paragraph = new Paragraph("Table 5.1 Planned Scorecard Milestones", fontTableCaption);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setSpacingAfter(6);
        document.add(paragraph);

        table = new PdfPTable(3);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 3, 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Milestone", "Planned Date", "Finish Date" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < milestones.length; i++) {
            cell = new PdfPCell(new Phrase(milestones[i].getMilestone()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(milestones[i].getPlannedDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(milestones[i].getFinishDate()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 6 License & Permitting, and Environmental Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_6);
        addSectionTitle(document, MPSRUI.TREE_6, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_6_1);
        addSectionTitle(document, MPSRUI.TREE_6_1, fontSection1Header, 6, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_1(), fontNormal, 12, 0, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_6_2);
        addSectionTitle(document, MPSRUI.TREE_6_2, fontSection1Header, 6, 12, 12);

        addOutline(outline2, writer, MPSRUI.TREE_6_2_1);
        addSectionTitle(document, MPSRUI.TREE_6_2_1, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_1(), fontNormal, 12, 0, 12);

        addOutline(outline2, writer, MPSRUI.TREE_6_2_2);
        addSectionTitle(document, MPSRUI.TREE_6_2_2, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, lpe.getDesc_6_2_2(), fontNormal, 12, 0, 12);

        // *******************************************************************************************//
        // 7 Engineering Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_7);
        addSectionTitle(document, MPSRUI.TREE_7, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_7_1);
        addSectionTitle(document, MPSRUI.TREE_7_1, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1, 3 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < ipds.length; i++) {
            cell = new PdfPCell(new Phrase(ipds[i].getPackage()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIFR()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIFC()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getIndicator()));
            cell.setBackgroundColor(getBackgroundColor(ipds[i].getIndicator()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(ipds[i].getNote()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);
        }

        document.add(table);

        // -----------------------------------------------------------------------------------//

        addOutline(outline1, writer, MPSRUI.TREE_7_2);
        addSectionTitle(document, MPSRUI.TREE_7_2, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(5);
        table.setTotalWidth(500);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 2, 1, 1, 1, 3 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Package", "IFR", "IFC", "Indicator", "Note" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontTableColumnHeaderYellow));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        for (int i = 0; i < opds.length; i++) {
            cell = new PdfPCell(new Phrase(opds[i].getPackage()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIFR()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIFC()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getIndicator()));
            cell.setBackgroundColor(getBackgroundColor(opds[i].getIndicator()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(opds[i].getNote()));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);
        }

        document.add(table);

        // *******************************************************************************************//
        // 8 Procurement Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_8);
        addSectionTitle(document, MPSRUI.TREE_8, fontChapterHeader, 0, 24, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_1);
        addSectionTitle(document, MPSRUI.TREE_8_1, fontSection1Header, 6, 12, 12);

        table = new PdfPTable(2);
        table.setTotalWidth(300);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cellValues = new String[][] {
                { "Receipted to Date", CURRENCY_FORMATTER.format(procure.getReceiptedToDate()) },
                { "Open Commitments", CURRENCY_FORMATTER.format(procure.getOpenCommitment()) },
                { "Total", CURRENCY_FORMATTER.format(procure.getTotalPurchaseOrder()) } };
        for (int i = 0; i < cellValues.length; i++) {
            cell = new PdfPCell(new Phrase(cellValues[i][0]));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(cellValues[i][1]));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        document.add(table);

        addParagraph(document, writer, xmlWorker, procure.getDesc_8_1_B(), fontNormal, 12, 12, 12);

        outline2 = addOutline(outline1, writer, MPSRUI.TREE_8_2);
        addSectionTitle(document, MPSRUI.TREE_8_2, fontSection1Header, 6, 12, 12);

        // ----------------------------------------------------
        // section 8.2.1
        // ----------------------------------------------------

        addOutline(outline2, writer, MPSRUI.TREE_8_2_1);
        addSectionTitle(document, MPSRUI.TREE_8_2_1, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_1(), fontNormal, 12, 0, 12);

        table = new PdfPTable(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount",
                "This Month Description", "Total Amount" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontPOTableHeader));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        double totalToDate = 0;

        for (int i = 0; i < approvedChanges.length; i++) {
            cell = new PdfPCell(new Phrase(approvedChanges[i].getPurchaseOrder(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(approvedChanges[i].getVendor(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getPreviousAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getThisMonthAmount()),
                    fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(approvedChanges[i].getThisMonthDescription(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(approvedChanges[i].getTotalAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            totalToDate += approvedChanges[i].getTotalAmount();
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 7, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // ----------------------------------------------------
        // section 8.2.2
        // ----------------------------------------------------

        addOutline(outline2, writer, MPSRUI.TREE_8_2_2);
        addSectionTitle(document, MPSRUI.TREE_8_2_2, fontSection2Header, 12, 12, 12);
        addParagraph(document, writer, xmlWorker, procure.getDesc_8_2_2(), fontNormal, 12, 0, 12);

        table = new PdfPTable(6);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 1, 2, 1, 1, 2, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        headers = new String[] { "Purchase Order", "Vendor", "Previous Amount", "This Month Amount",
                "This Month Description", "Total Amount" };
        for (String header : headers) {
            cell = new PdfPCell(new Phrase(header, fontPOTableHeader));
            cell.setBackgroundColor(BaseColor.BLUE);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            table.addCell(cell);
        }

        totalToDate = 0;

        for (int i = 0; i < pendingChanges.length; i++) {
            cell = new PdfPCell(new Phrase(pendingChanges[i].getPurchaseOrder(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(pendingChanges[i].getVendor(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getPreviousAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getThisMonthAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(pendingChanges[i].getThisMonthDescription(), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(CURRENCY_FORMATTER.format(pendingChanges[i].getTotalAmount()), fontPOTable));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setVerticalAlignment(Element.ALIGN_TOP);
            table.addCell(cell);

            totalToDate += pendingChanges[i].getTotalAmount();
        }

        document.add(table);

        table = new PdfPTable(2);
        table.setTotalWidth(550);
        table.setLockedWidth(true);
        table.setWidths(new int[] { 7, 1 });
        table.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell = new PdfPCell(new Phrase("Total To Date", fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(CURRENCY_FORMATTER.format(totalToDate), fontPOTableSummary));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);

        document.add(table);

        // *******************************************************************************************//
        // 9 Construction Status
        // *******************************************************************************************//

        outline1 = addOutline(root, writer, MPSRUI.TREE_9);
        addSectionTitle(document, MPSRUI.TREE_9, fontChapterHeader, 0, 24, 12);

        addOutline(outline1, writer, MPSRUI.TREE_9_1);
        addSectionTitle(document, MPSRUI.TREE_9_1, fontSection1Header, 6, 12, 12);

        for (int i = 0; i < ipcs.length; i++) {
            addParagraph(document, writer, xmlWorker, ipcs[i].getWork(), fontWork, 12, 12, 0);
            addParagraph(document, writer, xmlWorker, ipcs[i].getDescription(), fontNormal, 12, 0, 0);
            addImage(document, MPSRUI.getFilePath(mpsrID, ipcs[i].getFileName()),
                    "Figure " + ipcs[i].getFigure() + " " + ipcs[i].getTitle(), fontImageCaption, 12, 3, 12);
        }

        // -----------------------------------------------------------------------------------------//

        addOutline(outline1, writer, MPSRUI.TREE_9_2);
        addSectionTitle(document, MPSRUI.TREE_9_2, fontSection1Header, 6, 12, 12);

        for (int i = 0; i < opcs.length; i++) {
            addParagraph(document, writer, xmlWorker, opcs[i].getWork(), fontWork, 12, 12, 0);
            addParagraph(document, writer, xmlWorker, opcs[i].getDescription(), fontNormal, 12, 0, 0);
            addImage(document, MPSRUI.getFilePath(mpsrID, opcs[i].getFileName()),
                    "Figure " + opcs[i].getFigure() + " " + opcs[i].getTitle(), fontImageCaption, 12, 3, 12);
        }

        // *******************************************************************************************//
        // Appendix
        // *******************************************************************************************//

        if (appendixs.length > 0) {

            document.add(Chunk.NEXTPAGE);
            outline1 = addOutline(root, writer, MPSRUI.TREE_APPENDIX);

            for (int i = 0; i < appendixs.length; i++) {
                addOutline(outline1, writer,
                        "Appendix " + appendixs[i].getNumber() + "  " + appendixs[i].getTitle());
                addSectionTitle(document,
                        "Appendix " + appendixs[i].getNumber() + "  " + appendixs[i].getTitle(),
                        fontChapterHeader, 0, 12, 12);
                addParagraph(document, writer, xmlWorker, appendixs[i].getDescription(), fontNormal, 12, 0, 0);

                importPages(document, writer, mpsrID, appendixs[i].getFileName());
            }
        }

        // *******************************************************************************************//
        // Attachment
        // *******************************************************************************************//

        if (attachments.length > 0) {

            document.setPageSize(DEFAULT_PAGE_SIZE);
            document.add(Chunk.NEXTPAGE);
            outline1 = addOutline(root, writer, MPSRUI.TREE_ATTACHMENT);

            for (int i = 0; i < attachments.length; i++) {
                addOutline(outline1, writer,
                        "Attachment " + attachments[i].getNumber() + "  " + attachments[i].getTitle());
                addSectionTitle(document,
                        "Attachment " + attachments[i].getNumber() + "  " + attachments[i].getTitle(),
                        fontChapterHeader, 0, 12, 12);
                addParagraph(document, writer, xmlWorker, attachments[i].getDescription(), fontNormal, 12, 0,
                        0);

                importPages(document, writer, mpsrID, attachments[i].getFileName());
            }
        }

        document.close();

        // *******************************************************************************************//

        // retrieve outline
        PdfReader readerOrig = new PdfReader(baosOrig.toByteArray());
        // int origNumberOfPages = readerOrig.getNumberOfPages();
        ColumnText ct = new ColumnText(null);
        ct.addElement(new Paragraph("Table of Contents", fontCoverTitle));
        List<HashMap<String, Object>> bookmarkList = SimpleBookmark.getBookmark(readerOrig);
        fillColumnText(bookmarkList, ct, 18, 0, fontSection2Header);

        // generate TOC after cover page
        ByteArrayOutputStream baosTOC = new ByteArrayOutputStream();
        PdfStamper stamperTOC = new PdfStamper(readerOrig, baosTOC);
        int tocPageEnd = 1;
        while (true) {
            stamperTOC.insertPage(++tocPageEnd, readerOrig.getPageSize(1));

            PdfContentByte underContent = stamperTOC.getUnderContent(tocPageEnd);

            generatePageHeader(document, underContent, icon, headerTexts);

            ct.setCanvas(stamperTOC.getOverContent(tocPageEnd));
            ct.setSimpleColumn(36, 36, 558, 693);
            if (!ColumnText.hasMoreText(ct.go()))
                break;
        }
        stamperTOC.close();

        // change page labels
        PdfPageLabels labels = new PdfPageLabels();
        labels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
        labels.addPageLabel(tocPageEnd + 1, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);

        // add labels
        ByteArrayOutputStream baosFinal = new ByteArrayOutputStream();
        PdfReader readerTOC = new PdfReader(baosTOC.toByteArray());
        // String selectPages = String.format("1-%s,%s-%s", tocPageEnd,
        // tocPageEnd + 1, origNumberOfPages + (tocPageEnd - 1));
        // readerTOC.selectPages(selectPages);
        PdfStamper stamperFinal = new PdfStamper(readerTOC, baosFinal);
        stamperFinal.getWriter().setPageLabels(labels);
        stamperFinal.close();

        // *******************************************************************************************//

        // send final PDF to browser
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        response.setContentLength(baosFinal.size());

        OutputStream os = response.getOutputStream();
        os.write(baosFinal.toByteArray());
        os.flush();
        os.close();

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

}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

private PdfPCell getStringCell(String str, Font font, int border, int align, int colspan) {
    PdfPCell cell = new PdfPCell(new Paragraph(str, font));
    cell.setPaddingTop(5);/*from w  ww. j  a va 2 s .  com*/
    cell.setPaddingBottom(5);
    cell.setBorderWidth(1);
    cell.setBorder(border);
    cell.setHorizontalAlignment(align);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE /*.ALIGN_CENTER*/);
    cell.setColspan(colspan);

    return cell;
}

From source file:com.mim.controllers.HomeCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3//from   ww w . jav  a  2 s  .  c om

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    String area;
    if (lugar.getNombre().contains("linea")) {
        area = "envasado";
    } else if (lugar.getNombre().contains("otro")) {
        area = "Tecate 500";
    } else if (lugar.getNombre().contains("PD")) {
        area = "concretos";
    } else if (lugar.getNombre().contains("planta agua")) {
        area = "cerveceria";
    } else {
        area = "elaboracion";
    }

    PdfPCell areaValor = new PdfPCell(new Paragraph(area));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.controllers.OrdenCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/*  www  .ja  v a  2s.  c o m*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                table.addCell(paramCell);
                table.addCell(valueParamCell);
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.servlet.ReportGen.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3//w w  w . ja v  a2s . c o m

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        PdfPCell paramCell = new PdfPCell();
                        paramCell.setColspan(3);
                        paramCell.addElement(new Paragraph(historial.getParametro()));
                        paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        paramCell.setPaddingLeft(10);
                        paramCell.setPaddingBottom(10);

                        PdfPCell valueParamCell = new PdfPCell();
                        valueParamCell.setColspan(5);
                        valueParamCell.setPaddingLeft(10);
                        valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        valueParamCell.addElement(new Paragraph(historial.getValor()));
                        valueParamCell.setPaddingBottom(10);

                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.myapp.struts.transaction.transactionAction.java

public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SQLException, Exception {
    if (Constants.isSessionActive(request)) {
        transactionForm transactionForm = (transactionForm) form;
        try {/*from   ww  w .j a  v a  2 s.c om*/
            Date utilDate = new Date();
            java.sql.Date date = new java.sql.Date(utilDate.getTime());
            Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD,
                    BaseColor.BLACK);
            Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12,
                    Font.BOLD | Font.UNDERLINE, BaseColor.BLACK);
            Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD);

            Document document = new Document();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);
            document.open();

            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs.

            Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont);
            para1.setAlignment(Element.ALIGN_CENTER);
            document.add(para1);

            para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont);
            para1.setAlignment(Element.ALIGN_CENTER);
            document.add(para1);

            para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont);
            para1.setAlignment(Element.ALIGN_LEFT);
            document.add(para1);

            para1 = new Paragraph(
                    transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont);
            para1.setAlignment(Element.ALIGN_LEFT);
            document.add(para1);
            Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + "");
            if (obj != null) {
                para1 = new Paragraph("Group : " + obj.getGroupname(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont);
                para1.setAlignment(Element.ALIGN_LEFT);
                document.add(para1);

                para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont);
                para1.setAlignment(Element.ALIGN_RIGHT);
                document.add(para1);

                if (transactionForm.getStatus().equalsIgnoreCase("Settled")) {
                    para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont);
                    para1.setAlignment(Element.ALIGN_RIGHT);
                    document.add(para1);
                }

                String dateStr = sdf.format(date);
                para1 = new Paragraph("DATED:" + dateStr, font);
                para1.setAlignment(Element.ALIGN_RIGHT);
                document.add(para1);

                // add a couple of blank lines
                document.add(Chunk.NEWLINE);

                if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) {
                    PdfPTable table2 = new PdfPTable(7);
                    float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f };

                    table2.setWidthPercentage(100);
                    table2.setWidths(columnWidths);

                    para1 = new Paragraph("Sl No.", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    PdfPCell cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Term", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Receipt No.", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Receipt Date", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Payment Mode", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Remarks", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    para1 = new Paragraph("Paid Amount", font);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    cell = new PdfPCell(para1);
                    table2.addCell(cell);

                    int x = 1;
                    double total = 0;
                    //Iterator it = hmPayments.entrySet().iterator();
                    //while (it.hasNext()) {
                    if (hmPayments.size() > 0) {
                        for (int i = 1; i <= obj.getNoofinstallment(); i++) {
                            //float f = columnWidths[i];
                            Payment f1 = (Payment) hmPayments.get(i + "");
                            //}
                            //Map.Entry pairs = (Map.Entry) it.next();
                            //Payment f1 = (Payment) pairs.getValue();
                            String term = i + "";

                            para1 = new Paragraph(Integer.toString(x), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);
                            x++;

                            para1 = new Paragraph(term, font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getPaymentid() + "", font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(sdf.format(f1.getPaiddate()), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            para1 = new Paragraph(f1.getRemarks(), font);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);

                            //para1 = new Paragraph(f1.getPaidamount() + "", boldfont);
                            para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont);
                            para1.setAlignment(Element.ALIGN_CENTER);
                            cell = new PdfPCell(para1);
                            table2.addCell(cell);
                            total = total + obj.getInstallmentamount();
                            if (hmPayments.size() == i) {
                                break;
                            }
                        }

                        para1 = new Paragraph("Total", boldfont);
                        para1.setAlignment(Element.ALIGN_LEFT);
                        cell = new PdfPCell(para1);
                        cell.setColspan(6);
                        table2.addCell(cell);

                        //String numberStr = String.format("%.2f", total + "");
                        para1 = new Paragraph(total + "", boldfont);
                        para1.setAlignment(Element.ALIGN_CENTER);
                        cell = new PdfPCell(para1);
                        //cell.setColspan(7);
                        table2.addCell(cell);

                        table2.setHorizontalAlignment(Element.ALIGN_LEFT);
                        document.add(table2);
                    } else {
                        para1 = new Paragraph("NO PAYMENTS FOUND", boldfont);
                        para1.setAlignment(Element.ALIGN_CENTER);
                        document.add(para1);
                    }

                } else {
                    para1 = new Paragraph("NO RECORDS FOUND", boldfont);
                    para1.setAlignment(Element.ALIGN_CENTER);
                    document.add(para1);
                }
                document.add(Chunk.NEWLINE);

                //document.close();
                //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf"));
                document.close();
                ServletOutputStream outputStream = response.getOutputStream();
                baos.writeTo(outputStream);
                response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\"");
                response.setContentType("application/pdf");
                outputStream.flush();
                outputStream.close();
                return mapping.findForward("display");
            } else {
                para1 = new Paragraph("NO RECORDS FOUND", boldfont);
                para1.setAlignment(Element.ALIGN_CENTER);
                document.add(para1);
                document.close();
                ServletOutputStream outputStream = response.getOutputStream();
                baos.writeTo(outputStream);
                response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\"");
                response.setContentType("application/pdf");
                outputStream.flush();
                outputStream.close();
                return mapping.findForward("display");
            }
        } catch (DocumentException i) {
            System.out.println(i);
            return mapping.findForward("fail");
        } catch (IOException i) {
            System.out.println(i);
            return mapping.findForward("fail");
        }
    } else {
        return mapping.findForward("exp");
    }
}

From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java

License:Apache License

private void createHead(PdfPTable table, VisionVO vision) throws Exception {
    PdfPCell cell = new PdfPCell();
    cell.addElement(new Phrase(vision.getTitle() + "\n" + BscReportSupportUtils.parse2(vision.getScore()),
            this.getFont(vision.getFontColor(), true)));
    this.setCellBackgroundColor(cell, vision.getBgColor());
    cell.setColspan(MAX_COLSPAN);
    table.addCell(cell);/*from   w  ww  .  j a v a  2s.co m*/

    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getPerspectiveTitle(),
            this.getFont(BscReportPropertyUtils.getFontColor(), true)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    table.addCell(cell);

    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getObjectiveTitle(),
            this.getFont(BscReportPropertyUtils.getFontColor(), true)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    table.addCell(cell);

    cell = new PdfPCell();
    cell.addElement(new Phrase(BscReportPropertyUtils.getKpiTitle(),
            this.getFont(BscReportPropertyUtils.getFontColor(), true)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    table.addCell(cell);
}

From source file:com.netsteadfast.greenstep.bsc.command.KpiReportPdfCommand.java

License:Apache License

private void createDateRange(PdfPTable table, VisionVO vision, Context context, int maxRows) throws Exception {
    String frequency = (String) context.get("frequency");
    String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim();
    String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim();
    String startDate = StringUtils.defaultString((String) context.get("startDate")).trim();
    String endDate = StringUtils.defaultString((String) context.get("endDate")).trim();
    String date1 = startDate;//from w w w .j av  a  2 s.co m
    String date2 = endDate;
    if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency)
            || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) {
        date1 = startYearDate + "/01/01";
        date2 = endYearDate + "/12/" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12);
    }
    Map<String, Object> headContentMap = new HashMap<String, Object>();
    this.fillHeadContent(context, headContentMap);
    String content = "Frequency: " + BscMeasureDataFrequency.getFrequencyMap(false).get(frequency)
            + " Date range: " + date1 + " ~ " + date2 + "\n"
            + StringUtils.defaultString((String) headContentMap.get("headContent"));

    PdfPCell cell = null;

    cell = new PdfPCell();
    cell.addElement(new Phrase(content, this.getFont(BscReportPropertyUtils.getFontColor(), false)));
    this.setCellBackgroundColor(cell, BscReportPropertyUtils.getBackgroundColor());
    cell.setColspan(maxRows);
    table.addCell(cell);

    for (PerspectiveVO perspective : vision.getPerspectives()) {
        for (ObjectiveVO objective : perspective.getObjectives()) {
            for (KpiVO kpi : objective.getKpis()) {
                cell = new PdfPCell();
                cell.addElement(new Phrase(kpi.getName(), this.getFont(kpi.getFontColor(), false)));
                this.setCellBackgroundColor(cell, kpi.getBgColor());
                cell.setColspan(4);
                cell.setRowspan(2);
                table.addCell(cell);

                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    cell = new PdfPCell();
                    cell.addElement(
                            new Phrase(dateScore.getDate(), this.getFont(dateScore.getFontColor(), false)));
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }
                for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
                    Image image = Image
                            .getInstance(BscReportSupportUtils.getByteIcon(kpi, dateScore.getScore()));
                    image.setWidthPercentage(20f);
                    cell = new PdfPCell();
                    cell.addElement(new Phrase(BscReportSupportUtils.parse2(dateScore.getScore()),
                            this.getFont(dateScore.getFontColor(), false)));
                    cell.addElement(image);
                    this.setCellBackgroundColor(cell, dateScore.getBgColor());
                    table.addCell(cell);
                }

            }
        }
    }

}