Example usage for com.lowagie.text.pdf PdfAppearance setFontAndSize

List of usage examples for com.lowagie.text.pdf PdfAppearance setFontAndSize

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAppearance setFontAndSize.

Prototype

public void setFontAndSize(BaseFont bf, float size) 

Source Link

Document

Set the font and the size for the subsequent text writing.

Usage

From source file:org.xhtmlrenderer.pdf.SelectFormField.java

License:Open Source License

private void createAppearance(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box,
        PdfFormField field) {/*from www  . ja va 2  s .com*/
    PdfWriter writer = outputDevice.getWriter();
    ITextFSFont font = (ITextFSFont) box.getStyle().getFSFont(c);

    PdfContentByte cb = writer.getDirectContent();

    float width = outputDevice.getDeviceLength(getWidth());
    float height = outputDevice.getDeviceLength(getHeight());
    float fontSize = outputDevice.getDeviceLength(font.getSize2D());

    PdfAppearance tp = cb.createAppearance(width, height);
    tp.setFontAndSize(font.getFontDescription().getFont(), fontSize);

    FSColor color = box.getStyle().getColor();
    setFillColor(tp, color);

    field.setDefaultAppearanceString(tp);
}

From source file:org.xhtmlrenderer.pdf.TextFormField.java

License:Open Source License

private void createAppearance(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box,
        PdfFormField field, String value) {
    PdfWriter writer = outputDevice.getWriter();
    ITextFSFont font = (ITextFSFont) box.getStyle().getFSFont(c);

    PdfContentByte cb = writer.getDirectContent();

    float width = outputDevice.getDeviceLength(getWidth());
    float height = outputDevice.getDeviceLength(getHeight());
    float fontSize = outputDevice.getDeviceLength(font.getSize2D());

    PdfAppearance tp = cb.createAppearance(width, height);
    PdfAppearance tp2 = (PdfAppearance) tp.getDuplicate();
    tp2.setFontAndSize(font.getFontDescription().getFont(), fontSize);

    FSColor color = box.getStyle().getColor();
    setFillColor(tp2, color);/*from www . j a v  a2 s.c om*/

    field.setDefaultAppearanceString(tp2);
    tp.beginVariableText();
    tp.saveState();
    tp.beginText();
    tp.setFontAndSize(font.getFontDescription().getFont(), fontSize);
    setFillColor(tp, color);
    tp.setTextMatrix(0, height / 2 - (fontSize * 0.3f));
    tp.showText(value);
    tp.endText();
    tp.restoreState();
    tp.endVariableText();
    field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
}