Example usage for com.lowagie.text.pdf PdfPTable addCell

List of usage examples for com.lowagie.text.pdf PdfPTable addCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable addCell.

Prototype

public void addCell(Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:gov.medicaid.binders.MemberInfoFormBinder.java

License:Apache License

@Override
public void renderPDF(EnrollmentType enrollment, Document document, Map<String, Object> model)
        throws DocumentException {
    String ns = NAMESPACE;//  w  w w  . j av a  2 s .c o  m
    if ("Y".equals(PDFHelper.value(model, ns, "bound"))) {
        // License Info Section
        PdfPTable membersInfo = new PdfPTable(new float[] { 5, 65 });
        membersInfo.getDefaultCell().setBorder(0);
        membersInfo.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        membersInfo.setTotalWidth(72 * 7);
        membersInfo.setLockedWidth(true);

        int size = Integer.parseInt(PDFHelper.value(model, ns, "memberSize"));
        for (int i = 0; i < size; i++) {
            PDFHelper.addCenterCell(membersInfo, String.valueOf(i + 1));
            PdfPTable memberDetail = new PdfPTable(2);
            PDFHelper.addLabelValueCell(memberDetail, "NPI", PDFHelper.value(model, ns, "npi", i));
            PDFHelper.addLabelValueCell(memberDetail, "Provider Type",
                    PDFHelper.value(model, ns, "providerType", i));
            PDFHelper.addLabelValueCell(memberDetail, "Name", PDFHelper.value(model, ns, "name", i));
            PDFHelper.addLabelValueCell(memberDetail, "Date Of Birth", PDFHelper.value(model, ns, "dob", i));
            PDFHelper.addLabelValueCell(memberDetail, "SSN", PDFHelper.value(model, ns, "ssn", i));
            PDFHelper.addLabelValueCell(memberDetail, "Start Date", PDFHelper.value(model, ns, "startDate", i));
            membersInfo.addCell(memberDetail);
            membersInfo.completeRow();
        }
        document.add(membersInfo);
    }

}

From source file:gov.medicaid.binders.OrganizationInfoFormBinder.java

License:Apache License

@Override
public void renderPDF(EnrollmentType enrollment, Document document, Map<String, Object> model)
        throws DocumentException {

    String ns = NAMESPACE;/*from   www  .j  a va  2 s  . c o m*/
    if (!"Y".equals(PDFHelper.value(model, ns, "bound"))) {
        return;
    }

    ViewModel viewModel = (ViewModel) model.get("viewModel");
    UITabModel tabModel = viewModel.getTabModels().get(ViewStatics.ORGANIZATION_INFO);
    Map<String, Object> settings = tabModel.getFormSettings().get(ViewStatics.ORG_INFO_FORM).getSettings();
    boolean useEDILayout = false;
    if (settings != null && settings.get("useEDILayout") instanceof Boolean) {
        useEDILayout = (Boolean) settings.get("useEDILayout");
    }

    // Personal Info Section
    PdfPTable personalInfo = new PdfPTable(2);
    PDFHelper.setTableAsFullPage(personalInfo);

    if (useEDILayout) {
        PDFHelper.addLabelValueCell(personalInfo, "EDI Type", PDFHelper.value(model, ns, "subType"));
    }

    PDFHelper.addLabelValueCell(personalInfo, "NPI/UMPI", PDFHelper.value(model, ns, "npi"));
    PDFHelper.addLabelValueCell(personalInfo, "Effective Date", PDFHelper.value(model, ns, "effectiveDate"));
    PDFHelper.addLabelValueCell(personalInfo, "Organization Name", PDFHelper.value(model, ns, "name"));
    PDFHelper.addLabelValueCell(personalInfo, "Legal Name", PDFHelper.value(model, ns, "legalName"));
    PDFHelper.addLabelValueCell(personalInfo, "FEIN", PDFHelper.value(model, ns, "fein"));
    PDFHelper.addLabelValueCell(personalInfo, "State Tax ID", PDFHelper.value(model, ns, "stateTaxId"));
    PDFHelper.addLabelValueCell(personalInfo, "Fiscal Year End", PDFHelper.getFiscalYear(model, ns));

    PDFHelper.addLabelValueCell(personalInfo, "Address", PDFHelper.getAddress(model, ns, null));
    PDFHelper.addLabelValueCell(personalInfo, "Phone Number", PDFHelper.getPhone(model, ns, "phone"));
    PDFHelper.addLabelValueCell(personalInfo, "Fax Number", PDFHelper.getPhone(model, ns, "fax"));
    PDFHelper.addLabelValueCell(personalInfo, "Name Of Person Completing Form",
            PDFHelper.value(model, ns, "personCompletingForm"));

    if (!useEDILayout) {
        if ("Y".equals(PDFHelper.value(model, ns, "billingSameAsPrimary"))) {
            PDFHelper.addLabelValueCell(personalInfo, "Billing Address", "Same As Above");
        } else {
            PDFHelper.addLabelValueCell(personalInfo, "Billing Address",
                    PDFHelper.getAddress(model, ns, "billing"));
        }

        if ("Y".equals(PDFHelper.value(model, ns, "ten99SameAsPrimary"))) {
            PDFHelper.addLabelValueCell(personalInfo, "1099 Address", "Same As Above");
        } else {
            PDFHelper.addLabelValueCell(personalInfo, "1099 Address", PDFHelper.getAddress(model, ns, "ten99"));
        }
    }

    document.add(personalInfo);

    PdfPTable contactInfo = new PdfPTable(2); // 2 columns of key value pairs
    PDFHelper.setTableAsFullPage(contactInfo);

    contactInfo.addCell(PDFHelper.createHeaderCell("Contact Information", 2));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Name", PDFHelper.value(model, ns, "contactName"));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Phone Number",
            PDFHelper.getPhone(model, ns, "contactPhone"));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Fax Number", PDFHelper.getPhone(model, ns, "contactFax"));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Email Address",
            PDFHelper.value(model, ns, "contactEmail"));

    document.add(contactInfo);
}

