Example usage for com.lowagie.text Font setStyle

List of usage examples for com.lowagie.text Font setStyle

Introduction

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

Prototype

public void setStyle(String style) 

Source Link

Document

Sets the style using a String containing one of more of the following values: normal, bold, italic, underline, strike.

Usage

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private Font createLinkFont() {
    /*//from  ww  w .j  a  v a 2  s .c om
     * Font for anchors (links)
     */
    Font linkFont = new Font();
    linkFont.setStyle(Font.UNDERLINE);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(linkFontSize);

    return linkFont;
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private Font createHeaderFont() {
    /*// w ww .j  a  v a2s  .c o  m
     * Font for the headers
     */
    Font headerFont = new Font();
    headerFont.setStyle(Font.BOLD);
    headerFont.setSize(headerFontSize);

    return headerFont;
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private void addReplyLink(Document document, String replyURL) throws DocumentException {
    PdfPTable replyTable = new PdfPTable(1);
    replyTable.setWidthPercentage(100f);

    replyTable.setSplitLate(false);//w  w w .j av  a2 s  .co  m

    replyTable.setSpacingBefore(5f);
    replyTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    Font linkFont = new Font();

    linkFont.setStyle(Font.BOLD);
    linkFont.setColor(0, 0, 255);
    linkFont.setSize(headerFontSize);

    Chunk anchor = new Chunk("Reply", linkFont);

    anchor.setAnchor(replyURL);

    Phrase phrase = new Phrase();

    phrase.add(anchor);

    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(Rectangle.NO_BORDER);

    replyTable.addCell(cell);

    document.add(replyTable);
}

From source file:nl.dykema.jxmlnote.report.pdf.PdfChunk.java

License:Open Source License

public void setFont(Font g) {
    Font f = new Font(g);
    int chst = 0;
    if (_bold) {//  ww  w.  j a v a 2  s  .co m
        chst += Font.BOLD;
    }
    if (_italic) {
        chst += Font.ITALIC;
    }
    if (_underline) {
        chst += Font.UNDERLINE;
    }
    f.setStyle(chst);
    super.setFont(f);
}

From source file:nl.dykema.jxmlnote.report.pdf.PdfParagraph.java

License:Open Source License

public Paragraph setStyle(XMLNoteParStyle style) {
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    _style = style;/*  ww w  .ja v  a2  s  . c  om*/
    if (style == null) {
        return this;
    }

    int chst = 0;
    if (style.bold()) {
        chst += Font.BOLD;
    }
    if (style.italics()) {
        chst += Font.ITALIC;
    }
    if (style.underline()) {
        chst += Font.UNDERLINE;
    }
    Font f = getFont(style.getFont());
    f.setSize(style.pointSize());
    f.setStyle(chst);
    float indentleft;
    indentleft = (float) style.leftIndent();
    super.setIndentationLeft(indentleft);
    super.setSpacingAfter(style.bottomSkip());
    super.setSpacingBefore(style.topSkip());
    //super.setLeading(0.0f); DO DIT NIET!

    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    int p1align = getAlign(style);
    super.setAlignment(p1align);
    super.setFont(f);
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());
    super.setLeading(0.0f, 1.2f);
    //System.out.println(super.getLeading()+","+super.getMultipliedLeading());

    return this;
}

From source file:org.apache.maven.doxia.module.itext.ITextFont.java

License:Apache License

/**
 * Convenience method to get a defined font depending the wanted style and size.
 *
 * @param style the font style.//from  w ww . j  a  v  a2s  .com
 * @param size the font size.
 * @param color the font color.
 * @return a font the font.
 */
public static Font getFont(int style, float size, Color color) {
    Font font = new Font();
    font.setFamily(DEFAULT_FONT_NAME);
    font.setStyle(style);
    font.setSize(size);
    font.setColor(color);
    return font;
}

From source file:org.areasy.common.doclet.document.tags.TagA.java

License:Open Source License

protected Chunk createChunk(String text) {
    Chunk chunk = new Chunk(text);

    Font font = chunk.font();
    font.setStyle(Font.NORMAL);
    font.setColor(Color.blue);//from w w  w . j  a  v a2 s.c  o m

    chunk.setFont(font);

    return chunk;
}

From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java

License:Open Source License

/**
 * This method is used for add the main information table of project summary
 *//*from www .  java  2s.  com*/
private void addMainInformationTable() {

    String startDate, endDate;
    if (project.getStartDate() != null) {
        startDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getStartDate());
    } else {
        startDate = this.messageReturn(null);
    }

    if (project.getEndDate() != null) {
        endDate = new SimpleDateFormat("dd-MM-yyyy").format(project.getEndDate());
    } else {
        endDate = this.messageReturn(null);
    }

    Paragraph cellContent;

    // Add content
    try {
        PdfPTable table = new PdfPTable(4);

        // Set table widths
        table.setLockedWidth(true);
        table.setTotalWidth(480);
        table.setWidths(new int[] { 3, 5, 3, 5 });

        // First row
        cellContent = new Paragraph(this.getText("summaries.project.startDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(startDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.endDate") + "\n" + " (dd-MM-yyyy)",
                TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);

        cellContent = new Paragraph(this.messageReturn(endDate), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Second row
        cellContent = new Paragraph(this.getText("summaries.project.managementLiaison"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getLiaisonInstitution().getAcronym() + " - "
                + project.getLiaisonInstitution().getName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        cellContent = new Paragraph(this.getText("summaries.project.contactPerson"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getOwner().getComposedName()), TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Third row
        cellContent = new Paragraph(this.getText("summaries.project.leadOrganization"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeader() == null || project.getLeader().getInstitution() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(
                            this.messageReturn(project.getLeader().getInstitution().getComposedName())),
                    TABLE_BODY_FONT);

        }
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        cellContent = new Paragraph(this.getText("summaries.project.projectLeader"), TABLE_BODY_BOLD_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 0);
        if (project.getLeaderPerson() == null || project.getLeaderPerson().getUser() == null) {
            cellContent = new Paragraph(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
        } else {
            cellContent = new Paragraph(
                    this.messageReturn(project.getLeaderPerson().getUser().getComposedName()), TABLE_BODY_FONT);
        }

        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 0);

        // Fourth row
        cellContent = (new Paragraph(this.getText("summaries.project.projectType"), TABLE_BODY_BOLD_FONT));
        this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

        cellContent = new Paragraph(this.messageReturn(project.getType().replaceAll("_", " ")),
                TABLE_BODY_FONT);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        // Fiveth row
        Chunk imdb = null;
        Font hyperLink = new Font(FontFactory.getFont("openSans", 10, Color.BLUE));
        hyperLink.setStyle(Font.UNDERLINE);

        // -- Not Bilateral
        if (!project.isBilateralProject()) {
            cellContent = (new Paragraph(this.getText("summaries.project.detailed"), TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getWorkplanName() != null && !project.getWorkplanName().equals("")) {
                imdb = new Chunk(project.getWorkplanName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getWorkplanName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in " + project.getWorkplanName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        // -- Bilateral
        else {
            cellContent = (new Paragraph(this.getText("summaries.project.ipContributions.proposal.space"),
                    TABLE_BODY_BOLD_FONT));
            this.addTableBodyCell(table, cellContent, Element.ALIGN_RIGHT, 1);

            if (project.getBilateralContractProposalName() != null
                    && !project.getBilateralContractProposalName().equals("")) {
                imdb = new Chunk(project.getBilateralContractProposalName(), hyperLink);
                try {
                    imdb.setAction(new PdfAction(new URL(this.messageReturn(project.getWorkplanURL()))));
                } catch (MalformedURLException exp) {
                    imdb = new Chunk(project.getBilateralContractProposalName(), TABLE_BODY_FONT);
                    LOG.error("There is an Malformed exception in bilateral contract: "
                            + project.getBilateralContractProposalName());
                }
            } else {
                imdb = new Chunk(this.getText("summaries.project.empty"), TABLE_BODY_FONT);
            }
        }

        cellContent = new Paragraph();
        cellContent.add(imdb);
        this.addTableBodyCell(table, cellContent, Element.ALIGN_LEFT, 1);

        document.add(table);
        document.add(Chunk.NEWLINE);
    } catch (DocumentException e) {
        LOG.error(
                "-- generatePdf() > There was an error adding the table with content for case study summary. ",
                e);
    }
}

From source file:org.lucee.extension.pdf.tag.PDF.java

License:Open Source License

private Font toFont(Struct sct) throws PageException {
    Cast caster = engine.getCastUtil();//  w w w .ja v a 2s .  co  m
    Font f = getDefaultFont();
    // size
    float size = caster.toFloatValue(sct.get("size", null), 0);
    if (size > 0)
        f.setSize(size);

    // family
    Set fonts = FontFactory.getRegisteredFonts();
    String family = caster.toString(sct.get("family", null), null);
    if (!Util.isEmpty(family)) {
        String lc = family.toLowerCase();
        if (!fonts.contains(lc)) {
            StringBuilder sb = new StringBuilder();
            Iterator it = fonts.iterator();
            while (it.hasNext()) {
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(it.next());
            }
            throw engine.getExceptionUtil().createApplicationException(
                    "font family [" + family + "] is not available, available font families are [" + sb + "]");
        }
        f.setFamily(lc);
    }

    int style = 0;
    // bold
    boolean bold = caster.toBooleanValue(sct.get("bold", null), false);
    if (bold)
        style |= Font.BOLD;
    // italic
    boolean italic = caster.toBooleanValue(sct.get("italic", null), false);
    if (italic)
        style |= Font.ITALIC;
    // underline
    boolean underline = caster.toBooleanValue(sct.get("underline", null), false);
    if (underline)
        style |= Font.UNDERLINE;
    // strike
    boolean strike = caster.toBooleanValue(sct.get("strike", null), false);
    if (strike)
        style |= Font.STRIKETHRU;
    if (style != 0)
        f.setStyle(style);

    return f;
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    if (!elementPostProcessed) {
        elementPostProcessed = true;//from   www . java2s  .c  o m

        // add space if this paragraph is empty
        // otherwise it's height will be zero
        boolean empty = true;
        ArrayList<Chunk> chunks = getChunks();
        for (Chunk chunk : chunks) {
            if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
                empty = false;
                break;
            }
        }
        if (empty) {
            super.add(new Chunk("\u00A0")); // non breaking space
        }

        // adjust line height and baseline
        if (font != null && font.getBaseFont() != null) {
            // iText and open office computes proportional line height differently
            // [iText] line height = coefficient * font size
            // [open office] line height = coefficient * (font ascender + font descender + font extra margin)
            // we have to increase paragraph line height to generate pdf similar to open office document
            // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph
            float size = font.getSize();
            float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size);
            float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value
            float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size);
            float multiplier = (ascender + descender + margin) / size;
            if (multipliedLeading > 0.0f) {
                setMultipliedLeading(getMultipliedLeading() * multiplier);
            }

            // iText seems to output text with baseline lower than open office
            // we raise all paragraph text by some amount
            // again this may be inaccurate if fonts with different size are used in this paragraph
            float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative
            float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
            chunks = getChunks();
            for (Chunk chunk : chunks) {
                Font f = chunk.getFont();
                if (f != null) {
                    // have to raise underline and strikethru as well
                    float s = f.getSize();
                    if (f.isUnderlined()) {
                        f.setStyle(f.getStyle() & ~Font.UNDERLINE);
                        chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise);
                    }
                    if (f.isStrikethru()) {
                        f.setStyle(f.getStyle() & ~Font.STRIKETHRU);
                        chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise);
                    }
                }
                chunk.setTextRise(chunk.getTextRise() + textRise);
            }
        }

        // wrap this paragraph into a table if necessary
        if (wrapperCell != null) {
            // background color or borders were set
            wrapperCell.addElement(this);
            wrapperTable = createTable(wrapperCell);
            if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f
                    || getSpacingAfter() > 0.0f) {
                // margins were set, have to wrap the cell again
                PdfPCell outerCell = createCell();
                outerCell.setPaddingLeft(getIndentationLeft());
                setIndentationLeft(0.0f);
                outerCell.setPaddingRight(getIndentationRight());
                setIndentationRight(0.0f);
                outerCell.setPaddingTop(getSpacingBefore());
                setSpacingBefore(0.0f);
                outerCell.setPaddingBottom(getSpacingAfter());
                setSpacingAfter(0.0f);
                outerCell.addElement(wrapperTable);
                wrapperTable = createTable(outerCell);
            }
        }
    }
    return wrapperTable != null ? wrapperTable : this;
}