Example usage for com.itextpdf.text.pdf PdfStamper getOverContent

List of usage examples for com.itextpdf.text.pdf PdfStamper getOverContent

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfStamper getOverContent.

Prototype

public PdfContentByte getOverContent(final int pageNum) 

Source Link

Document

Gets a PdfContentByte to write over the page of the original document.

Usage

From source file:com.mui.certificate.core.HalalCertification.java

License:Apache License

@Override
public void exportCertificate(Certificate cert, File outputPdf) throws Exception {
    ByteMatrix matrix = generateQRCode(cert.getCertificateURL().toString());
    int scale = sMagicNumber / matrix.getWidth();
    BufferedImage buffImage = convertToImage(matrix, scale);
    File tempOutput = new File("tmp-qrcode.png");
    ImageIO.write(buffImage, "png", tempOutput);
    Image itImage = Image.getInstance(tempOutput.getCanonicalPath());
    PdfReader reader = new PdfReader("doc/template_certificate_halal.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdf));
    int centerY = 715;
    int centerX = 135;
    itImage.setAbsolutePosition(centerX - (itImage.getWidth() / 2), centerY - (itImage.getHeight() / 2));
    stamper.getOverContent(1).addImage(itImage);
    AcroFields form1 = stamper.getAcroFields();
    String nameHeader = "topmostSubform[0].Page1[0].";
    form1.setField(nameHeader + "no_certificate[0]", cert.getCertificateNumber().toString());
    form1.setField(nameHeader + "name_product[0]", cert.getProductName());
    form1.setField(nameHeader + "type_product[0]", cert.getProductType());
    form1.setField(nameHeader + "name_company[0]", cert.getCompanyName());
    form1.setField(nameHeader + "company_address[0]", cert.getCompanyAddress());
    Calendar cal = Calendar.getInstance(new Locale("id"));
    Locale idLocale = new Locale("id");
    cal.setTime(cert.getIssuedDate());/*w  w w.jav a 2  s.  c  om*/
    form1.setField(nameHeader + "issued_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal));
    cal.setTime(cert.getValidDate());
    form1.setField(nameHeader + "expired_date[0]", String.format(idLocale, "%1$tA, %1$te %1$tB %1$tY", cal));
    stamper.setFormFlattening(true);
    stamper.close();
    tempOutput.delete();
}

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

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)// ww w.ja v a 2  s.  co  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("PMA - 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/pma.bmp");

        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 = { "PMA 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.qmetric.document.watermark.strategy.ImageWatermarkStrategy.java

License:Open Source License

@Override
public void apply(final PdfReader reader, final PdfStamper outputPdf) throws Exception {
    final Image image = pdfWatermarkFactory.createImage(reader);

    for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) {
        outputPdf.getOverContent(pageNumber).addImage(image);
    }/*from w ww.j  av  a2 s .c om*/
}

From source file:com.qmetric.document.watermark.strategy.MessageWatermarkStrategy.java

License:Open Source License

@Override
public void apply(final PdfReader reader, final PdfStamper outputPdf) throws Exception {
    for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) {
        final PdfContentByte overContent = outputPdf.getOverContent(pageNumber);

        applyTextTransparency(overContent);

        addTextToPage(reader.getPageSizeWithRotation(pageNumber), overContent, watermarkText);

        overContent.restoreState();//from  ww w.  j a v  a  2  s.  c o  m
    }
}