From source file:gov.medicaid.binders.PersonalInformationFormBinder.java

License:Apache License

/**
 * Renders this form as a PDF./*from   w ww  .java2 s.c  om*/
 * 
 * @param enrollment the enrollment to be rendered
 * @param document the PDF document to render on
 * @param model the view model
 */
@Override
public void renderPDF(EnrollmentType enrollment, Document document, Map<String, Object> model)
        throws DocumentException {
    String ns = NAMESPACE;
    if (!"Y".equals(PDFHelper.value(model, ns, "bound"))) {
        return;
    }

    // Personal Info Section
    PdfPTable personalInfo = new PdfPTable(2);
    PDFHelper.setTableAsFullPage(personalInfo);

    PDFHelper.addLabelValueCell(personalInfo, "Last Name", PDFHelper.value(model, ns, "lastName"));
    PDFHelper.addLabelValueCell(personalInfo, "First Name", PDFHelper.value(model, ns, "firstName"));
    PDFHelper.addLabelValueCell(personalInfo, "Middle Name", PDFHelper.value(model, ns, "middleName"));

    PDFHelper.addLabelValueCell(personalInfo, "NPI", PDFHelper.value(model, ns, "npi"));
    PDFHelper.addLabelValueCell(personalInfo, "Social Security Number", PDFHelper.value(model, ns, "ssn"));
    PDFHelper.addLabelValueCell(personalInfo, "Date of Birth", PDFHelper.value(model, ns, "dob"));
    PDFHelper.addLabelValueCell(personalInfo, "Individual Practitioner's Email",
            PDFHelper.value(model, ns, "email"));
    document.add(personalInfo);

    PdfPTable contactInfo = new PdfPTable(2); // 2 columns of key value pairs
    PDFHelper.setTableAsFullPage(contactInfo);

    contactInfo.addCell(PDFHelper.createHeaderCell("Contact Information", 2));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Name", PDFHelper.value(model, ns, "contactName"));
    PDFHelper.addLabelValueCell(contactInfo, "Contact Email Address",
            PDFHelper.value(model, ns, "contactEmail"));

    document.add(contactInfo);
}

From source file:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Adds a centered cell to the given table.
 * /*  w w w  . j a  v a2  s.  c  o  m*/
 * @param table
 *            the table to add the cell to
 * @param value
 *            the value text
 */
private static void addCenterCell(PdfPTable table, String value) {
    PdfPCell val = new PdfPCell(
            new Phrase(Util.defaultString(value), FontFactory.getFont(FontFactory.HELVETICA, 7)));
    val.setBorder(Rectangle.NO_BORDER);
    val.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    table.addCell(val);
}

From source file:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Exports the search results into PDF.//from w w  w  .  j a  v  a  2 s.  c  om
 * 
 * @param requests
 *            the list to be exported
 * @param status
 *            the status filter
 * @param outputStream
 *            the stream to export to
 * @throws PortalServiceException
 *             for any errors encountered
 */
