List of usage examples for com.lowagie.text.pdf PdfContentByte createAppearance
public PdfAppearance createAppearance(float width, float height)
From source file:org.xhtmlrenderer.pdf.RadioButtonFormField.java
License:Open Source License
private void createAppearances(PdfContentByte cb, PdfFormField field, String onValue, float width, float height, boolean normal, FSColor color, FSColor darker) { // XXX Should cache this by width and height, but they're small so // don't bother for now... PdfAppearance tpOff = cb.createAppearance(width, height); PdfAppearance tpOn = cb.createAppearance(width, height); float diameter = Math.min(width, height); setStrokeColor(tpOff, color);// ww w . j a v a2s. c o m setStrokeColor(tpOn, color); if (!normal) { setStrokeColor(tpOff, darker); setStrokeColor(tpOn, darker); } float strokeWidth = Math.max(1.0f, reduce(diameter)); tpOff.setLineWidth(strokeWidth); tpOn.setLineWidth(strokeWidth); tpOff.circle(width / 2, height / 2, diameter / 2 - strokeWidth / 2); tpOn.circle(width / 2, height / 2, diameter / 2 - strokeWidth / 2); if (!normal) { tpOff.fillStroke(); tpOn.fillStroke(); } else { tpOff.stroke(); tpOn.stroke(); } setFillColor(tpOn, color); if (!normal) { tpOn.circle(width / 2, height / 2, diameter * 0.23f); } else { tpOn.circle(width / 2, height / 2, diameter * 0.20f); } tpOn.fill(); if (normal) { field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, OFF_STATE, tpOff); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, onValue, tpOn); } else { field.setAppearance(PdfAnnotation.APPEARANCE_DOWN, OFF_STATE, tpOff); field.setAppearance(PdfAnnotation.APPEARANCE_DOWN, onValue, tpOn); } }
From source file:org.xhtmlrenderer.pdf.SelectFormField.java
License:Open Source License
private void createAppearance(RenderingContext c, ITextOutputDevice outputDevice, BlockBox box, PdfFormField field) {/* www . j a v a2 s. c om*/ 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 w ww. j a va2 s. c o m 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); }