From source file:controller.DownloadCVServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request/*from w  w  w  .j  av  a 2  s . co  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //protect servlet
    HttpSession session = request.getSession();
    Admin loggedInAdmin = (Admin) session.getAttribute("admin");

    //check if admin is logged in
    if (loggedInAdmin == null) {
        response.sendRedirect("login.jsp");
        return;
    }

    String[] appIDs = request.getParameterValues("download");

    ServletOutputStream sOut = response.getOutputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);

    //prepare fonts
    Font font = FontFactory.getFont("Arial", 10);

    for (String appIDStr : appIDs) {
        int appID = Integer.parseInt(appIDStr);
        Application application = ApplicationDAO.retrieveByAppID(appID);
        Job job = JobDAO.retrieveJobById(application.getJobID());

        ZipEntry entry = new ZipEntry(application.getFullname() + "_CV.pdf");
        zos.putNextEntry(entry);

        String path = System.getenv("OPENSHIFT_DATA_DIR");

        if (path == null) {
            path = getServletContext().getRealPath("/templates/Personal_Particulars_Form.pdf");
        } else {
            path += "Personal_Particulars_Form.pdf";
        }

        try {
            //Prepare PdfStamper
            PdfReader reader = new PdfReader(path);
            PdfStamper stamper = new PdfStamper(reader, zos);
            stamper.setRotateContents(false);
            stamper.getWriter().setCloseStream(false);

            //Get first page
            PdfContentByte canvas = stamper.getOverContent(1);

            //Application ID
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getAppID() + "", font), 110, 555, 0);

            //Date Applied
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getDateApplied(), font), 110, 526, 0);

            //Position Applied
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(job.getPostingTitle(), font), 36,
                    442, 0);

            //Job ID
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getJobID() + "", font), 405, 442, 0);

            //Name
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getFullname(), font),
                    36, 350, 0);

            //Street
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getBlkStreetUnit(), font), 36, 305, 0);

            //Postal Code
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getPostalCode(), font), 377, 305, 0);

            //Nationality
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getNricType(), font),
                    36, 260, 0);

            //NRIC
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getNric(), font), 289,
                    260, 0);

            //DOB
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getDob(), font), 36,
                    215, 0);

            //Gender
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getGender(), font),
                    379, 215, 0);

            //Contact Number
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(application.getContactNo(), font),
                    36, 170, 0);

            //Email Address
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase(application.getEmailAddress(), font), 36, 125, 0);

            //Declaration
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("X", font), 50, 80, 0);

            //Generated on
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
            dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Singapore"));
            Date date = new Date();
            String today = dateFormat.format(date);
            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(today, font), 437, 15, 0);

            stamper.close();
            reader.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }

    zos.close();
    response.setContentType("application/zip");
    response.addHeader("Content-Disposition", "attachment; filename=CVs.zip");

    sOut.write(baos.toByteArray());
    sOut.close();
}

From source file:de.drippinger.cytricHelper.CytricHelper.java

License:Open Source License

public void manipulatePdf(String sourceFile, String expenseID) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(sourceFile);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(getOutputName(sourceFile)));

    PdfContentByte over = stamper.getOverContent(1);
    Phrase p = new Phrase(String.format("Cytric ID: %s", expenseID));
    ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, 500, reader.getPageSize(1).getHeight() - 30, 0);
    over.saveState();// w  w  w.jav  a 2  s .  co  m

    stamper.close();
    reader.close();
}

From source file:de.earthdawn.ECEPdfExporter.java

License:Open Source License

public void exportRedbrickExtended(EDCHARACTER edCharakter, File outFile)
        throws DocumentException, IOException {
    PdfReader reader = new PdfReader(
            new FileInputStream(new File("./templates/ed3_extended_character_sheet.pdf")));
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile));
    acroFields = stamper.getAcroFields();
    CharacterContainer character = new CharacterContainer(edCharakter);
    // +++ DEBUG +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
    //Set<String> fieldNames = acroFields.getFields().keySet();
    //fieldNames = new TreeSet<String>(fieldNames);
    //for( String fieldName : fieldNames ) {
    //   acroFields.setField( fieldName, fieldName );
    //   System.out.println( fieldName );
    //}/*  www  .  j  a  v a 2s  .  c o m*/
    // +++ ~DEBUG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    exportCommonFields(character, 16, 55);
    setButtons(character.getWound().getNormal(), "WoundPenalties.", 9);
    acroFields.setField("Shield", "none");
    acroFields.setField("ShieldDeflectionBonus", "na");

    // Charakter Potrait-Bild einfgen
    List<Base64BinaryType> potraits = character.getPortrait();
    if (!potraits.isEmpty()) {
        Image image = Image.getInstance(potraits.get(0).getValue());
        image.setAbsolutePosition(35f, 517f);
        image.scaleAbsolute(165f, 200f);
        PdfContentByte overContent = stamper.getOverContent(2);
        overContent.addImage(image);
    }

    int armor_max = 0;
    int shield_max = 0;
    for (ARMORType armor : character.getProtection().getARMOROrSHIELD()) {
        if (!armor.getUsed().equals(YesnoType.YES))
            continue;
        if (armor.getClass().getSimpleName().equals("ARMORType")) {
            if (armor.getPhysicalarmor() > armor_max) {
                armor_max = armor.getPhysicalarmor();
                acroFields.setField("Armor", armor.getName());
            }
        } else if (armor.getClass().getSimpleName().equals("SHIELDType")) {
            SHIELDType shield = (SHIELDType) armor;
            if (shield.getPhysicalarmor() > shield_max) {
                shield_max = armor.getPhysicalarmor();
                acroFields.setField("Shield", shield.getName());
                acroFields.setField("ShieldDeflectionBonus",
                        shield.getPhysicaldeflectionbonus() + "/" + shield.getMysticdeflectionbonus());
            }
        } else {
            System.err.println("Unbekannte Rstungstyp: " + armor.getClass().getSimpleName());
        }
    }
    acroFields.setField("Discipline", concat(" / ", character.getDisciplineNames()));
    acroFields.setField("Circle", concat(" / ", character.getDisciplineCircles()));
    int counterKarmaritual = 0;
    for (String karmaritual : character.getAllKarmaritual()) {
        for (String description : wrapString(50, karmaritual)) {
            if (counterKarmaritual > 11) {
                System.err.println("Karmaritual description is to long. Only first 12 lines were displayed.");
                break;
            }
            acroFields.setField("KarmaRitual." + counterKarmaritual, description);
            counterKarmaritual++;
        }
    }
    List<DISCIPLINEType> disciplines = character.getDisciplines();
    if (!disciplines.isEmpty()) {
        DISCIPLINEType discipline1 = disciplines.get(0);
        int counter = 0;
        List<TALENTType> disziplinetalents = discipline1.getDISZIPLINETALENT();
        Collections.sort(disziplinetalents, new TalentComparator());
        HashMap<String, ATTRIBUTEType> attributes = character.getAttributes();
        for (TALENTType talent : disziplinetalents) {
            if ((talent.getCircle() > 4) && (counter < 9))
                counter = 9;
            if ((talent.getCircle() > 8) && (counter < 13))
                counter = 13;
            if ((talent.getCircle() > 12) && (counter < 17))
                counter = 17;
            setTalent(counter, talent, attributes);
            counter++;
        }
        List<TALENTType> optionaltalents = discipline1.getOPTIONALTALENT();
        Collections.sort(optionaltalents, new TalentComparator());
        counter = 0;
        for (TALENTType talent : optionaltalents) {
            if ((talent.getCircle() > 4) && (counter < 7))
                counter = 7;
            if ((talent.getCircle() > 8) && (counter < 13))
                counter = 13;
            setTalent(20 + counter, talent, attributes);
            // Optionale Talente knnen Karma erfordern
            if (talent.getKarma().equals(YesnoType.YES)) {
                acroFields.setField("KarmaRequired." + counter, "Yes");
            } else {
                acroFields.setField("KarmaRequired." + counter, "");
            }
            counter++;
        }
    }
    if (disciplines.size() > 1) {
        DISCIPLINEType discipline2 = disciplines.get(1);
        int counter = 36;
        List<TALENTType> disziplinetalents = discipline2.getDISZIPLINETALENT();
        Collections.sort(disziplinetalents, new TalentComparator());
        HashMap<String, ATTRIBUTEType> attributes = character.getAttributes();
        for (TALENTType talent : disziplinetalents) {
            if ((talent.getCircle() > 4) && (counter < 44))
                counter = 44;
            if ((talent.getCircle() > 8) && (counter < 48))
                counter = 48;
            if ((talent.getCircle() > 12) && (counter < 52))
                counter = 52;
            setTalent(counter, talent, attributes);
            counter++;
        }
        List<TALENTType> optionaltalents = discipline2.getOPTIONALTALENT();
        Collections.sort(optionaltalents, new TalentComparator());
        counter = 16;
        for (TALENTType talent : optionaltalents) {
            if ((talent.getCircle() > 4) && (counter < 22))
                counter = 22;
            if ((talent.getCircle() > 8) && (counter < 26))
                counter = 26;
            setTalent(39 + counter, talent, attributes);
            // Optionale Talente knnen Karma erfordern
            if (talent.getKarma().equals(YesnoType.YES)) {
                acroFields.setField("KarmaRequired." + counter, "Yes");
            } else {
                acroFields.setField("KarmaRequired." + counter, "");
            }
            counter++;
        }
    }
    List<WEAPONType> weapons = character.getWeapons();
    if (weapons != null) {
        int counter_melee = 0;
        int counter_range = 0;
        for (WEAPONType weapon : weapons) {
            if (weapon.getShortrange() > 0) {
                acroFields.setField("RangedWeapon." + counter_range, weapon.getName());
                acroFields.setField("RangedWeaponDmgStep." + counter_range,
                        String.valueOf(weapon.getDamagestep()));
                acroFields.setField("RangedWeapon Size." + counter_range, String.valueOf(weapon.getSize()));
                acroFields.setField("RangedWeaponTimesForged." + counter_range,
                        String.valueOf(weapon.getTimesforged()));
                acroFields.setField("WeaponShortRange." + counter_range,
                        String.valueOf(weapon.getShortrange()));
                acroFields.setField("Weapon Long Range." + counter_range,
                        String.valueOf(weapon.getLongrange()));
                counter_range++;
            } else {
                acroFields.setField("Weapon." + counter_melee, weapon.getName());
                acroFields.setField("WeaponDmgStep." + counter_melee, String.valueOf(weapon.getDamagestep()));
                acroFields.setField("Weapon Size." + counter_melee, String.valueOf(weapon.getSize()));
                acroFields.setField("WeaponTimesForged." + counter_melee,
                        String.valueOf(weapon.getTimesforged()));
                counter_melee++;
            }
        }
    }

    List<List<SPELLType>> spellslist = new ArrayList<List<SPELLType>>();
    spellslist.add(character.getOpenSpellList());
    for (DISCIPLINEType discipline : disciplines)
        spellslist.add(discipline.getSPELL());
    setSpellRedbrick(spellslist);

    counterEquipment = 0;
    for (ITEMType item : listArmorAndWeapon(character))
        addEquipment(item.getName(), item.getWeight());
    for (ITEMType item : character.getItems())
        addEquipment(item.getName(), item.getWeight());
    for (MAGICITEMType item : character.getMagicItem()) {
        StringBuffer text = new StringBuffer(item.getName());
        text.append(" (");
        text.append(item.getBlooddamage());
        text.append("/");
        text.append(item.getDepatterningrate());
        text.append("/");
        text.append(item.getEnchantingdifficultynumber());
        text.append(")");
        addEquipment(text.toString(), item.getWeight());
    }

    int copperPieces = 0;
    int goldPieces = 0;
    int silverPieces = 0;
    for (COINSType coins : character.getAllCoins()) {
        addEquipment(coinsToString(coins), coins.getWeight());
        copperPieces += coins.getCopper();
        silverPieces += coins.getSilver();
        goldPieces += coins.getGold();
    }
    acroFields.setField("CopperPieces", String.valueOf(copperPieces));
    acroFields.setField("SilverPieces", String.valueOf(silverPieces));
    acroFields.setField("GoldPieces", String.valueOf(goldPieces));

    int counterDescription = 0;
    for (String description : wrapString(60, character.getDESCRIPTION())) {
        acroFields.setField("ShortDescription." + counterDescription, description);
        counterDescription++;
        if (counterDescription > 7) {
            System.err.println("Character description to long. Only first 8 lines were displayed.");
            break;
        }
    }

    int counterMagicItem = 0;
    int counterThreadItem = 0;
    for (THREADITEMType item : character.getThreadItem()) {
        int weaventhreadrank = item.getWeaventhreadrank();
        acroFields.setField("MagicalTreasureName." + counterMagicItem, item.getName());
        acroFields.setField("MagicalTreasureSpellDefense." + counterMagicItem,
                String.valueOf(item.getSpelldefense()));
        acroFields.setField("MagicalTreasureMaxThreads." + counterMagicItem,
                String.valueOf(item.getMaxthreads()));
        int counterMagicItemDescription = 0;
        for (String description : wrapString(55, item.getDESCRIPTION())) {
            acroFields.setField("MagicalTreasureDesc." + counterMagicItemDescription + "." + counterMagicItem,
                    description);
            counterMagicItemDescription++;
            if (counterMagicItemDescription > 2) {
                System.err.println("MagicItem description to long. Only first 3 lines were displayed.");
                break;
            }
        }
        int counterMagicItemRank = 0;
        for (THREADRANKType rank : item.getTHREADRANK()) {
            acroFields.setField("MagicalTreasureRank." + counterMagicItemRank + "." + counterMagicItem,
                    String.valueOf(counterMagicItemRank + 1));
            acroFields.setField("MagicalTreasureLPCost." + counterMagicItemRank + "." + counterMagicItem,
                    String.valueOf(rank.getLpcost()));
            acroFields.setField("MagicalTreasureKeyKnowledge." + counterMagicItemRank + "." + counterMagicItem,
                    rank.getKeyknowledge());
            acroFields.setField("MagicalTreasureEffect." + counterMagicItemRank + "." + counterMagicItem,
                    rank.getEffect());
            if (counterMagicItemRank < weaventhreadrank) {
                acroFields.setField("ThreadMagicTarget." + counterThreadItem, item.getName());
                acroFields.setField("ThreadMagicEffect." + counterThreadItem, rank.getEffect());
                acroFields.setField("ThreadMagicLPCost." + counterThreadItem, String.valueOf(rank.getLpcost()));
                acroFields.setField("ThreadMagicRank." + counterThreadItem,
                        String.valueOf(counterMagicItemRank + 1));
                counterThreadItem++;
            }
            counterMagicItemRank++;
        }
        counterMagicItem++;
    }

    int counterBloodCharms = 0;
    for (MAGICITEMType item : character.getBloodCharmItem()) {
        acroFields.setField("BloodMagicType." + counterBloodCharms, item.getName());
        if (item.getUsed().equals(YesnoType.YES)) {
            acroFields.setField("BloodMagicDamage." + counterBloodCharms,
                    String.valueOf(item.getBlooddamage()));
        } else {
            acroFields.setField("BloodMagicDamage." + counterBloodCharms, "(" + item.getBlooddamage() + ")");
        }
        acroFields.setField("BloodMagicDR." + counterBloodCharms, String.valueOf(item.getDepatterningrate()));
        acroFields.setField("BloodMagicEffect." + counterBloodCharms, item.getEffect());
        counterBloodCharms++;
    }

    stamper.close();
}