public void export(List<UserRequest> requests, String status, OutputStream outputStream)
        throws PortalServiceException {
    PdfPTable resultTable;
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, outputStream);
        document.open();

        resultTable = new PdfPTable(new float[] { 3, 8, 8, 8, 10, 25, 8, 8, 8 });
        resultTable.getDefaultCell().setBorder(0);
        resultTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        resultTable.setTotalWidth(72 * 7);
        resultTable.setLockedWidth(true);

        resultTable.addCell(createHeaderCell("Enrollments", 9));
        resultTable.completeRow();

        addCenterCell(resultTable, "#");
        addCenterCell(resultTable, "NPI/UMPI");
        addCenterCell(resultTable, "Date Created");
        addCenterCell(resultTable, "Request Type");
        addCenterCell(resultTable, "Provider Type");
        addCenterCell(resultTable, "Provider Name");
        addCenterCell(resultTable, "Risk Level");
        addCenterCell(resultTable, "Status");
        addCenterCell(resultTable, "Status Date");
        resultTable.completeRow();

        int i = 0;
        for (UserRequest userRequest : requests) {
            addCenterCell(resultTable, String.valueOf(++i));
            addCenterCell(resultTable, userRequest.getNpi());
            addCenterCell(resultTable,
                    BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getCreateDate())));
            addCenterCell(resultTable, userRequest.getRequestType());
            addCenterCell(resultTable, userRequest.getProviderType());
            addCenterCell(resultTable, userRequest.getProviderName());
            addCenterCell(resultTable, userRequest.getRiskLevel());
            addCenterCell(resultTable, userRequest.getStatus());
            addCenterCell(resultTable,
                    BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getStatusDate())));
        }

        resultTable.setSpacingAfter(20);
        document.add(resultTable);

        document.close();
    } catch (DocumentException e) {
        throw new PortalServiceException("Export failed, see log for additional details.", e);
    }
}

From source file:gov.medicaid.services.impl.ExportServiceBean.java

License:Apache License

/**
 * Renders the ticket./*  ww w. j a va 2s .  co  m*/
 * 
 * @param enrollment
 *            the enrollment
 * @param document
 *            the document to render to
 * @param model
 *            the view model
 * @throws IOException
 *             for read/write errors
 * @throws DocumentException
 *             for PDF related errors
 * @throws PortalServiceException
 *             for any other errors encountered
 */
private void renderTicket(EnrollmentType enrollment, Document document, Map<String, Object> model)
        throws PortalServiceException, DocumentException, IOException {

    CMSConfigurator config = new CMSConfigurator();
    PresentationService presentationService = config.getPresentationService();
    Map<String, FormBinder> registry = config.getBinderRegistry();
    ViewModel viewModel = presentationService.getProviderViewModel(enrollment.getProviderInformation());

    Map<String, UITabModel> pageModels = viewModel.getTabModels();

    // render all forms from all pages
    for (String page : viewModel.getTabNames()) {
        if (page.equals(ViewStatics.SUMMARY_INFORMATION)) {
            continue;
        }

        PdfPTable pageTitle = new PdfPTable(2);
        setTableAsFullPage(pageTitle);
        pageTitle.addCell(createHeaderCell(page, 2));
        document.add(pageTitle);
        UITabModel pageModel = pageModels.get(page);
        List<String> formNames = pageModel.getFormNames();
        for (String form : formNames) {
            FormBinder binder = registry.get(form);
            if (binder != null) {
                binder.renderPDF(enrollment, document, model);
            }
        }
    }
}

From source file:gov.medicaid.services.util.PDFHelper.java

License:Apache License

/**
 * Adds a label to the given table./*from   w  ww.j  a  v  a 2  s  .c  o  m*/
 *
 * @param table the table to add to
 * @param label the label text
 */
public static void addLabel(PdfPTable table, String label) {
    PdfPCell key = new PdfPCell(
            new Phrase(Util.defaultString(label), FontFactory.getFont(FontFactory.HELVETICA_BOLD, 8)));
    key.setBorder(Rectangle.NO_BORDER);
    table.addCell(key);
}

From source file:gov.medicaid.services.util.PDFHelper.java

License:Apache License

/**
 * Adds a cell to the given table.//from   w  w w.  j a va  2  s. c  o  m
 *
 * @param table the table to add the cell to
 * @param value the value text
 */
public static void addCell(PdfPTable table, String value) {
    PdfPCell val = new PdfPCell(
            new Phrase(": " + Util.defaultString(value), FontFactory.getFont(FontFactory.HELVETICA, 7)));
    val.setBorder(Rectangle.NO_BORDER);
    val.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    table.addCell(val);
}

From source file:gov.medicaid.services.util.PDFHelper.java

License:Apache License

/**
 * Adds a centered cell to the given table.
 *
 * @param table the table to add the cell to
 * @param value the value text//  w w w . jav  a 2  s . co  m
 */
