Example usage for com.lowagie.text.pdf PdfFormField setPlaceInPage

List of usage examples for com.lowagie.text.pdf PdfFormField setPlaceInPage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfFormField setPlaceInPage.

Prototype

public void setPlaceInPage(int placeInPage) 

Source Link

Document

Places the annotation in a specified page that must be greater or equal to the current one.

Usage

From source file:org.xhtmlrenderer.pdf.RadioButtonFormField.java

License:Open Source License

private void createField(RenderingContext c, ITextOutputDevice outputDevice, PdfContentByte cb,
        PdfWriter writer, PdfFormField group, RadioButtonFormField fieldElem, RadioButtonFormField checked) {
    Box box = fieldElem.getBox();

    Element e = box.getElement();
    String onValue = getValue(e);

    float width = outputDevice.getDeviceLength(fieldElem.getWidth());
    float height = outputDevice.getDeviceLength(fieldElem.getHeight());

    PdfFormField field = PdfFormField.createEmpty(writer);

    FSColor color = box.getStyle().getColor();
    FSColor darker = box.getEffBackgroundColor(c).darkenColor();
    createAppearances(cb, field, onValue, width, height, true, color, darker);
    createAppearances(cb, field, onValue, width, height, false, color, darker);

    field.setWidget(outputDevice.createTargetArea(c, box), PdfAnnotation.HIGHLIGHT_INVERT);

    // XXX createTargetArea already looks up the page, but hopefully a document
    // won't have enough radio buttons to matter
    Rectangle bounds = box.getContentAreaEdge(box.getAbsX(), box.getAbsY(), c);
    PageBox page = c.getRootLayer().getPage(c, bounds.y);
    field.setPlaceInPage(page.getPageNo() + 1);

    field.setBorderStyle(new PdfBorderDictionary(0.0f, 0));

    field.setAppearanceState(fieldElem == checked ? onValue : OFF_STATE);

    if (isReadOnly(e)) {
        field.setFieldFlags(PdfFormField.FF_READ_ONLY);
    }//from  www .  j  a v a2  s  .  com

    group.addKid(field);
}

From source file:questions.forms.KidsOnDifferentPages.java

public static void createPdf() {
    Document document = new Document();
    try {/*  w  w  w .  j a  v  a2s.c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FORM));
        document.open();

        // create the parent field and its kids
        PdfFormField person = PdfFormField.createEmpty(writer);
        person.setFieldName("person");
        // one kid on page 1
        TextField field1 = new TextField(writer, new Rectangle(0, 0), "name1");
        PdfFormField kid1 = field1.getTextField();
        kid1.setPlaceInPage(1);
        person.addKid(kid1);
        // another kid on page 2
        TextField field2 = new TextField(writer, new Rectangle(0, 0), "name2");
        PdfFormField kid2 = field2.getTextField();
        kid2.setPlaceInPage(2);
        person.addKid(kid2);
        writer.addAnnotation(person);

        // now add the page content
        document.add(createTable(kid1));
        document.newPage();
        document.add(createTable(kid2));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.forms.RadioButtonsOnDifferentPages.java

private static void addRadioButton(PdfWriter writer, Rectangle rect, PdfFormField radio, String name,
        boolean on, int page) throws IOException, DocumentException {
    RadioCheckField check = new RadioCheckField(writer, rect, null, name);
    check.setCheckType(RadioCheckField.TYPE_CIRCLE);
    check.setChecked(on);/*from   w  ww .j av  a  2s  .  c o  m*/
    PdfFormField field = check.getRadioField();
    field.setPlaceInPage(page);
    radio.addKid(field);
}