Example usage for com.lowagie.text Phrase Phrase

List of usage examples for com.lowagie.text Phrase Phrase

Introduction

In this page you can find the example usage for com.lowagie.text Phrase Phrase.

Prototype

public Phrase(float leading, String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

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/*from  www  .j  a v a 2s . c o  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.");
    }//w ww.  j ava 2  s .com

    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);
    }
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

private void renderObject(final ExportSheet exportSheet, final Table datatable) throws BadElementException {
    final Font labelFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font valueFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);

    for (final ExportField exportColumn : exportSheet.getExportFields()) {
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), labelFont));

        datatable.getDefaultCell().setBorderWidth(1);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        final DtField dtField = exportColumn.getDtField();
        final Object value = dtField.getDataAccessor().getValue(exportSheet.getDtObject());
        final int horizontalAlignement;
        if (value instanceof Number || value instanceof Date) {
            horizontalAlignement = Element.ALIGN_RIGHT;
        } else if (value instanceof Boolean) {
            horizontalAlignement = Element.ALIGN_CENTER;
        } else {/*from w w w .  j av  a 2s. c o m*/
            horizontalAlignement = Element.ALIGN_LEFT;
        }
        datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

        String text = ExportUtil.getText(persistenceManager, referenceCache, denormCache,
                exportSheet.getDtObject(), exportColumn);
        if (text == null) {
            text = "";
        }
        datatable.addCell(new Phrase(8, text, valueFont));
    }
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu des headers.//ww w  .ja  v  a 2 s. c  o m
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private static void renderHeaders(final ExportSheet parameters, final Table datatable)
        throws BadElementException {
    // size of columns
    // datatable.setWidths(headerwidths);
    // datatable.setWidth(100f);

    // table header
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    // datatable.getDefaultCell().setGrayFill(0.75f);

    for (final ExportField exportColumn : parameters.getExportFields()) {
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:io.vertigo.dynamo.plugins.export.rtf.RTFExporter.java

License:Apache License

/** {@inheritDoc} */
@Override/*from w w w  .ja  va 2  s . com*/
protected void createWriter(final Document document, final OutputStream out) {
    // final RtfWriter2 writer =
    RtfWriter2.getInstance(document, out);
    // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

    // advanced page numbers : x/y
    final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
    //-----
    final Paragraph footerParagraph = new Paragraph();
    footerParagraph.add(new RtfPageNumber(font));
    footerParagraph.add(new Phrase(" / ", font));
    footerParagraph.add(new RtfTotalPageNumber(font));
    footerParagraph.setAlignment(Element.ALIGN_CENTER);
    //-----
    final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
    footer.setBorder(Rectangle.TOP);
    document.setFooter(footer);
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

private void renderObject(final ExportSheet exportSheet, final Table datatable) throws BadElementException {
    final Font labelFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font valueFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);

    for (final ExportField exportColumn : exportSheet.getExportFields()) {
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), labelFont));

        datatable.getDefaultCell().setBorderWidth(1);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        final DtField dtField = exportColumn.getDtField();
        final Object value = dtField.getDataAccessor().getValue(exportSheet.getDtObject());
        final int horizontalAlignement;
        if (value instanceof Number || value instanceof LocalDate || value instanceof Instant) {
            horizontalAlignement = Element.ALIGN_RIGHT;
        } else if (value instanceof Boolean) {
            horizontalAlignement = Element.ALIGN_CENTER;
        } else {//from   w w  w .  j a  va 2s .co  m
            horizontalAlignement = Element.ALIGN_LEFT;
        }
        datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

        String text = ExportUtil.getText(storeManager, referenceCache, denormCache, exportSheet.getDtObject(),
                exportColumn);
        if (text == null) {
            text = "";
        }
        datatable.addCell(new Phrase(8, text, valueFont));
    }
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu des headers./*from w  ww .  j  a va 2  s  .  c  om*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private static void renderHeaders(final ExportSheet parameters, final Table datatable)
        throws BadElementException {
    // table header
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    for (final ExportField exportColumn : parameters.getExportFields()) {
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:io.vertigo.quarto.plugins.export.rtf.RTFExporter.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  www  .  ja v  a2  s .  c  om*/
protected void createWriter(final Document document, final OutputStream out) {
    RtfWriter2.getInstance(document, out);

    // advanced page numbers : x/y
    final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
    //-----
    final Paragraph footerParagraph = new Paragraph();
    footerParagraph.add(new RtfPageNumber(font));
    footerParagraph.add(new Phrase(" / ", font));
    footerParagraph.add(new RtfTotalPageNumber(font));
    footerParagraph.setAlignment(Element.ALIGN_CENTER);
    //-----
    final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
    footer.setBorder(Rectangle.TOP);
    document.setFooter(footer);
}

