Example usage for com.itextpdf.text.pdf BarcodeEAN setTextAlignment

List of usage examples for com.itextpdf.text.pdf BarcodeEAN setTextAlignment

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf BarcodeEAN setTextAlignment.

Prototype

public void setTextAlignment(int textAlignment) 

Source Link

Document

Sets the text alignment.

Usage

From source file:se.billes.pdf.renderer.model.Barcode.java

License:Open Source License

public void onRender(PdfContentByte cb) throws PdfRenderException {

    float[] positions = new BlockFactory().getBoundsInPs(this);

    BarcodeEAN barcode = new BarcodeEAN();
    barcode.setCodeType(BarCodeType.getBarCodeType(barCodeType).codeType);
    barcode.setCode(getCode());//from  ww w.j  av a 2s .  c o m
    barcode.setSize(getFontSize());
    barcode.setGuardBars(isShowGuardBars());
    barcode.setBarHeight(positions[3]);
    barcode.setTextAlignment(Element.ALIGN_RIGHT);
    if (getBaseFont() != null) {
        barcode.setFont(getBaseFont());
    }

    if (align.equals("top")) {
        barcode.setBaseline(-1f);
    }

    PdfDocument request = getPage().getPdfDocument();
    float pageHeight = request.getSize()[1];
    float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight);

    com.itextpdf.text.Image image = barcode.createImageWithBarcode(cb, getBarBaseColor(), getCodeBaseColor());
    image.setRotationDegrees(rotation);
    image.setAbsolutePosition(positions[0], pageHeightInPs - (positions[1] + positions[3] + fontSize));
    try {
        cb.addImage(image);
    } catch (DocumentException e) {
        throw new PdfRenderException(e);
    }
}