Example usage for com.lowagie.text.pdf PdfTemplate showTextAligned

List of usage examples for com.lowagie.text.pdf PdfTemplate showTextAligned

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfTemplate showTextAligned.

Prototype

public void showTextAligned(int alignment, String text, float x, float y, float rotation) 

Source Link

Document

Shows text right, left or center aligned with rotation.

Usage

From source file:questions.images.CustomizedTitleBar.java

public static Image getTitleBar(PdfWriter writer, Image background, String title)
        throws DocumentException, IOException {
    float width = background.getWidth();
    float height = background.getHeight();
    PdfTemplate tmp = writer.getDirectContent().createTemplate(width, height);
    tmp.addImage(background, width, 0, 0, height, 0, 0);
    BaseFont font = BaseFont.createFont();
    tmp.beginText();/*from   w w  w . j  a v a 2s .c o  m*/
    tmp.setGrayFill(1);
    tmp.setFontAndSize(font, 18);
    tmp.showTextAligned(Element.ALIGN_CENTER, title, width / 2, 4, 0);
    tmp.endText();
    return Image.getInstance(tmp);
}