Example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell

List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java

private static PdfPTable populateLicenseInformation(FacilityLicenseView license) throws DocumentException {
    Paragraph paragraph;/* w  w  w. j av a  2 s .c  om*/
    PdfPTable datatable = getLicenseDetailTable();

    // Put License Number
    datatable.getDefaultCell().setPaddingLeft(4);
    datatable.getDefaultCell().setPaddingRight(2);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(new Phrase("License No:", smallfontB));
    datatable.getDefaultCell().setPaddingLeft(4);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if (license.getLicenseNumber() != null) {
        datatable.addCell(new Phrase(license.getLicenseNumber().toString(), smallfont));
    } else {
        datatable.addCell(BLANK);
    }

    // Put Service information
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(new Phrase("Service: ", smallfontB));
    datatable.getDefaultCell().setColspan(3);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if (StringUtils.isNotBlank(license.getServiceCodeDesc())) {
        datatable.addCell(new Phrase(license.getServiceCodeDesc(), smallfont));
    } else {
        datatable.addCell(BLANK);
    }

    // Put License Expiration
    paragraph = new Paragraph(fixedLeading);
    paragraph.add(new Phrase("Expires: ", smallfontB));
    if (license.getExpirationDate() != null) {
        paragraph.add(new Phrase(df.format(license.getExpirationDate()), smallfont));
    }
    datatable.getDefaultCell().setColspan(1);
    datatable.getDefaultCell().setPaddingRight(4);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(paragraph);

    // Add the License SubType Information
    datatable.getDefaultCell().setPaddingLeft(4);
    datatable.getDefaultCell().setPaddingRight(2);
    datatable.addCell(new Phrase("Type:", smallfontB));
    datatable.getDefaultCell().setPaddingLeft(2);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if (StringUtils.isNotBlank(license.getSubtype())) {
        datatable.addCell(new Phrase(license.getSubtype(), smallfont));
    } else {
        datatable.addCell(BLANK);
    }

    // Add Specific Service
    datatable.getDefaultCell().setPaddingLeft(2);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(new Phrase("Specific Service: ", smallfontB));
    datatable.getDefaultCell().setPaddingRight(4);
    datatable.getDefaultCell().setColspan(4);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if (StringUtils.isNotBlank(license.getSpecificServiceCode())) {
        datatable.addCell(new Phrase(license.getSpecificServiceCode(), smallfont));
    } else {
        datatable.addCell(BLANK);
    }

    // Add License Capacity Information
    datatable.getDefaultCell().setColspan(1);
    datatable.getDefaultCell().setPaddingLeft(4);
    datatable.getDefaultCell().setPaddingRight(2);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(new Phrase("Age Group: ", smallfontB));
    datatable.getDefaultCell().setPaddingLeft(2);
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if (StringUtils.isNotBlank(license.getAgeGroup())) {
        datatable.addCell(new Phrase(license.getAgeGroup(), smallfont));
    } else {
        datatable.addCell(BLANK);
    }

    // Add Age Group total capacity
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    datatable.addCell(new Phrase("Capacity:", smallfontB));
    datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    if ("Youth".equalsIgnoreCase(license.getAgeGroup())) {
        // Youth capacity
        if (license.getYouthTotalSlots() != null) {
            datatable.addCell(new Phrase(license.getYouthTotalSlots().toString(), smallfont));
        } else {
            datatable.addCell(BLANK);
        }
    } else {
        // Adult capacity
        if (license.getAdultTotalSlots() != null) {
            datatable.addCell(new Phrase(license.getAdultTotalSlots().toString(), smallfont));
        } else {
            datatable.addCell(BLANK);
        }
    }

    // Add Age Group ages
    paragraph = new Paragraph(fixedLeading);
    paragraph.add(new Phrase("Ages: ", smallfontB));
    if (license.getFromAge() != null || license.getToAge() != null) {
        sb = new StringBuilder();
        if (license.getFromAge() != null) {
            sb.append(license.getFromAge().toString());
            if (license.getToAge() != null) {
                sb.append(" to " + license.getToAge().toString());
            } else {
                sb.append(" and Older");
            }
        } else {
            sb.append("to " + license.getToAge().toString());
        }
        paragraph.add(new Phrase(sb.toString(), smallfont));
    }
    datatable.addCell(paragraph);

    // Add Age Group Male and Female Counts
    if ("Adult".equalsIgnoreCase(license.getAgeGroup()) || "Youth".equalsIgnoreCase(license.getAgeGroup())) {
        if ("Adult".equalsIgnoreCase(license.getAgeGroup())) {
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Male: ", smallfontB));
            if (license.getAdultMaleCount() != null) {
                paragraph.add(new Phrase(license.getAdultMaleCount().toString(), smallfont));
            }
            datatable.addCell(paragraph);

            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Female: ", smallfontB));
            if (license.getAdultFemaleCount() != null) {
                paragraph.add(new Phrase(license.getAdultFemaleCount().toString(), smallfont));
            }
            datatable.getDefaultCell().setPaddingRight(4);
            datatable.addCell(paragraph);
        } else {
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Male: ", smallfontB));
            if (license.getYouthMaleCount() != null) {
                paragraph.add(new Phrase(license.getYouthMaleCount().toString(), smallfont));
            }
            datatable.addCell(paragraph);

            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Female: ", smallfontB));
            if (license.getYouthFemaleCount() != null) {
                paragraph.add(new Phrase(license.getYouthFemaleCount().toString(), smallfont));
            }
            datatable.getDefaultCell().setPaddingRight(4);
            datatable.addCell(paragraph);
        }
    } else {
        datatable.getDefaultCell().setColspan(2);
        datatable.addCell(BLANK);
    }

    // Add Program Code Information
    if (license.getProgramCodeIds() != null && license.getProgramCodeIds().size() > 0) {
        for (PickListValue prog : license.getProgramCodeIds()) {
            datatable.getDefaultCell().setColspan(1);
            datatable.getDefaultCell().setPaddingLeft(4);
            datatable.getDefaultCell().setPaddingRight(2);
            datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
            datatable.addCell(new Phrase("Program:", smallfontB));
            datatable.getDefaultCell().setColspan(6);
            datatable.getDefaultCell().setPaddingRight(4);
            datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
            String program = getPickListValueDesc(prog);
            if (StringUtils.isNotBlank(program)) {
                datatable.addCell(new Phrase(program, smallfont));
            } else {
                datatable.addCell(BLANK);
            }
        }
    }

    return datatable;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java

private static PdfPTable getDocumentTable(Person specialist, Date endDate) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    // format the tables
    int headerwidths[] = { 100 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);/*from  w ww.ja va  2 s .  c  o m*/
    table.getDefaultCell().setLeading(0, 0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setBorderWidthTop(0);
    table.getDefaultCell().setPaddingBottom(4);
    table.getDefaultCell().setBorderWidthBottom(1.0f);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

    table.addCell(getHeaderTable(specialist, endDate));
    table.setHeaderRows(1);

    return table;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java

private static PdfPTable getHeaderTable(Person specialist, Date endDate) throws DocumentException {
    Date today = new Date();

    PdfPTable table = new PdfPTable(2);
    // format the table
    int headerwidths[] = { 80, 20 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);//from  w  ww. j  a  v a  2 s  .c o  m
    table.getDefaultCell().setLeading(largeFixedLeading, 0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setPaddingLeft(4);
    table.getDefaultCell().setPaddingRight(2);
    if (endDate == null) {
        table.getDefaultCell().setPaddingBottom(17);
    }
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setBorderWidthTop(1.0f);
    table.getDefaultCell().setBorderWidthBottom(0);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    // Add Page header information
    sb = new StringBuilder();
    sb.append("Facility Licenses for ");
    if (StringUtils.isNotBlank(specialist.getFirstAndLastName())) {
        sb.append(specialist.getFirstAndLastName());
    }
    table.addCell(new Phrase(sb.toString(), largefontB));

    // Add report date
    table.getDefaultCell().setPaddingLeft(2);
    table.getDefaultCell().setPaddingRight(4);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    table.addCell(new Phrase(df.format(today), mediumfontB));

    if (endDate != null) {
        // Add expiration end date date
        table.getDefaultCell().setPaddingLeft(8);
        table.getDefaultCell().setPaddingRight(4);
        table.getDefaultCell().setPaddingBottom(0);
        table.getDefaultCell().setBorderWidthTop(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        table.getDefaultCell().setColspan(2);
        table.addCell(new Phrase("With Licenses Expiring " + df.format(endDate), mediumfontB));
    }

    return table;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java

private static PdfPTable getFacilityDetailTable() throws DocumentException {
    PdfPTable table = new PdfPTable(4);
    // format the table
    int headerwidths[] = { 11, 18, 29, 42 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);/*from ww  w  .  ja v a  2 s.  c o m*/
    table.getDefaultCell().setLeading(fixedLeading, 0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    return table;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java

private static PdfPTable getLicenseDetailTable() throws DocumentException {
    PdfPTable table = new PdfPTable(7);
    // format the table
    int headerwidths[] = { 11, 18, 15, 8, 17, 12, 19 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);//from  ww  w  .j a va  2 s  .co m
    table.getDefaultCell().setLeading(fixedLeading, 0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    return table;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseSummaryReport.java

private static void writePdf(Person specialist, Date endDate, FacilityLicenseSummarySortBy sortBy,
        List<FacilityLicenseView> licenses, OutputStream ba) throws DocumentException, BadElementException {
    Document document = null;/*  ww  w.j a  v a 2 s.  co  m*/
    PdfPTable doctable;
    PdfPTable datatable;
    PdfPTable factable;
    Paragraph paragraph;
    Facility facility;
    document = new Document(PageSize.A4);
    @SuppressWarnings("unused")
    PdfWriter writer = PdfWriter.getInstance(document, ba);

    document.open();

    doctable = getDocumentTable(specialist, endDate, sortBy);

    if (licenses != null && licenses.size() > 0) {
        doctable.getDefaultCell().setPaddingBottom(4);
        doctable.getDefaultCell().setBorderWidthBottom(.5f);
        for (FacilityLicenseView license : licenses) {
            facility = license.getFacility();
            datatable = getDetailTable();
            datatable.getDefaultCell().setPaddingLeft(4);
            datatable.getDefaultCell().setPaddingRight(2);
            datatable.getDefaultCell().setColspan(1);
            // Add Facility Name information
            if (StringUtils.isNotBlank(license.getFacilityName())) {
                datatable.addCell(new Phrase(license.getFacilityName(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Number information
            datatable.getDefaultCell().setPaddingLeft(2);
            if (license.getLicenseNumber() != null) {
                datatable.addCell(new Phrase(license.getLicenseNumber().toString(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add Service Code information
            if (StringUtils.isNotBlank(license.getServiceCodeCode())) {
                datatable.addCell(new Phrase(license.getServiceCodeCode(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Type information
            if (StringUtils.isNotBlank(license.getSubtype())) {
                datatable.addCell(new Phrase(license.getSubtype(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Expiration date information
            datatable.getDefaultCell().setPaddingRight(4);
            if (StringUtils.isNotBlank(license.getExpirationDateFormatted())) {
                datatable.addCell(new Phrase(license.getExpirationDateFormatted(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }

            // Add Mailing Location information
            sb = new StringBuilder();
            if (facility != null && facility.getMailingAddress() != null
                    && StringUtils.isNotBlank(facility.getMailingAddress().getAddressOne())) {
                sb.append(facility.getMailingAddress().getAddressOne());

                // add address two
                if (StringUtils.isNotBlank(facility.getMailingAddress().getAddressTwo())) {
                    if (sb.length() > 0) {
                        sb.append(" ");
                    }
                    sb.append(facility.getMailingAddress().getAddressTwo());
                }

                // Add city, state, zip
                if (StringUtils.isNotBlank(facility.getMailingAddress().getCityStateZip())) {
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append(facility.getMailingAddress().getCityStateZip());
                }
            }
            datatable.getDefaultCell().setColspan(5);
            datatable.getDefaultCell().setPaddingLeft(4);
            datatable.getDefaultCell().setPaddingRight(4);
            if (sb.length() > 0) {
                datatable.addCell(new Phrase(sb.toString().toUpperCase(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }

            //
            // Add Facility details information
            // 
            factable = getFacilityDetailsTable();

            // Add primary phone information
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Primary Phone: ", smallfontB));
            if (facility != null && facility.getPrimaryPhone() != null
                    && StringUtils.isNotBlank(facility.getPrimaryPhone().getFormattedPhoneNumber())) {
                paragraph.add(new Phrase(facility.getPrimaryPhone().getFormattedPhoneNumber(), smallfont));
            }
            factable.getDefaultCell().setPaddingLeft(4);
            factable.getDefaultCell().setPaddingRight(2);
            factable.addCell(paragraph);

            // Add SAFE Provider ID number
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("SAFE: ", smallfontB));
            if (facility != null && facility.getSafeProviderId() != null) {
                paragraph.add(new Phrase(facility.getSafeProviderId().toString(), smallfontB));
            }
            factable.getDefaultCell().setColspan(2);
            factable.addCell(paragraph);

            // Add the facility information table to the details table
            datatable.getDefaultCell().setPadding(0);
            datatable.addCell(factable);
            // Add the detail to the document table
            doctable.addCell(datatable);
        }
    } else {
        // No open applications
        datatable = getDetailTable();
        datatable.getDefaultCell().setPaddingTop(10);
        datatable.getDefaultCell().setColspan(3);
        datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        datatable.addCell(new Phrase("No expired licenses found to display.", smallfont));
        doctable.getDefaultCell().setPaddingBottom(0);
        doctable.getDefaultCell().setBorderWidthBottom(0);
        doctable.addCell(datatable);
    }

    // Add the document table to the document
    document.add(doctable);

    document.close();
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseSummaryReport.java

private static PdfPTable getDocumentTable(Person specialist, Date endDate, FacilityLicenseSummarySortBy sortBy)
        throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    // format the tables
    int headerwidths[] = { 100 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);//from  w w w  .  ja v  a2 s. c o m
    table.getDefaultCell().setLeading(0, 0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setBorderWidthTop(0);
    table.getDefaultCell().setPaddingBottom(4);
    table.getDefaultCell().setBorderWidthBottom(1.0f);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

    table.addCell(getHeaderTable(specialist, endDate, sortBy));
    table.setHeaderRows(1);

    return table;

}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseSummaryReport.java

private static PdfPTable getHeaderTable(Person specialist, Date endDate, FacilityLicenseSummarySortBy sortBy)
        throws DocumentException {
    Date today = new Date();

    PdfPTable table = getDetailTable();

    // Add Page header information
    table.getDefaultCell().setLeading(largeFixedLeading, 0);
    table.getDefaultCell().setPaddingLeft(4);
    table.getDefaultCell().setPaddingRight(2);
    if (endDate == null) {
        table.getDefaultCell().setPaddingBottom(17);
    }/*  w  ww  .  j av a  2 s.  co  m*/
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setBorderWidthTop(1.0f);
    table.getDefaultCell().setBorderWidthBottom(0);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.getDefaultCell().setColspan(3);
    sb = new StringBuilder();
    sb.append("Facility Licenses for ");
    if (StringUtils.isNotBlank(specialist.getFirstAndLastName())) {
        sb.append(specialist.getFirstAndLastName());
    }
    if (sortBy != null && sortBy.equals(FacilityLicenseSummarySortBy.EXPIRE_DATE)) {
        sb.append(" - Expiration Order");
    } else {
        sb.append(" - Name Order");
    }

    table.addCell(new Phrase(sb.toString(), largefontB));

    // Add report date
    table.getDefaultCell().setPaddingLeft(2);
    table.getDefaultCell().setPaddingRight(4);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    table.getDefaultCell().setColspan(2);
    table.addCell(new Phrase(df.format(today), mediumfontB));

    if (endDate != null) {
        // Add expiration end date date
        table.getDefaultCell().setPaddingLeft(8);
        table.getDefaultCell().setPaddingRight(4);
        table.getDefaultCell().setPaddingBottom(4);
        table.getDefaultCell().setBorderWidthTop(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        table.getDefaultCell().setColspan(5);
        table.addCell(new Phrase("With Licenses Expiring " + df.format(endDate), mediumfontB));
    }

    // Add Facility Name column header
    table.getDefaultCell().setLeading(fixedLeading, 0);
    table.getDefaultCell().setPaddingLeft(4);
    table.getDefaultCell().setPaddingRight(2);
    table.getDefaultCell().setPaddingBottom(0);
    table.getDefaultCell().setBorderWidthTop(0.5f);
    table.getDefaultCell().setBorderWidthBottom(0);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM);
    table.getDefaultCell().setColspan(1);
    table.addCell(new Phrase("Facility Name", smallfontB));

    // Add License Number column header
    table.getDefaultCell().setPaddingLeft(2);
    table.addCell(new Phrase("License Number", smallfontB));

    // Add Service Code column header
    table.addCell(new Phrase("Service", smallfontB));

    // Add License Type column header
    table.addCell(new Phrase("License Type", smallfontB));

    // Add End Date column header
    table.getDefaultCell().setPaddingRight(4);
    table.addCell(new Phrase("End Date", smallfontB));

    return table;
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.LicenseRenewalsListReport.java

private static void writePdf(Person specialist, Date endDate, List<FacilityLicenseView> licenses,
        OutputStream ba) throws DocumentException, BadElementException {
    Document document = null;/*from   ww  w. j a  va  2  s.co  m*/
    PdfPTable doctable;
    PdfPTable datatable;
    PdfPTable factable;
    Paragraph paragraph;
    Facility facility;
    document = new Document(PageSize.A4);
    @SuppressWarnings("unused")
    PdfWriter writer = PdfWriter.getInstance(document, ba);

    document.open();

    doctable = getDocumentTable(specialist, endDate);

    if (licenses != null && licenses.size() > 0) {
        doctable.getDefaultCell().setPaddingBottom(4);
        doctable.getDefaultCell().setBorderWidthBottom(.5f);
        for (FacilityLicenseView license : licenses) {
            facility = license.getFacility();
            datatable = getDetailTable();
            datatable.getDefaultCell().setPaddingLeft(4);
            datatable.getDefaultCell().setPaddingRight(2);
            datatable.getDefaultCell().setColspan(1);
            // Add Facility Name information
            if (StringUtils.isNotBlank(license.getFacilityName())) {
                datatable.addCell(new Phrase(license.getFacilityName(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Number information
            datatable.getDefaultCell().setPaddingLeft(2);
            if (license.getLicenseNumber() != null) {
                datatable.addCell(new Phrase(license.getLicenseNumber().toString(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add Service Code information
            if (StringUtils.isNotBlank(license.getServiceCodeCode())) {
                datatable.addCell(new Phrase(license.getServiceCodeCode(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Type information
            if (StringUtils.isNotBlank(license.getSubtype())) {
                datatable.addCell(new Phrase(license.getSubtype(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }
            // Add License Expiration date information
            datatable.getDefaultCell().setPaddingRight(4);
            if (StringUtils.isNotBlank(license.getExpirationDateFormatted())) {
                datatable.addCell(new Phrase(license.getExpirationDateFormatted(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }

            // Add Mailing Location information
            sb = new StringBuilder();
            if (facility != null && facility.getMailingAddress() != null
                    && StringUtils.isNotBlank(facility.getMailingAddress().getAddressOne())) {
                sb.append(facility.getMailingAddress().getAddressOne());

                // add address two
                if (StringUtils.isNotBlank(facility.getMailingAddress().getAddressTwo())) {
                    if (sb.length() > 0) {
                        sb.append(" ");
                    }
                    sb.append(facility.getMailingAddress().getAddressTwo());
                }

                // Add city, state, zip
                if (StringUtils.isNotBlank(facility.getMailingAddress().getCityStateZip())) {
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append(facility.getMailingAddress().getCityStateZip());
                }
            }
            datatable.getDefaultCell().setColspan(5);
            datatable.getDefaultCell().setPaddingLeft(4);
            datatable.getDefaultCell().setPaddingRight(4);
            if (sb.length() > 0) {
                datatable.addCell(new Phrase(sb.toString().toUpperCase(), smallfont));
            } else {
                datatable.addCell(BLANK);
            }

            //
            // Add Facility details information
            // 
            factable = getFacilityDetailsTable();

            // Add primary phone information
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("Primary Phone: ", smallfontB));
            if (facility != null && facility.getPrimaryPhone() != null
                    && StringUtils.isNotBlank(facility.getPrimaryPhone().getFormattedPhoneNumber())) {
                paragraph.add(new Phrase(facility.getPrimaryPhone().getFormattedPhoneNumber(), smallfont));
            }
            factable.getDefaultCell().setPaddingLeft(4);
            factable.getDefaultCell().setPaddingRight(2);
            factable.addCell(paragraph);

            // Add SAFE Provider ID number
            paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("SAFE: ", smallfontB));
            if (facility != null && facility.getSafeProviderId() != null) {
                paragraph.add(new Phrase(facility.getSafeProviderId().toString(), smallfontB));
            }
            factable.getDefaultCell().setColspan(2);
            factable.addCell(paragraph);

            // Add the facility information table to the details table
            datatable.getDefaultCell().setPadding(0);
            datatable.addCell(factable);
            // Add the detail to the document table
            doctable.addCell(datatable);
        }
    } else {
        // No open applications
        datatable = getDetailTable();
        datatable.getDefaultCell().setPaddingTop(10);
        datatable.getDefaultCell().setColspan(3);
        datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        datatable.addCell(new Phrase("No licenses due for renewal were found to display.", smallfont));
        doctable.getDefaultCell().setPaddingBottom(0);
        doctable.getDefaultCell().setBorderWidthBottom(0);
        doctable.addCell(datatable);
    }

    // Add the document table to the document
    document.add(doctable);

    document.close();
}

From source file:gov.utah.dts.det.ccl.actions.reports.generators.LicenseRenewalsListReport.java

private static PdfPTable getHeaderTable(Person specialist, Date endDate) throws DocumentException {
    Date today = new Date();

    PdfPTable table = getDetailTable();

    // Add Page header information
    table.getDefaultCell().setLeading(largeFixedLeading, 0);
    table.getDefaultCell().setPaddingLeft(4);
    table.getDefaultCell().setPaddingRight(2);
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setBorderWidthTop(1.0f);
    table.getDefaultCell().setBorderWidthBottom(0);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.getDefaultCell().setColspan(3);
    sb = new StringBuilder();
    sb.append("Renewal Licenses for ");
    if (StringUtils.isNotBlank(specialist.getFirstAndLastName())) {
        sb.append(specialist.getFirstAndLastName());
    }//from   w ww.j a  v a 2s . c  o m
    table.addCell(new Phrase(sb.toString(), largefontB));

    // Add report date
    table.getDefaultCell().setPaddingLeft(2);
    table.getDefaultCell().setPaddingRight(4);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    table.getDefaultCell().setColspan(2);
    table.addCell(new Phrase(df.format(today), mediumfontB));

    // Add expiration end date date
    table.getDefaultCell().setPaddingLeft(8);
    table.getDefaultCell().setPaddingRight(4);
    table.getDefaultCell().setPaddingBottom(4);
    table.getDefaultCell().setBorderWidthTop(0);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.getDefaultCell().setColspan(5);
    table.addCell(new Phrase("With Licenses Expiring " + df.format(endDate), mediumfontB));

    // Add Facility Name column header
    table.getDefaultCell().setLeading(fixedLeading, 0);
    table.getDefaultCell().setPaddingLeft(4);
    table.getDefaultCell().setPaddingRight(2);
    table.getDefaultCell().setPaddingBottom(0);
    table.getDefaultCell().setBorderWidthTop(0.5f);
    table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM);
    table.getDefaultCell().setColspan(1);
    table.addCell(new Phrase("Facility Name", smallfontB));

    // Add License Number column header
    table.getDefaultCell().setPaddingLeft(2);
    table.addCell(new Phrase("License Number", smallfontB));

    // Add Service Code column header
    table.addCell(new Phrase("Service", smallfontB));

    // Add License Type column header
    table.addCell(new Phrase("License Type", smallfontB));

    // Add End Date column header
    table.getDefaultCell().setPaddingRight(4);
    table.addCell(new Phrase("End Date", smallfontB));

    return table;
}