Example usage for com.lowagie.text.pdf PdfPCell setBorderWidth

List of usage examples for com.lowagie.text.pdf PdfPCell setBorderWidth

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setBorderWidth.

Prototype

public void setBorderWidth(float borderWidth) 

Source Link

Document

Sets the borderwidth of the table.

Usage

From source file:org.egov.works.web.actions.contractorBill.ContractorBillPDFGenerator.java

License:Open Source License

protected void createHeaderRow(final PdfPTable contractorBillMainTable) {
    final PdfPTable contractorBillLeftHeader = createContractorBillHeader(
            pdfLabel.get("contractorbill.pdf.leftheader"), 0);
    contractorBillLeftHeader.getDefaultCell().setBorderWidth(0);
    final PdfPCell contractorBillLeftHeaderCell = new PdfPCell(contractorBillLeftHeader);
    contractorBillLeftHeaderCell.setBorderWidth(0);
    contractorBillLeftHeaderCell.setColspan(4);
    contractorBillMainTable.addCell(contractorBillLeftHeaderCell);
    final PdfPTable contractorBillMainHeader = createContractorBillHeader(
            pdfLabel.get("contractorbill.pdf.mainheader"), 1);
    contractorBillMainHeader.getDefaultCell().setBorderWidth(0);
    final PdfPCell contractorBillMainHeaderCell = new PdfPCell(contractorBillMainHeader);
    contractorBillMainHeaderCell.setBorderWidth(0);
    contractorBillMainHeaderCell.setColspan(3);
    contractorBillMainTable.addCell(contractorBillMainHeaderCell);
    final PdfPTable contractorBillRightHeader = createContractorBillHeader(
            pdfLabel.get("contractorbill.pdf.rightheader"), 2);
    contractorBillMainHeader.getDefaultCell().setBorderWidth(0);
    final PdfPCell contractorBillRightHeaderCell = new PdfPCell(contractorBillRightHeader);
    contractorBillRightHeaderCell.setBorderWidth(0);
    contractorBillRightHeaderCell.setColspan(4);
    contractorBillMainTable.addCell(contractorBillRightHeaderCell);
}

From source file:org.egov.works.web.actions.estimate.EstimatePDFGenerator.java

License:Open Source License