From source file:de.earthdawn.ECEPdfExporter.java

License:Open Source License

public void exportAjfelMordom(EDCHARACTER edCharakter, int pdftype, File outFile)
        throws DocumentException, IOException {
    File pdfinputfile;//from  w  w  w  .j  a va2s  .  c  om
    if (pdftype == 1)
        pdfinputfile = new File("templates/ed3_character_sheet_Ajfel+Mordom_pl.pdf");
    else
        pdfinputfile = new File("templates/ed3_character_sheet_Ajfel+Mordom.pdf");
    PdfReader reader = new PdfReader(new FileInputStream(pdfinputfile));
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outFile));
    acroFields = stamper.getAcroFields();
    CharacterContainer character = new CharacterContainer(edCharakter);
    // +++ DEBUG +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
    //Set<String> fieldNames = acroFields.getFields().keySet();
    //fieldNames = new TreeSet<String>(fieldNames);
    //for( String fieldName : fieldNames ) {
    //   acroFields.setField( fieldName, fieldName );
    //}
    // +++ ~DEBUG ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    exportCommonFields(character, 16, 40);
    setButtons(character.getWound().getNormal(), "Wound.", 7);
    acroFields.setField("BloodWound", "D:" + character.getHealth().getBlooddamage() + ", W:"
            + character.getWound().getBlood() + ", DR:" + character.getHealth().getDepatterningrate());

    // Charakter Potrait-Bild einfgen
    List<Base64BinaryType> potraits = character.getPortrait();
    if (!potraits.isEmpty()) {
        Image image = Image.getInstance(potraits.get(0).getValue());
        if (image != null) {
            image.setAbsolutePosition(18.5f, 702.5f);
            image.scaleAbsolute(91.5f, 93f);
            PdfContentByte overContent = stamper.getOverContent(2);
            if (overContent != null)
                overContent.addImage(image);
            else
                errorout.println("Unable to insert character image.");
        }
    }

    int counterArmor = 0;
    for (ARMORType armor : character.getProtection().getARMOROrSHIELD()) {
        if (!armor.getUsed().equals(YesnoType.YES))
            continue;
        int physicalarmor = armor.getPhysicalarmor();
        int mysticarmor = armor.getMysticarmor();
        int penalty = armor.getPenalty();
        if ((physicalarmor == 0) && (mysticarmor == 0) && (penalty == 0))
            continue;
        acroFields.setField("ArmorName." + counterArmor, armor.getName());
        acroFields.setField("ArmorPhysical." + counterArmor, String.valueOf(physicalarmor));
        acroFields.setField("ArmorMystic." + counterArmor, String.valueOf(mysticarmor));
        acroFields.setField("ArmorPenalty." + counterArmor, String.valueOf(penalty));
        counterArmor++;
    }

    acroFields.setField("Discipline", concat(" / ", character.getDisciplineNames()));
    acroFields.setField("Circle", concat(" / ", character.getDisciplineCircles()));
    acroFields.setField("HalfMagic", character.getAllHalfMagic());

    List<WEAPONType> weapons = character.getWeapons();
    if (weapons != null) {
        int counter = 0;
        ATTRIBUTEType str = character.getAttributes().get("STR");
        for (WEAPONType weapon : weapons) {
            acroFields.setField("Weapon." + counter, weapon.getName());
            acroFields.setField("WeaponStrength." + counter, String.valueOf(str.getStep()));
            acroFields.setField("WeaponDamage.0." + counter, String.valueOf(weapon.getDamagestep()));
            acroFields.setField("WeaponDamage.1." + counter,
                    String.valueOf(weapon.getDamagestep() + str.getStep()));
            acroFields.setField("WeaponRange." + counter,
                    weapon.getShortrange() + " / " + weapon.getLongrange());
            counter++;
        }
    }

    counterEquipment = 0;
    for (ITEMType item : listArmorAndWeapon(character))
        addEquipment(item.getName(), item.getWeight());
    for (ITEMType item : character.getItems())
        addEquipment(item.getName(), item.getWeight());
    for (MAGICITEMType item : character.getMagicItem()) {
        StringBuffer text = new StringBuffer(item.getName());
        text.append(" (");
        text.append(item.getBlooddamage());
        text.append("/");
        text.append(item.getDepatterningrate());
        text.append("/");
        text.append(item.getEnchantingdifficultynumber());
        text.append(")");
        addEquipment(text.toString(), item.getWeight());
    }

    String copperPieces = null;
    String goldPieces = null;
    String silverPieces = null;
    int otherPieces = 0;
    for (COINSType coins : character.getAllCoins()) {
        StringBuffer other = new StringBuffer();
        if (coins.getEarth() > 0)
            other.append(" earth:" + coins.getEarth());
        if (coins.getWater() > 0)
            other.append(" water:" + coins.getWater());
        if (coins.getAir() > 0)
            other.append(" air:" + coins.getAir());
        if (coins.getFire() > 0)
            other.append(" fire:" + coins.getFire());
        if (coins.getOrichalcum() > 0)
            other.append(" orichalcum:" + coins.getOrichalcum());
        if (coins.getGem50() > 0)
            other.append(" gem50:" + coins.getGem50());
        if (coins.getGem100() > 0)
            other.append(" gem100:" + coins.getGem100());
        if (coins.getGem200() > 0)
            other.append(" gem200:" + coins.getGem200());
        if (coins.getGem500() > 0)
            other.append(" gem500:" + coins.getGem500());
        if (coins.getGem1000() > 0)
            other.append(" gem1000:" + coins.getGem1000());
        if (!other.toString().isEmpty()) {
            if (!coins.getName().isEmpty())
                other.append(" [" + coins.getName() + "]");
            acroFields.setField("Coins." + String.valueOf(otherPieces), other.toString());
            otherPieces++;
        }
        if (coins.getCopper() != 0) {
            if (copperPieces == null) {
                copperPieces = String.valueOf(coins.getCopper());
            } else {
                copperPieces += "+" + String.valueOf(coins.getCopper());
            }
        }
        if (coins.getSilver() != 0) {
            if (silverPieces == null) {
                silverPieces = String.valueOf(coins.getSilver());
            } else {
                silverPieces += "+" + String.valueOf(coins.getSilver());
            }
        }
        if (coins.getGold() != 0) {
            if (goldPieces == null) {
                goldPieces = String.valueOf(coins.getGold());
            } else {
                goldPieces += "+" + String.valueOf(coins.getGold());
            }
        }
    }
    acroFields.setField("CopperPieces", copperPieces);
    acroFields.setField("SilverPieces.0", silverPieces);
    acroFields.setField("GoldPieces", goldPieces);

    List<List<SPELLType>> spellslist = new ArrayList<List<SPELLType>>();
    spellslist.add(character.getOpenSpellList());
    int counterDisciplinetalent = 0;
    int counterOthertalent = 0;
    int counterKnack = 0;
    for (DISCIPLINEType discipline : character.getDisciplines()) {
        List<TALENTType> disziplinetalents = discipline.getDISZIPLINETALENT();
        Collections.sort(disziplinetalents, new TalentComparator());
        for (TALENTType talent : disziplinetalents) {
            // Fr mehr als 20 Disziplintalente ist kein Platz!
            if (counterDisciplinetalent > 20)
                break;
            setTalent(counterDisciplinetalent, talent, character.getAttributes());
            counterDisciplinetalent++;
            for (KNACKType knack : talent.getKNACK()) {
                acroFields.setField("TalentKnackTalent." + counterKnack, talent.getName());
                acroFields.setField("TalentKnackName." + counterKnack,
                        knack.getName() + " [" + knack.getStrain() + "]");
                counterKnack++;
            }
        }
        List<TALENTType> optionaltalents = discipline.getOPTIONALTALENT();
        Collections.sort(optionaltalents, new TalentComparator());
        for (TALENTType talent : optionaltalents) {
            setTalent(20 + counterOthertalent, talent, character.getAttributes());
            if (talent.getKarma().equals(YesnoType.YES)) {
                acroFields.setField("KarmaRequired." + counterOthertalent, "Yes");
            } else {
                acroFields.setField("KarmaRequired." + counterOthertalent, "");
            }
            counterOthertalent++;
            for (KNACKType knack : talent.getKNACK()) {
                acroFields.setField("TalentKnackTalent." + counterKnack, talent.getName());
                acroFields.setField("TalentKnackName." + counterKnack,
                        knack.getName() + " [" + knack.getStrain() + "]");
                counterKnack++;
            }
        }
        spellslist.add(discipline.getSPELL());
    }
    setSpellAjfelMordom(spellslist);

    // Die eventuell gesetzte KarmaBentigtHarken lschen
    while (counterOthertalent < 17) {
        acroFields.setField("KarmaRequired." + counterOthertalent, "");
        counterOthertalent++;
    }

    int counterMagicItem = 0;
    for (THREADITEMType item : character.getThreadItem()) {
        int counterMagicItemRank = 0;
        for (THREADRANKType rank : item.getTHREADRANK()) {
            counterMagicItemRank++;
            acroFields.setField("ThreadMagicObject." + counterMagicItem, item.getName());
            acroFields.setField("ThreadMagicRank." + counterMagicItem, String.valueOf(counterMagicItemRank));
            acroFields.setField("ThreadMagicLPCost." + counterMagicItem, String.valueOf(rank.getLpcost()));
            acroFields.setField("ThreadMagicEffect." + counterMagicItem, rank.getEffect());
            counterMagicItem++;
        }
    }

    int counterBloodCharms = 0;
    for (MAGICITEMType item : character.getBloodCharmItem()) {
        acroFields.setField("BloodMagicType." + counterBloodCharms, item.getName());
        String used = "";
        if (item.getUsed().equals(YesnoType.YES))
            used = " (in use)";
        acroFields.setField("BloodMagicDamage." + counterBloodCharms, item.getBlooddamage() + used);
        acroFields.setField("BloodMagicEffect." + counterBloodCharms, item.getEffect());
        counterBloodCharms++;
    }

    acroFields.setField("ShortDescription", character.getDESCRIPTION());

    int counterLanguageSpeak = 0;
    int counterLanguageReadwrite = 0;
    for (CHARACTERLANGUAGEType language : character.getLanguages().getLanguages()) {
        if (!language.getSpeak().equals(LearnedbyType.NO)) {
            acroFields.setField("LanguagesSpeak." + counterLanguageSpeak, language.getLanguage());
            counterLanguageSpeak++;
        }
        if (!language.getReadwrite().equals(LearnedbyType.NO)) {
            acroFields.setField("LanguagesReadWrite." + counterLanguageReadwrite, language.getLanguage());
            counterLanguageReadwrite++;
        }
    }

    stamper.close();
}