public static void addCenterCell(PdfPTable table, String value) {
    PdfPCell val = new PdfPCell(
            new Phrase(Util.defaultString(value), FontFactory.getFont(FontFactory.HELVETICA, 7)));
    val.setBorder(Rectangle.NO_BORDER);
    val.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    val.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
    table.addCell(val);
}

From source file:gov.utah.dts.det.ccl.documents.templating.templates.AbstractCaseloadTemplate.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor)
        throws TemplateException {
    Long specialistId = (Long) context.get("specId");
    if (specialistId == null) {
        throw new TemplateException("Specialist id is required.");
    }//from w w  w  .  j  a va 2s .  co m

    CaseloadSortBy sortBy = CaseloadSortBy.getDefaultSortBy();
    String sortByStr = (String) context.get("sortBy");
    if (sortByStr != null) {
        sortBy = CaseloadSortBy.valueOf(sortByStr);
    }

    Person specialist = personService.getPerson(specialistId);
    context.put(SPECIALIST_KEY, specialist);

    List<FacilityCaseloadView> caseload = getCaseload(specialistId, sortBy);

    setFileName(context, descriptor);

    try {
        Document document = new Document(PageSize.LETTER.rotate(), MARGIN, MARGIN, MARGIN, MARGIN);
        PdfWriter.getInstance(document, outputStream);

        document.open();

        document.add(new Paragraph(getReportTitle() + " for " + specialist.getFirstAndLastName(), FONT));
        //columns: name, facility id, address, phone, 1st director(s), status, type, capacity (<2)

        PdfPTable table = new PdfPTable(8);
        table.setWidths(new float[] { 23f, 25f, 11f, 13f, 5f, 9f, 7f, 7f });
        table.setWidthPercentage(100);
        table.setSpacingBefore(FONT_SIZE);

        table.getDefaultCell().setPadding(TABLE_CELL_PADDING);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setBorderWidthBottom(.5f);
        table.setHeaderRows(1);

        table.addCell(new Phrase("Facility Name", HEADER_FONT));
        table.addCell(new Phrase("Address", HEADER_FONT));
        table.addCell(new Phrase("Phone", HEADER_FONT));
        table.addCell(new Phrase("1st Director(s)", HEADER_FONT));
        table.addCell(new Phrase("Type", HEADER_FONT));
        table.addCell(new Phrase("Exp Dt", HEADER_FONT));
        table.addCell(new Phrase("Adult Cap", HEADER_FONT));
        table.addCell(new Phrase("Youth Cap", HEADER_FONT));

        boolean hasInProcess = false;

        for (FacilityCaseloadView fcv : caseload) {
            if (fcv.getStatus() == FacilityStatus.REGULATED || fcv.getStatus() == FacilityStatus.IN_PROCESS) {
                StringBuilder name = new StringBuilder();
                if (fcv.getStatus() == FacilityStatus.IN_PROCESS) {
                    hasInProcess = true;
                    name.append("* ");
                }
                name.append(fcv.getName());

                table.addCell(new Phrase(name.toString(), FONT));
                table.addCell(new Phrase(fcv.getLocationAddress().toString(), FONT));
                table.addCell(new Phrase(fcv.getPrimaryPhone().getFormattedPhoneNumber(), FONT));
                table.addCell(new Phrase(fcv.getDirectorNames(), FONT));

                String typeAbbrev = null;
                /*
                               if (fcv.getLicenseType() != null) {
                                  typeAbbrev = applicationService.getApplicationPropertyValue("facility.license.type." + fcv.getLicenseType().getId()+ ".abbrev");
                               }
                */
                table.addCell(new Phrase(typeAbbrev != null ? typeAbbrev : "", FONT));
                //               table.addCell(new Phrase(fcv.getExpirationDate() != null ? DATE_FORMATTER.format(fcv.getExpirationDate()) : "", FONT));
                table.addCell(new Phrase("", FONT));

                //               if (fcv.getAdultTotalSlots() == null) {
                table.addCell(new Phrase(""));
                //               } else {
                //                  table.addCell(new Phrase(fcv.getAdultTotalSlots().toString(), FONT));
                //               }
                //               if (fcv.getYouthTotalSlots() == null) {
                table.addCell(new Phrase(""));
                //               } else {
                //                  table.addCell(new Phrase(fcv.getYouthTotalSlots().toString(), FONT));
                //               }
            }
        }

        document.add(table);
        if (hasInProcess) {
            document.add(new Paragraph(
                    "* - Facility is in the process of becoming a regulated child care facility.", FONT));
        }

        document.close();
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
}