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

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

Introduction

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

Prototype

public PdfContentByte getDuplicate() 

Source Link

Usage

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  .  ja  v  a  2 s.com*/

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