From source file:de.mat.utils.pdftools.PdfAddPageNum.java

License:Mozilla Public License

/**
 * <h4>FeatureDomain:</h4>// w w  w. j ava2s. co  m
 *     PublishingTools
 * <h4>FeatureDescription:</h4>
 *     adds pagenum with stamper to pages from reader 
 * <h4>FeatureResult:</h4>
 *   <ul>
 *     <li>updates stamper - updates the stamper
 *   </ul> 
 * <h4>FeatureKeywords:</h4>
 *     PDF Publishing
 * @param reader - reader with the pages
 * @param stamper - stamper to add the canvas
 * @param pageOffset - add to pagenumber
 * @throws DocumentException
 * @throws IOException
 */
public void addPageNumber(PdfReader reader, PdfStamper stamper, int pageOffset)
        throws DocumentException, IOException {
    // ierate all pages from reader
    for (int zaehler = 1; zaehler <= reader.getNumberOfPages(); zaehler++) {
        // read pagesize
        Rectangle pageSize = reader.getPageSize(zaehler);
        float xpos = pageSize.getLeft() + pageSize.getWidth() / 2;
        float ypos = 20;
        float fontSize = 7;

        // Default-Positions for --page-width 150mm --page-height 212mm == 601px
        if (pageSize.getHeight() > 602 || pageSize.getHeight() < 598) {
            // correct it relative
            float factor = pageSize.getHeight() / 601;
            if (LOGGER.isDebugEnabled())
                LOGGER.debug(" PageHeight:" + pageSize.getHeight() + " Factor:" + factor);
            ypos = ypos * factor;
            fontSize = fontSize * factor;
        }

        // add pagenumber-canvas
        PdfContentByte canvas = stamper.getOverContent(zaehler);
        BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);
        canvas.setFontAndSize(bf_helv, fontSize);
        canvas.beginText();
        canvas.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + new Integer(zaehler + pageOffset - 1), xpos,
                ypos, 0);
        canvas.endText();
    }
}

From source file:fyp.JavaWritePDF.java

public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(src); // read source file
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); // create destination file
    stamper.insertPage(reader.getNumberOfPages() + 1, reader.getPageSizeWithRotation(1)); // insert new page 
    Image img = Image.getInstance(IMG); // get instance of image file 
    img.setAbsolutePosition(0, 350);/*from w w  w .j a  v a 2 s  . c  om*/
    stamper.getOverContent(2).addImage(img); // insert image to new page
    stamper.close(); // close stamper
    File delfile = new File(SRC);
    delfile.delete(); // delete source file 
    respiratorytest.success();
}