Example usage for com.lowagie.text.pdf PdfAnnotation APPEARANCE_NORMAL

List of usage examples for com.lowagie.text.pdf PdfAnnotation APPEARANCE_NORMAL

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfAnnotation APPEARANCE_NORMAL.

Prototype

PdfName APPEARANCE_NORMAL

To view the source code for com.lowagie.text.pdf PdfAnnotation APPEARANCE_NORMAL.

Click Source Link

Document

appearance attributename

Usage

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  www  .j av  a2 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:classroom.newspaper_b.Newspaper08.java

public static void main(String[] args) {
    try {/*from  w  ww. ja v  a 2  s .c o m*/
        PdfReader reader = new PdfReader(NEWSPAPER);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));

        PdfAnnotation annotation1 = PdfAnnotation.createText(stamper.getWriter(),
                new Rectangle(LLX1, LLY1, URX1, URY1), "Advertisement 1", MESSAGE, false, "Insert");
        PdfAppearance ap = stamper.getOverContent(1).createAppearance(W1, H1);
        ap.setRGBColorStroke(0xFF, 0x00, 0x00);
        ap.setLineWidth(3);
        ap.moveTo(0, 0);
        ap.lineTo(W1, H1);
        ap.moveTo(W1, 0);
        ap.lineTo(0, H1);
        ap.stroke();
        annotation1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
        stamper.addAnnotation(annotation1, 1);

        PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(),
                new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, true, "Insert");
        annotation2.put(PdfName.C, new PdfArray(new float[] { 0, 0, 1 }));
        stamper.addAnnotation(annotation2, 1);

        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

protected void drawHyperlink(final RenderNode box, final String target, final String window,
        final String title) {
    if (box.isNodeVisible(getDrawArea()) == false) {
        return;/*  w  w  w.  j  a  v a2s  .  co m*/
    }

    final PdfAction action = createActionForLink(target);

    final AffineTransform affineTransform = getGraphics().getTransform();
    final float translateX = (float) affineTransform.getTranslateX();

    final float leftX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX()));
    final float rightX = translateX + (float) (StrictGeomUtility.toExternalValue(box.getX() + box.getWidth()));
    final float lowerY = (float) (globalHeight
            - StrictGeomUtility.toExternalValue(box.getY() + box.getHeight()));
    final float upperY = (float) (globalHeight - StrictGeomUtility.toExternalValue(box.getY()));

    if (action != null) {
        final PdfAnnotation annotation = new PdfAnnotation(writer, leftX, lowerY, rightX, upperY, action);
        writer.addAnnotation(annotation);
    } else if (StringUtils.isEmpty(title) == false) {
        final Rectangle rect = new Rectangle(leftX, lowerY, rightX, upperY);
        final PdfAnnotation commentAnnotation = PdfAnnotation.createText(writer, rect, "Tooltip", title, false,
                null);
        commentAnnotation.setAppearance(PdfAnnotation.APPEARANCE_NORMAL,
                writer.getDirectContent().createAppearance(rect.getWidth(), rect.getHeight()));
        writer.addAnnotation(commentAnnotation);
    }
}

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  w w  w  .ja v a  2  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);
    }
}

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);//  w  w w.j ava  2  s  .c om

    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);
}