private PdfPTable createDepositAppropriationTable(final AbstractEstimate estimate,
        final String appropriationNumber) throws DocumentException {
    int isReject = -1;
    depositWorksUsageService = abstractEstimateService.getDepositWorksUsageService();
    BigDecimal totalUtilizedAmt;// w  w w.  j a  v a  2  s. c  o m
    BigDecimal amtAppropriatedsofar;
    BigDecimal totalDepositAmt;
    BigDecimal balOnHand;
    BigDecimal balanceAvailable;
    BigDecimal amtAppropriated;
    final Accountdetailtype accountdetailtype = worksService.getAccountdetailtypeByName("DEPOSITCODE");
    estimateAppropriationService = abstractEstimateService.getEstimateAppropriationService();
    abstractEstimateAppropriationList = estimateAppropriationService.findAllBy(
            "from AbstractEstimateAppropriation aea where aea.abstractEstimate.id=? and aea.depositWorksUsage.id is not null order by id, aea.depositWorksUsage.financialYearId asc",
            estimate.getId());
    final PdfPTable depositWorksAppropriationTable = new PdfPTable(2);
    depositWorksAppropriationTable.setWidthPercentage(100);
    depositWorksAppropriationTable.setWidths(new float[] { 2f, 8f });

    if (appropriationNumber != null && appropriationNumber.toUpperCase().contains("BC"))
        isReject = 1;

    if (appropriationNumber != null && estimate.getTotalAmount() != null && isReject == -1) {
        addRow(depositWorksAppropriationTable, true, centerPara("Deposit Code"),
                centerPara(estimate.getDepositCode().getCode()));
        addRow(depositWorksAppropriationTable, true, centerPara("Account Code"),
                centerPara(estimate.getFinancialDetails().get(0).getCoa().getGlcode() + "-"
                        + estimate.getFinancialDetails().get(0).getCoa().getName()));
        addRow(depositWorksAppropriationTable, true, makePara("Function Center"),
                centerPara(estimate.getFinancialDetails().get(0).getFunction().getName()));
        addRow(depositWorksAppropriationTable, true, makePara("Department"),
                centerPara(estimate.getUserDepartment().getName()));
        addRow(depositWorksAppropriationTable, true, makePara("Amount of the Estimate "),
                rightPara(toCurrency(estimate.getTotalAmount())));
        final PdfPTable appropriationDetailTable = new PdfPTable(6);
        addRow(appropriationDetailTable, true, makePara(7f, "Appropriation Number"),
                makePara(7f, "Total Deposit Amount"), makePara(7f, "Amount Appropriated so far"),
                makePara(7f, "Amount Appropriated"), makePara(7f, "Balance on Hand"),
                makePara(7f, "Balance After Appropriation"));
        for (final AbstractEstimateAppropriation abstractEstimateAppropriation : abstractEstimateAppropriationList)
            if (abstractEstimateAppropriation.getDepositWorksUsage().getConsumedAmount().doubleValue() != 0) {
                totalDepositAmt = depositWorksUsageService.getTotalDepositWorksAmount(
                        estimate.getDepositCode().getFund(),
                        abstractEstimateAppropriation.getAbstractEstimate().getFinancialDetails().get(0)
                                .getCoa(),
                        accountdetailtype, estimate.getDepositCode().getId(),
                        abstractEstimateAppropriation.getDepositWorksUsage().getAppropriationDate());
                totalUtilizedAmt = depositWorksUsageService.getTotalUtilizedAmountForDepositWorks(
                        abstractEstimateAppropriation.getAbstractEstimate().getFinancialDetails().get(0),
                        abstractEstimateAppropriation.getDepositWorksUsage().getCreatedDate());
                if (totalUtilizedAmt == null)
                    totalUtilizedAmt = BigDecimal.ZERO;
                amtAppropriatedsofar = totalUtilizedAmt
                        .subtract(abstractEstimateAppropriation.getDepositWorksUsage().getConsumedAmount());
                balOnHand = totalDepositAmt.subtract(amtAppropriatedsofar);
                amtAppropriated = abstractEstimateAppropriation.getDepositWorksUsage().getConsumedAmount();
                balanceAvailable = BigDecimal
                        .valueOf(totalDepositAmt.doubleValue() - totalUtilizedAmt.doubleValue());
                addRow(appropriationDetailTable, true,
                        makePara(7f,
                                abstractEstimateAppropriation.getDepositWorksUsage().getAppropriationNumber()),
                        rightPara(7f, toCurrency(totalDepositAmt.doubleValue())),
                        rightPara(7f, toCurrency(amtAppropriatedsofar.doubleValue())),
                        rightPara(7f, toCurrency(amtAppropriated.doubleValue())),
                        rightPara(7f, toCurrency(balOnHand.doubleValue())),
                        rightPara(7f, toCurrency(balanceAvailable.doubleValue())));
            }

        final PdfPCell appDetailpdfCell = new PdfPCell(appropriationDetailTable);
        appDetailpdfCell.setBorderWidth(0);

        final PdfPCell appDetailRightHeader = new PdfPCell(
                makePara("Financail Year Wise Appropriation Details"));
        appDetailRightHeader.setVerticalAlignment(Element.ALIGN_MIDDLE);

        depositWorksAppropriationTable.addCell(appDetailRightHeader);
        appropriationDetailTable.setWidthPercentage(100);
        depositWorksAppropriationTable.addCell(appDetailpdfCell);
    }
    return depositWorksAppropriationTable;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

@Override
public void export(GTDModel model, ActionsCollection collection, OutputStream out,
        ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception {

    fontSelector = new FontSelector();
    fontSelectorB = new FontSelector();
    fontSelectorB2 = new FontSelector();
    fontSelectorB4 = new FontSelector();

    baseFont = fontModel.getBaseFont();//from w w w . j a  v a2s  .  co  m

    for (BaseFont bf : fontModel.getFonts()) {
        fontSelector.addFont(new Font(bf, baseFontSize));
        fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD));
        fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD));
        fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD));
    }

    boolean emptyH2 = false;
    boolean emptyH3 = false;

    PdfPTable actionTable = null;

    Document doc = new Document();

    if (sizeSet) {
        doc.setPageSize(pageSize);
    }
    if (marginSet) {
        doc.setMargins(marginLeft, marginRight, marginTop, marginBottom);
    }

    //System.out.println("PDF size "+doc.getPageSize().toString());
    //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom);

    @SuppressWarnings("unused")
    PdfWriter pw = PdfWriter.getInstance(doc, out);

    doc.addCreationDate();
    doc.addTitle("GTD-Free PDF");
    doc.addSubject("GTD-Free data exported as PDF");

    HeaderFooter footer = new HeaderFooter(newParagraph(), true);
    footer.setAlignment(HeaderFooter.ALIGN_CENTER);
    footer.setBorder(HeaderFooter.TOP);
    doc.setFooter(footer);

    doc.open();

    Phrase ch = newTitle("GTD-Free Data");
    Paragraph p = new Paragraph(ch);
    p.setAlignment(Paragraph.ALIGN_CENTER);

    PdfPTable t = new PdfPTable(1);
    t.setWidthPercentage(100f);
    PdfPCell c = newCell(p);
    c.setBorder(Table.BOTTOM);
    c.setBorderWidth(2.5f);
    c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    c.setPadding(5f);
    t.addCell(c);
    doc.add(t);

    Iterator<Object> it = collection.iterator(order);

    while (it.hasNext()) {
        Object o = it.next();

        if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) {

            if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = false;
                emptyH3 = true;
            } else {

                doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = true;
                emptyH3 = false;
            }

            continue;
        }

        if (o instanceof Folder) {

            Folder f = (Folder) o;

            if (actionTable != null) {
                doc.add(actionTable);
                actionTable = null;
            }

            if (f.isProject()) {

                if (order == ExportAddOn.ExportOrder.ProjectsActions
                        || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) {

                    if (emptyH2 || emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSection(f.getName()));

                    if (compact) {
                        if (f.getDescription() != null && f.getDescription().length() > 0) {
                            p = newParagraph(f.getDescription());
                            p.setIndentationLeft(10f);
                            p.setIndentationRight(10f);
                            doc.add(p);
                        }
                    } else {
                        t = new PdfPTable(2);
                        t.setKeepTogether(true);
                        t.setSpacingBefore(5f);
                        t.setWidthPercentage(66f);
                        t.setWidths(new float[] { 0.33f, 0.66f });

                        c = newCell("ID");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                        t.addCell(c);
                        c = newCell("Type");
                        t.addCell(c);
                        c = newCell(newStrongParagraph("Project"));
                        t.addCell(c);
                        c = newCell("Open");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                        t.addCell(c);
                        c = newCell("All");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.size())));
                        t.addCell(c);
                        c = newCell("Description");
                        t.addCell(c);
                        c = newDescriptionCell(f.getDescription());
                        t.addCell(c);

                        doc.add(t);
                    }

                    emptyH2 = true;
                    emptyH3 = false;

                } else {

                    if (emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSubSection("Project:" + " " + f.getName()));

                    emptyH2 = false;
                    emptyH3 = true;
                }

                continue;

            }
            if (order == ExportAddOn.ExportOrder.FoldersActions
                    || order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                if (emptyH2 || emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSection(f.getName()));

                if (compact) {
                    if (f.getDescription() != null && f.getDescription().length() > 0) {
                        p = newParagraph(f.getDescription());
                        p.setIndentationLeft(10f);
                        p.setIndentationRight(10f);
                        doc.add(p);
                    }
                } else {

                    t = new PdfPTable(2);
                    t.setKeepTogether(true);
                    t.setSpacingBefore(5f);
                    t.setWidthPercentage(66f);
                    t.setWidths(new float[] { 0.33f, 0.66f });

                    c = newCell("ID");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                    t.addCell(c);

                    String type = "";
                    if (f.isAction()) {
                        type = "Action list";
                    } else if (f.isInBucket()) {
                        type = "In-Bucket";
                    } else if (f.isQueue()) {
                        type = "Next action queue";
                    } else if (f.isReference()) {
                        type = "Reference list";
                    } else if (f.isSomeday()) {
                        type = "Someday/Maybe list";
                    } else if (f.isBuildIn()) {
                        type = "Default list";
                    }

                    c = newCell("Type");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(type));
                    t.addCell(c);
                    c = newCell("Open");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                    t.addCell(c);
                    c = newCell("All");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.size())));
                    t.addCell(c);
                    c = newCell("Description");
                    t.addCell(c);
                    c = newDescriptionCell(f.getDescription());
                    t.addCell(c);

                    doc.add(t);
                }

                emptyH2 = true;
                emptyH3 = false;

            } else {

                if (emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSubSection("List:" + " " + f.getName()));

                emptyH2 = false;
                emptyH3 = true;

            }

            continue;

        }

        if (o instanceof Action) {
            emptyH2 = false;
            emptyH3 = false;

            Action a = (Action) o;

            if (compact) {

                if (actionTable == null) {
                    actionTable = new PdfPTable(5);
                    actionTable.setWidthPercentage(100f);
                    actionTable.setHeaderRows(1);
                    actionTable.setSpacingBefore(5f);
                    c = newHeaderCell("ID");
                    actionTable.addCell(c);
                    c = newHeaderCell("Pri.");
                    actionTable.addCell(c);
                    c = newHeaderCell("Description");
                    actionTable.addCell(c);
                    c = newHeaderCell("Reminder");
                    actionTable.addCell(c);
                    c = newHeaderCell(CHECK_RESOLVED);
                    actionTable.addCell(c);

                    float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft()
                            - doc.getPageSize().getBorderWidthRight();
                    int i = model.getLastActionID();
                    float step = baseFontSize - 1;
                    int steps = (int) Math.floor(Math.log10(i)) + 1;
                    // ID column
                    float col1 = 8 + steps * step;
                    // Priority column
                    float col2 = 4 + 3 * (baseFontSize + 4);
                    // Reminder column
                    float col4 = 10 + step * 11;
                    // Resolved column
                    float col5 = 8 + baseFontSize;
                    // Description column
                    float col3 = width - col1 - col2 - col4 - col5;
                    actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 });

                }

                addSingleActionRow(a, actionTable);

            } else {
                addSingleActionTable(model, doc, a);
            }
        }

    }

    if (actionTable != null) {
        doc.add(actionTable);
        actionTable = null;
    }
    if (emptyH2 || emptyH3) {

        p = newParagraph(NONE_DOT);
        doc.add(p);
    }

    //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date()));

    doc.close();
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private PdfPCell newCell(Paragraph p) throws BadElementException {
    PdfPCell c = new PdfPCell(p);
    c.setBorder(PdfPCell.BOX);//from   w  w  w.  ja v  a  2  s.com
    c.setBorderWidth(0.1f);
    c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    c.setPaddingBottom(3f);
    c.setPaddingLeft(3f);
    c.setPaddingRight(3f);
    c.setPaddingTop(0f);
    c.setUseBorderPadding(true);
    return c;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB2.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(15f);/*  w  ww.ja va2s  . co  m*/
    t.setSpacingAfter(7f);
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(1f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSubSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(7f);/*from  w  w w  .j  a  v a2 s.  c  o  m*/
    t.setSpacingAfter(5f);
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(0.75f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.kuali.kfs.module.endow.report.util.EndowmentReportPrintBase.java

License:Educational Community License

/**
 * Generates the footer/*w  ww. j a v  a  2  s.  c o m*/
 * 
 * @param footerData
 * @param document
 */
public boolean printFooter(EndowmentReportFooterDataHolder footerData, Document document) {

    if (footerData == null) {
        return false;
    }

    try {
        document.add(new Phrase("\n"));

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(FULL_TABLE_WIDTH);
        int[] colWidths = { 40, 60 };
        table.setWidths(colWidths);
        table.getDefaultCell().setPadding(2);

        // left column
        PdfPTable leftTable = new PdfPTable(2);
        leftTable.setWidths(colWidths);
        leftTable.setWidthPercentage(40);

        leftTable.addCell(createCell("Reference: ", footerTitleFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell(footerData.getReference(), footerRegularFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell("Date Established: ", footerTitleFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(
                createCell(footerData.getEstablishedDate(), footerRegularFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell("KEMID Type: ", footerTitleFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell(footerData.getKemidType(), footerRegularFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell("KEMID Purpose: ", footerTitleFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(
                createCell(footerData.getKemidPurpose(), footerRegularFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(createCell("Report Run Date: ", footerTitleFont, Element.ALIGN_LEFT, false));
        leftTable.addCell(
                createCell(footerData.getReportRunDate(), footerRegularFont, Element.ALIGN_LEFT, false));
        table.addCell(leftTable);

        // right column
        PdfPTable rightTable = new PdfPTable(4);
        rightTable.setWidthPercentage(60);

        PdfPCell cellBenefitting = new PdfPCell(new Paragraph("BENEFITTING\n", titleFont));
        cellBenefitting.setColspan(4);
        cellBenefitting.setBorderWidth(0);
        rightTable.addCell(cellBenefitting);

        rightTable.addCell(createCell("Campus", footerTitleFont, Element.ALIGN_LEFT, false));
        rightTable.addCell(createCell("Chart", footerTitleFont, Element.ALIGN_LEFT, false));
        rightTable.addCell(createCell("Organizaztion", footerTitleFont, Element.ALIGN_LEFT, false));
        rightTable.addCell(createCell("Percent", footerTitleFont, Element.ALIGN_LEFT, false));

        List<BenefittingForFooter> benefittingList = footerData.getBenefittingList();
        if (benefittingList != null) {
            for (BenefittingForFooter benefitting : benefittingList) {
                rightTable.addCell(createCell(benefitting.getCampusName(), footerRegularFont,
                        Element.ALIGN_LEFT, Element.ALIGN_TOP, false));
                rightTable.addCell(createCell(benefitting.getChartName(), footerRegularFont, Element.ALIGN_LEFT,
                        Element.ALIGN_TOP, false));
                rightTable.addCell(createCell(benefitting.getOrganizationName(), footerRegularFont,
                        Element.ALIGN_LEFT, Element.ALIGN_TOP, false));
                rightTable.addCell(createCell(benefitting.getBenefittingPercent(), footerRegularFont,
                        Element.ALIGN_LEFT, Element.ALIGN_TOP, false));
            }
        }

        table.addCell(rightTable);

        document.add(table);

    } catch (Exception e) {
        return false;
    }

    return true;
}

From source file:org.kuali.kfs.module.endow.report.util.EndowmentReportPrintBase.java

License:Educational Community License

/**
 * Creates a call with given font, alignments, and borderline
 * /*w ww .j ava2 s. c o m*/
 * @param contents
 * @param font
 * @param horizontalAlignment
 * @param verticalAlignment
 * @param borderLine
 * @return
 */
public PdfPCell createCell(String contents, Font font, int horizontalAlignment, int verticalAlignment,
        boolean borderLine) {
    if (contents == null)
        contents = "";
    Phrase phr = new Phrase(contents, font);
    PdfPCell cell = new PdfPCell(phr);
    cell.setHorizontalAlignment(horizontalAlignment);
    if (!borderLine) {
        cell.setBorderWidth(0);
    }
    cell.setVerticalAlignment(verticalAlignment);
    return cell;
}

From source file:org.kuali.kfs.module.purap.pdf.BulkReceivingPdf.java

License:Open Source License

private void loadHeaderTable() throws Exception {

    float[] headerWidths = { 0.20f, 0.80f };

    headerTable = new PdfPTable(headerWidths);
    headerTable.setWidthPercentage(100);
    headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.setSplitLate(false);/*  ww  w.j  a  v  a  2 s  .co  m*/
    headerTable.getDefaultCell().setBorderWidth(0);
    headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);

    /**
     * Logo display
     */
    if (StringUtils.isNotBlank(logoImage)) {
        logo = Image.getInstance(logoImage);
        logo.scalePercent(3, 3);
        headerTable.addCell(new Phrase(new Chunk(logo, 0, 0)));
    } else {
        headerTable.addCell(new Phrase(new Chunk("")));
    }

    /**
     * Nested table in tableHeader to display title and doc number
     */
    float[] nestedHeaderWidths = { 0.70f, 0.30f };
    nestedHeaderTable = new PdfPTable(nestedHeaderWidths);
    nestedHeaderTable.setSplitLate(false);
    PdfPCell cell;

    /**
     * Title
     */
    cell = new PdfPCell(new Paragraph("RECEIVING TICKET", ver_15_normal));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0);
    nestedHeaderTable.addCell(cell);

    /**
     * Doc Number
     */
    Paragraph p = new Paragraph();
    p.add(new Chunk("Doc Number: ", ver_11_normal));
    p.add(new Chunk(blkRecDoc.getDocumentNumber().toString(), cour_10_normal));
    cell = new PdfPCell(p);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setBorderWidth(0);
    nestedHeaderTable.addCell(cell);

    // Add the nestedHeaderTable to the headerTable
    cell = new PdfPCell(nestedHeaderTable);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorderWidth(0);
    headerTable.addCell(cell);
}

From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderPdf.java

License:Open Source License

/**
 * Overrides the method in PdfPageEventHelper from itext to create and set the headerTable and set its logo image if
 * there is a logoImage to be used, creates and sets the nestedHeaderTable and its content.
 *
 * @param writer    The PdfWriter for this document.
 * @param document  The document./*from w ww  .  ja  v a 2 s . c om*/
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onOpenDocument(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
@Override
public void onOpenDocument(PdfWriter writer, Document document) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("onOpenDocument() started. isRetransmit is " + isRetransmit);
    }
    try {
        float[] headerWidths = { 0.20f, 0.80f };
        headerTable = new PdfPTable(headerWidths);
        headerTable.setWidthPercentage(100);
        headerTable.setHorizontalAlignment(Element.ALIGN_CENTER);
        headerTable.setSplitLate(false);
        headerTable.getDefaultCell().setBorderWidth(0);
        headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        headerTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);

        Image logo = null;
        if (StringUtils.isNotBlank(logoImage)) {
            try {
                logo = Image.getInstance(logoImage);
            } catch (IOException e) {
                LOG.info("The logo image [" + logoImage
                        + "] is not available.  Defaulting to the default image.");
            }
        }

        if (logo == null) {
            // if we don't use images
            headerTable.addCell(new Phrase(new Chunk("")));
        } else {
            logo.scalePercent(3, 3);
            headerTable.addCell(new Phrase(new Chunk(logo, 0, 0)));
        }
        // Nested table for titles, etc.
        float[] nestedHeaderWidths = { 0.70f, 0.30f };
        nestedHeaderTable = new PdfPTable(nestedHeaderWidths);
        nestedHeaderTable.setSplitLate(false);
        PdfPCell cell;

        // New nestedHeaderTable row
        cell = new PdfPCell(new Paragraph(po.getBillingName(), ver_15_normal));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(0);
        nestedHeaderTable.addCell(cell);
        cell = new PdfPCell(new Paragraph(" ", ver_15_normal));
        cell.setBorderWidth(0);
        nestedHeaderTable.addCell(cell);
        // New nestedHeaderTable row
        if (isRetransmit) {
            cell = new PdfPCell(new Paragraph(po.getRetransmitHeader(), ver_15_normal));
        } else {
            cell = new PdfPCell(new Paragraph("PURCHASE ORDER", ver_15_normal));
        }
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(0);
        nestedHeaderTable.addCell(cell);
        Paragraph p = new Paragraph();
        p.add(new Chunk("PO Number: ", ver_11_normal));
        p.add(new Chunk(po.getPurapDocumentIdentifier().toString(), cour_16_bold));

        cell = new PdfPCell(p);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorderWidth(0);
        nestedHeaderTable.addCell(cell);
        if (!po.getPurchaseOrderAutomaticIndicator()) { // Contract manager name goes on non-APOs.
            // New nestedHeaderTable row, spans both columns
            p = new Paragraph();
            p.add(new Chunk("Contract Manager: ", ver_11_normal));
            p.add(new Chunk(po.getContractManager().getContractManagerName(), cour_7_normal));
            cell = new PdfPCell(p);
            cell.setColspan(2);
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setBorderWidth(0);
            nestedHeaderTable.addCell(cell);
        }
        // Add the nestedHeaderTable to the headerTable
        cell = new PdfPCell(nestedHeaderTable);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidth(0);
        headerTable.addCell(cell);

        // initialization of the template
        tpl = writer.getDirectContent().createTemplate(100, 100);
        // initialization of the font
        helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false);
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}