From source file:is.idega.idegaweb.egov.cases.business.CaseWriter.java

License:Open Source License

protected MemoryFileBuffer writePDF(IWContext iwc) {
    Font titleFont = new Font(Font.HELVETICA, 14, Font.BOLD);
    Font labelFont = new Font(Font.HELVETICA, 11, Font.BOLD);
    Font textFont = new Font(Font.HELVETICA, 11, Font.NORMAL);

    try {/*from  w w  w.  j  av  a  2  s . co m*/
        MemoryFileBuffer buffer = new MemoryFileBuffer();
        MemoryOutputStream mos = new MemoryOutputStream(buffer);

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter.getInstance(document, mos);
        document.addAuthor("Idegaweb eGov");
        document.addSubject("Case");
        document.open();
        document.newPage();

        String title = iwrb.getLocalizedString("case_overview", "Case overview");
        Paragraph cTitle = new Paragraph(title, titleFont);
        cTitle.setSpacingAfter(24);
        document.setPageCount(1);
        document.add(cTitle);

        int[] widths = { 25, 75 };
        PdfPTable table = new PdfPTable(2);
        table.setWidths(widths);
        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setPaddingBottom(8);

        CaseCategory category = theCase.getCaseCategory();
        CaseCategory parentCategory = category.getParent();
        CaseType type = theCase.getCaseType();
        User user = theCase.getOwner();
        Address address = user != null ? getUserBusiness(iwc).getUsersMainAddress(user) : null;
        PostalCode postal = null;
        if (address != null) {
            postal = address.getPostalCode();
        }
        Phone phone = null;
        if (user != null) {
            try {
                phone = getUserBusiness(iwc).getUsersHomePhone(user);
            } catch (NoPhoneFoundException e) {
                //No phone found...
            }
        }
        Email email = null;
        if (user != null) {
            try {
                email = getUserBusiness(iwc).getUsersMainEmail(user);
            } catch (NoEmailFoundException e) {
                //No email found...
            }
        }

        IWTimestamp created = new IWTimestamp(theCase.getCreated());

        if (user != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("name", "Name"), labelFont));
            table.addCell(new Phrase(
                    new Name(user.getFirstName(), user.getMiddleName(), user.getLastName()).getName(locale),
                    textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("personal_id", "Personal ID"), labelFont));
            table.addCell(new Phrase(PersonalIDFormatter.format(user.getPersonalID(), locale), textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("address", "Address"), labelFont));
            table.addCell(new Phrase(address != null ? address.getStreetAddress() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("zip_code", "Postal code"), labelFont));
            table.addCell(new Phrase(postal != null ? postal.getPostalAddress() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("home_phone", "Home phone"), labelFont));
            table.addCell(new Phrase(phone != null ? phone.getNumber() : "-", textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("email", "Email"), labelFont));
            table.addCell(new Phrase(email != null ? email.getEmailAddress() : "-", textFont));

            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
            table.addCell(new Phrase(""));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("case_nr", "Case nr."), labelFont));
        table.addCell(new Phrase(theCase.getPrimaryKey().toString(), textFont));

        if (getCasesBusiness(iwc).useTypes()) {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_type", "Case type"), labelFont));
            table.addCell(new Phrase(type.getName(), textFont));
        }

        if (parentCategory != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont));
            table.addCell(new Phrase(parentCategory.getLocalizedCategoryName(locale), textFont));

            table.addCell(new Phrase(iwrb.getLocalizedString("sub_case_category", "Case category"), labelFont));
            table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont));
        } else {
            table.addCell(new Phrase(iwrb.getLocalizedString("case_category", "Case category"), labelFont));
            table.addCell(new Phrase(category.getLocalizedCategoryName(locale), textFont));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("created_date", "Created date"), labelFont));
        table.addCell(new Phrase(created.getLocaleDateAndTime(locale, IWTimestamp.SHORT, IWTimestamp.SHORT),
                textFont));

        if (theCase.getSubject() != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("subject", "Subject"), labelFont));
            table.addCell(new Phrase(theCase.getSubject(), textFont));
        }

        table.addCell(new Phrase(iwrb.getLocalizedString("message", "Message"), labelFont));
        table.addCell(new Phrase(theCase.getMessage(), textFont));

        if (theCase.getReference() != null) {
            table.addCell(new Phrase(iwrb.getLocalizedString("reference", "Reference"), labelFont));
            table.addCell(new Phrase(theCase.getReference(), textFont));
        }

        table.setWidthPercentage(100);
        document.add(table);

        document.close();
        try {
            mos.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        buffer.setMimeType("application/pdf");
        return buffer;

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private int createPasswordLetterContent(DocumentPrintContext dpc) throws ContentCreationException {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    System.out.println("Default locale: "
            + getIWApplicationContext().getApplicationSettings().getDefaultLocale().toString());
    String sAddrString = "";
    PdfContentByte cb = dpc.getPdfWriter().getDirectContent();
    Document document = dpc.getDocument();
    Locale locale = dpc.getLocale();
    PrintMessage msg = dpc.getMessage();
    // String mail_zip = iwb.getProperty("commune.mail_zip");
    // String mail_name = iwb.getProperty("commune.mail_name");

    try {/*from w  ww. j ava 2 s  .  c o  m*/
        sAddrString = getAddressString(dpc.getMessage().getOwner());
    } catch (Exception nouser) {
        handleNoAddressUser();
        System.err.println(nouser.getMessage());
        // nouser.printStackTrace();
        return ADDRESS_ERROR;
    }
    try {
        if (addTemplateHeader()) {
            ColumnText ct = new ColumnText(cb);
            float margin = getPointsFromMM(14);
            float lly = getPointsFromMM(297 - 22);
            float ury = lly + 60f;
            float urx = 595f - margin - 60f - 5f;
            float llx = 110f + margin;
            Phrase Ph0 = new Phrase(sAddrString, new Font(Font.HELVETICA, 12, Font.BOLD));
            ct.setSimpleColumn(Ph0, llx, lly, urx, ury, 15, Element.ALIGN_LEFT);
            ct.go();

            document.add(new Paragraph("\n\n\n\n\n\n\n"));
        }

        {

            User owner = msg.getOwner();
            HashMap tagmap = new CommuneUserTagMap(getIWApplicationContext(), owner);
            tagmap.putAll(getMessageTagMap(msg, locale));

            XmlPeer date = new XmlPeer(ElementTags.CHUNK, "date");
            date.setContent(new IWTimestamp().getDateString("dd.MM.yyyy"));
            tagmap.put(date.getAlias(), date);
            System.out.println("Date tag: " + date.getTag());

            String letterUrl = getXMLLetterUrl(iwb, locale, "password_letter.xml");
            if (msg.getBody().indexOf("|") > 0) {
                StringTokenizer tokenizer = new StringTokenizer(msg.getBody(), "|");
                XmlPeer peer = new XmlPeer(ElementTags.ITEXT, "letter");
                tagmap.put(peer.getAlias(), peer);

                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "username");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }
                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "password");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }

            }
            javax.xml.parsers.SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            SAXmyHandler handler = new SAXmyHandler(document, tagmap);
            handler.setControlOpenClose(false);

            parser.parse(letterUrl, handler);
        }
    } catch (Exception e) {
        throw new ContentCreationException(e);
    }

    return 0;
}