List of usage examples for com.lowagie.text.pdf PdfFormField setAppearance
public void setAppearance(PdfName ap, String state, PdfTemplate template)
From source file:at.reppeitsolutions.formbuilder.components.pdf.itext.ITextCheckbox.java
License:Open Source License
@Override public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) { PdfWriter writer = canvases[0].getPdfWriter(); PdfAppearance[] onOff = new PdfAppearance[2]; onOff[0] = canvases[0].createAppearance(20, 20); onOff[0].rectangle(1, 1, 18, 18);/*from w w w . jav a 2 s.c o m*/ onOff[0].stroke(); onOff[1] = canvases[0].createAppearance(20, 20); onOff[1].setRGBColorFill(255, 128, 128); onOff[1].rectangle(1, 1, 18, 18); onOff[1].fillStroke(); onOff[1].moveTo(1, 1); onOff[1].lineTo(19, 19); onOff[1].moveTo(1, 19); onOff[1].lineTo(19, 1); onOff[1].stroke(); RadioCheckField checkbox; Font f = new Font(); f.setSize(ITextInputText.FONTSIZE); for (int i = 0; i < values.length; i++) { try { Rectangle rect = ITextRadio.getBoxRectangle(rectangle, i); checkbox = new RadioCheckField(writer, rect, UUID.randomUUID().toString(), "Yes"); boolean checked = false; if (selectedValues != null) { for (int i2 = 0; i2 < selectedValues.length; i2++) { if (values[i].equals(selectedValues[i2])) { checked = true; break; } } } checkbox.setChecked(checked); PdfFormField field = checkbox.getCheckField(); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]); field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[1]); if (locked) { field.setFieldFlags(BaseField.READ_ONLY); } writer.addAnnotation(field); ITextRadio.addBoxDescription(rectangle, i, values, canvases); } catch (IOException ex) { Logger.getLogger(ITextCheckbox.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ITextCheckbox.class.getName()).log(Level.SEVERE, null, ex); } } }
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);/*from www .j a va2 s. co 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); } }