List of usage examples for com.itextpdf.text.pdf PdfContentByte showTextAlignedKerned
public void showTextAlignedKerned(final int alignment, final String text, final float x, final float y, final float rotation)
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private void getDirectContent(PdfContentByte cb, Rectangle ps, Map it) throws Exception { BaseColor color = getColor(it, "fillColor"); if (color != null) cb.setColorFill(color);// w ww. j av a2 s .c o m float x = MapUtil.getFloat(it, "x", 0f); float y = MapUtil.getFloat(it, "y", 0f); float w = MapUtil.getFloat(it, "w", 0f); float h = MapUtil.getFloat(it, "h", 0f); float xPer = MapUtil.getFloat(it, "xPer", 0f); float yPer = MapUtil.getFloat(it, "yPer", 0f); float wPer = MapUtil.getFloat(it, "wPer", 0f); float hPer = MapUtil.getFloat(it, "hPer", 0f); String pos = MapUtil.getStr(it, "position", "bottom"); switch (pos) { case "top": y += ps.getHeight(); break; case "right": x += ps.getWidth(); break; } float xx = x + ps.getWidth() * xPer / 100f; float yy = y + ps.getWidth() * yPer / 100f; float ww = ps.getWidth() * wPer / 100f + w; float hh = ps.getHeight() * hPer / 100f + h; int font = MapUtil.getInt(it, "fontSize", 8); cb.setFontAndSize(getDefaultFont(), font); cb.beginText(); String cls = MapUtil.getStr(it, "cls", ""); if (cls.equals("image")) { Image img = getImage(it); cb.addImage(img, img.getWidth(), 0, 0, img.getHeight(), xx, yy); } else { String text = LightUtil.macro(MapUtil.getStr(it, "text", ""), '$').toString(); float degree = MapUtil.getFloat(it, "rotateDegree", 0f); boolean kerned = MapUtil.getBool(it, "kerned", false); int align = getAlignment(it, "alignment"); x = xx; y = yy; switch (align) { case Element.ALIGN_CENTER: x = xx + ww / 2; break; case Element.ALIGN_RIGHT: x = xx + ww; break; default: align = Element.ALIGN_LEFT; break; } if (kerned) cb.showTextAlignedKerned(align, text, x, y, degree); else cb.showTextAligned(align, text, x, y, degree); } cb.endText(); }