Example usage for com.itextpdf.text Phrase setLeading

List of usage examples for com.itextpdf.text Phrase setLeading

Introduction

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

Prototype

public void setLeading(final float fixedLeading) 

Source Link

Usage

From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java

public PdfPTable onStartPage(String realPath, String scheduleNo, String unitNo, String voyContent)
        throws Exception {
    String path = LoadLogisoftProperties.getProperty("application.image.logo");
    Font fontArialBold = FontFactory.getFont("Arial", 10f, Font.BOLD);
    Font colorBoldFont = FontFactory.getFont("Arial", 12f, Font.BOLD, new BaseColor(00, 102, 00));
    Phrase p = null;
    Paragraph pValues = null;/*w w w .ja  v a2 s. c o  m*/
    table = new PdfPTable(6);
    table.setWidths(new float[] { 0.1f, 1.8f, 2.5f, 3.5f, 1.8f, 1.8f });
    table.setWidthPercentage(100f);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setRowspan(3);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setPadding(0f);
    cell.setBorder(0);
    cell.setPaddingBottom(3f);
    p = new Phrase("", fontArialBold);
    p.setLeading(20f);
    cell.addElement(p);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    pValues = new Paragraph(25f, "", fontArialBold);
    cell.addElement(pValues);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setRowspan(3);
    cell.setBorder(0);
    cell.setPadding(0f);
    Image img = Image.getInstance(realPath + path);
    img.scalePercent(60);
    img.setAlignment(Element.ALIGN_CENTER);
    img.setAlignment(Element.ALIGN_TOP);
    cell.addElement(img);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    pValues = new Paragraph(20f, "Date:", fontArialBold);
    pValues.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(pValues);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    pValues = new Paragraph(20f, " " + DateUtils.formatStringDateToAppFormatMMM(new Date()), fontArialBold);
    pValues.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(pValues);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setPadding(0f);
    cell.setBorder(0);
    cell.setPaddingBottom(3f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPaddingBottom(3f);
    cell.setPadding(0f);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    pValues = new Paragraph(9f, "Time:", fontArialBold);
    pValues.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(pValues);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    pValues = new Paragraph(9f, " " + DateUtils.formatStringDateToTimeTT(new Date()), fontArialBold);
    pValues.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(pValues);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setColspan(2);
    cell.setBorder(0);
    cell.setPadding(0f);
    cell.setPaddingBottom(3f);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.setColspan(2);
    cell.setBorder(0);
    cell.setPaddingBottom(3f);
    table.addCell(cell);
    //voyage
    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(3);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setPaddingLeft(5f);
    pValues = new Paragraph(8f, "VOYAGE NOTIFICATION", colorBoldFont);
    pValues.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(pValues);
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(0);
    cell.setColspan(2);
    table.addCell(cell);
    return table;
}

From source file:de.beimax.talenttree.AbstractPageGenerator.java

License:Open Source License

/**
 * Parse a string to PDF/itext phrase to be rendered later
 * @param key language key/* w w  w  .ja v  a2  s .co  m*/
 * @param fontSize size of font
 * @param narrowFonts use narrow fonts?
 * @return
 * @throws Exception
 */
protected Phrase parseTextProperty(String key, float fontSize, boolean narrowFonts) throws Exception {
    // define fonts
    Font fontRegular, fontBold;
    if (narrowFonts) {
        fontRegular = new Font(generator.getFontCondensedRegular(), fontSize);
        fontBold = new Font(generator.getFontCondensedBold(), fontSize);
    } else {
        fontRegular = new Font(generator.getFontRegular(), fontSize);
        fontBold = new Font(generator.getFontBold(), fontSize);
    }
    Font fontSymbol = new Font(generator.getFontSymbol(), fontSize);

    Phrase phrase = new Phrase();
    phrase.setLeading(fontSize * 1.2f);

    // get localized element
    String localized = getLocalizedString(key);
    for (String part : localized.split("\\|")) {
        if (part.length() == 0)
            continue; // make sure to not fire index out of range
        char first = part.charAt(0);
        char last = part.charAt(part.length() - 1);
        switch (first) {
        case '*': // bold
            part = part.substring(1); // remove first char
            if (last == ' ')
                part = part.substring(0, part.length() - 1);
            phrase.add(new Chunk(part, fontBold));
            if (last == ' ')
                phrase.add(new Chunk(" ", fontRegular));
            break;
        case '#': // symbol font
            part = part.substring(1); // remove first char
            if (last == ' ')
                part = part.substring(0, part.length() - 1);
            phrase.add(new Chunk(part, fontSymbol));
            if (last == ' ')
                phrase.add(new Chunk(" ", fontRegular));
            break;
        default: // all other cases
            phrase.add(new Chunk(part, fontRegular));
        }
    }

    return phrase;
}

From source file:eyeofthetiger.utils.PDFDossardGenerator.java

private Phrase createCleanPhrase(String txt1, float fontSize1, boolean bold1) {
    Phrase phrase = new Phrase(txt1);
    phrase.getFont().setSize(fontSize1);
    if (bold1) {/*  ww  w . ja  va  2  s . co  m*/
        phrase.getFont().setStyle(Font.BOLD);
        phrase.setLeading(fontSize1);
    }

    return phrase;
}

From source file:gov.utah.dts.det.ccl.actions.facility.information.license.reports.LicenseCertificate.java

private static void writePdf(License license, ByteArrayOutputStream ba, HttpServletRequest request)
        throws DocumentException, BadElementException {
    SimpleDateFormat df = new SimpleDateFormat("MMMM d, yyyy");
    StringBuilder sb;/*from   w w w.ja va 2  s . c o m*/

    // Retrieve the certificate template to use as watermark
    ServletContext context = request.getSession().getServletContext();
    String templatefile = context.getRealPath("/resources") + "/LicenseCertificateTemplate.pdf";
    PdfReader reader = getTemplateReader(templatefile);
    if (reader != null && reader.getNumberOfPages() > 0) {
        Phrase phrase;

        // Create new document using the page size of the certificate template document
        Document document = new Document(reader.getPageSizeWithRotation(1), 0, 0, 0, 0);
        PdfWriter writer = PdfWriter.getInstance(document, ba);
        document.open();

        // Get the writer under content byte for placing of watermark
        PdfContentByte under = writer.getDirectContentUnder();
        PdfContentByte over = writer.getDirectContent();

        // Retrieve the first page of the template document and wrap as an Image to use as new document watermark
        PdfImportedPage page = writer.getImportedPage(reader, 1);
        Image img = Image.getInstance(page);
        // Make sure the image has an absolute page position
        if (!img.hasAbsoluteX() || !img.hasAbsoluteY()) {
            img.setAbsolutePosition(0, 0);
        }

        under.addImage(img);

        /*
         * THE FOLLOWING TWO FUNCTION CALLS DISPLAY THE PAGE MARGINS AND TEXT COLUMN BORDERS FOR DEBUGGING TEXT PLACEMENT.
         * UNCOMMENT EACH FUNCTION CALL TO HAVE BORDERS DISPLAYED ON THE OUTPUT DOCUMENT.  THIS WILL HELP WHEN YOU NEED
         * TO SEE WHERE TEXT WILL BE PLACED ON THE CERTIFICATE FORM.
         */
        // Show the page margins
        //showPageMarginBorders(over);

        // Show the text column borders
        //showColumnBorders(over);

        ColumnText ct = new ColumnText(over);
        ct.setLeading(fixedLeading);

        // Add Facility Name to column
        String text = license.getFacility().getName();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Add Facility Site to column
        text = license.getFacility().getSiteName();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Add Facility Address to column
        text = license.getFacility().getLocationAddress().getAddressOne();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        text = license.getFacility().getLocationAddress().getCityStateZip();
        if (text != null) {
            phrase = new Phrase(text.toUpperCase(), mediumfontB);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }
        // Write column to document
        ct.setAlignment(Element.ALIGN_CENTER);
        ct.setSimpleColumn(COLUMNS[0][0], COLUMNS[0][1], COLUMNS[0][2], COLUMNS[0][3]);
        ct.go();

        // Add Certification Service Code to column
        ct = new ColumnText(over);
        ct.setLeading(fixedLeading);
        String service = "";
        if (license.getSpecificServiceCode() != null
                && StringUtils.isNotBlank(license.getSpecificServiceCode().getValue())
                && DV_TREATMENT.equalsIgnoreCase(license.getSpecificServiceCode().getValue())) {
            service += DOMESTIC_VIOLENCE;
        }
        if (!license.getProgramCodeIds().isEmpty()) { // redmine 25410
            mentalHealthLoop: for (PickListValue pkv : license.getProgramCodeIds()) {
                String program = pkv.getValue();
                int idx = program.indexOf(" -");
                if (idx >= 0) {
                    String code = program.substring(0, idx);
                    if (MENTAL_HEALTH_CODES.indexOf(code + ":") >= 0) {
                        if (service.length() > 0) {
                            service += " / ";
                        }
                        service += MENTAL_HEALTH;
                        break mentalHealthLoop;
                    }
                }
            }
            substanceAbuseLoop: for (PickListValue pkv : license.getProgramCodeIds()) {
                String program = pkv.getValue();
                int idx = program.indexOf(" -");
                if (idx >= 0) {
                    String code = program.substring(0, idx);
                    if (SUBSTANCE_ABUSE_CODES.indexOf(code + ":") >= 0) {
                        if (service.length() > 0) {
                            service += " / ";
                        }
                        service += SUBSTANCE_ABUSE;
                        break substanceAbuseLoop;
                    }
                }
            }
        }
        if (StringUtils.isNotBlank(license.getServiceCodeDesc())) {
            if (service.length() > 0) {
                service += " / ";
            }
            service += license.getServiceCodeDesc();
        }
        if (StringUtils.isNotEmpty(service)) {
            phrase = new Phrase(service.toUpperCase(), mediumfont);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
            ct.addText(Chunk.NEWLINE);
        }

        // Add CLIENTS Info to column
        sb = new StringBuilder("FOR ");
        if (license.getAgeGroup() == null
                || license.getAgeGroup().getValue().equalsIgnoreCase("Adult & Youth")) {
            // Adult & Youth
            if (license.getAdultTotalSlots() != null) {
                sb.append(license.getAdultTotalSlots().toString());
            }
            sb.append(" ADULT AND YOUTH CLIENTS");
        } else if (license.getAgeGroup().getValue().equalsIgnoreCase("Adult")) {
            // Adult
            if (license.getAdultTotalSlots() != null) {
                // Are male or female counts specified?
                sb.append(license.getAdultTotalSlots().toString());
                sb.append(" ADULT");
                if (license.getAdultFemaleCount() != null || license.getAdultMaleCount() != null) {
                    // Does either the male or female count equal the total slot count?
                    if ((license.getAdultFemaleCount() != null
                            && license.getAdultFemaleCount().equals(license.getAdultTotalSlots()))) {
                        sb.append(" FEMALE CLIENTS");
                    } else if (license.getAdultMaleCount() != null
                            && license.getAdultMaleCount().equals(license.getAdultTotalSlots())) {
                        sb.append(" MALE CLIENTS");
                    } else {
                        sb.append(" CLIENTS, ");
                        if (license.getAdultMaleCount() != null) {
                            sb.append(license.getAdultMaleCount().toString() + " MALE");
                        }
                        if (license.getAdultFemaleCount() != null) {
                            if (license.getAdultMaleCount() != null) {
                                sb.append(" AND ");
                            }
                            sb.append(license.getAdultFemaleCount().toString() + " FEMALE");
                        }
                        if (license.getFromAge() != null || license.getToAge() != null) {
                            sb.append(",");
                        }
                    }
                } else {
                    sb.append(" CLIENTS");
                }
            } else {
                sb.append(" ADULT CLIENTS");
            }
        } else {
            // Youth
            if (license.getYouthTotalSlots() != null) {
                // Are male or female counts specified?
                sb.append(license.getYouthTotalSlots().toString());
                sb.append(" YOUTH");
                if (license.getYouthFemaleCount() != null || license.getYouthMaleCount() != null) {
                    // Does either the male or female count equal the total slot count?
                    if ((license.getYouthFemaleCount() != null
                            && license.getYouthFemaleCount().equals(license.getYouthTotalSlots()))) {
                        sb.append(" FEMALE CLIENTS");
                    } else if (license.getYouthMaleCount() != null
                            && license.getYouthMaleCount().equals(license.getYouthTotalSlots())) {
                        sb.append(" MALE CLIENTS");
                    } else {
                        sb.append(" CLIENTS, ");
                        if (license.getYouthMaleCount() != null) {
                            sb.append(license.getYouthMaleCount().toString() + " MALE");
                        }
                        if (license.getYouthFemaleCount() != null) {
                            if (license.getYouthMaleCount() != null) {
                                sb.append(" AND ");
                            }
                            sb.append(license.getYouthFemaleCount().toString() + " FEMALE");
                        }
                        if (license.getFromAge() != null || license.getToAge() != null) {
                            sb.append(",");
                        }
                    }
                } else {
                    sb.append(" CLIENTS");
                }
            } else {
                sb.append(" YOUTH CLIENTS");
            }
        }
        if (license.getFromAge() != null || license.getToAge() != null) {
            sb.append(" AGES ");
            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());
            }
        }
        phrase = new Phrase(sb.toString(), mediumfont);
        phrase.setLeading(noLeading);
        ct.addText(phrase);
        ct.addText(Chunk.NEWLINE);

        // Add Certificate Comments
        if (StringUtils.isNotBlank(license.getCertificateComment())) {
            phrase = new Phrase(license.getCertificateComment().toUpperCase(), mediumfont);
            phrase.setLeading(noLeading);
            ct.addText(phrase);
        }

        // Write column to document
        ct.setAlignment(Element.ALIGN_CENTER);
        ct.setSimpleColumn(COLUMNS[1][0], COLUMNS[1][1], COLUMNS[1][2], COLUMNS[1][3]);
        ct.go();

        // Add Certificate Start Date
        if (license.getStartDate() != null) {
            phrase = new Phrase(df.format(license.getStartDate()), mediumfont);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[2][0], COLUMNS[2][1], COLUMNS[2][2], COLUMNS[2][3], fixedLeading,
                    Element.ALIGN_RIGHT);
            ct.go();
        }

        // Add Certificate End Date
        if (license.getEndDate() != null) {
            phrase = new Phrase(df.format(license.getEndDate()), mediumfont);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[3][0], COLUMNS[3][1], COLUMNS[3][2], COLUMNS[3][3], fixedLeading,
                    Element.ALIGN_LEFT);
            ct.go();
        }

        // Add License Number
        if (license.getLicenseNumber() != null) {
            phrase = new Phrase(license.getLicenseNumber().toString(), largefontB);
            phrase.setLeading(noLeading);
            ct = new ColumnText(over);
            ct.setSimpleColumn(phrase, COLUMNS[4][0], COLUMNS[4][1], COLUMNS[4][2], COLUMNS[4][3],
                    numberLeading, Element.ALIGN_CENTER);
            ct.go();
        }
        document.close();
    }
}