Example usage for com.lowagie.text.pdf PushbuttonField setBorderColor

List of usage examples for com.lowagie.text.pdf PushbuttonField setBorderColor

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PushbuttonField setBorderColor.

Prototype

public void setBorderColor(Color borderColor) 

Source Link

Document

Sets the border color.

Usage

From source file:classroom.newspaper_b.Newspaper10.java

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

        rect = new Rectangle(100, 980, 700, 1000);
        button = new PushbuttonField(stamper.getWriter(), rect, "click");
        button.setBackgroundColor(Color.ORANGE);
        button.setText("Click here to close window");
        button.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY);
        button.setAlignment(Element.ALIGN_RIGHT);
        PdfFormField menubar = button.getField();
        String js = "var f1 = getField('click'); f1.display = display.hidden;"
                + "var f2 = getField('advertisement'); f2.display = display.hidden;";
        menubar.setAction(PdfAction.javaScript(js, stamper.getWriter()));
        stamper.addAnnotation(menubar, 1);

        rect = new Rectangle(100, 500, 700, 980);
        button = new PushbuttonField(stamper.getWriter(), rect, "advertisement");
        button.setBackgroundColor(Color.WHITE);
        button.setBorderColor(Color.ORANGE);
        button.setImage(Image.getInstance(IMG));
        button.setText("Buy the book iText in Action");
        button.setLayout(PushbuttonField.LAYOUT_LABEL_TOP_ICON_BOTTOM);
        PdfFormField advertisement = button.getField();
        advertisement.setAction(new PdfAction("http://www.1t3xt.com/docs/book.php"));
        stamper.addAnnotation(advertisement, 1);
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:classroom.newspaper_b.Newspaper13.java

public static void addButton(PdfStamper stamper, Rectangle rect, String path, String name, int pagenumber)
        throws IOException, DocumentException {
    PushbuttonField field = new PushbuttonField(stamper.getWriter(), rect, name);
    if (path.endsWith(".pdf")) {
        PdfReader reader = new PdfReader(path);
        field.setTemplate(stamper.getImportedPage(reader, 1));
    } else {/*  w  w  w  .ja  va2  s.co  m*/
        field.setImage(Image.getInstance(path));
    }
    field.setBackgroundColor(new Color(0xFF, 0xFF, 0xFF));
    field.setBorderColor(new Color(0xC0, 0xC0, 0xC0));
    field.setBorderWidth(0.5f);
    field.setScaleIcon(PushbuttonField.SCALE_ICON_ALWAYS);
    field.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
    stamper.addAnnotation(field.getField(), pagenumber);
}

From source file:com.geek.tutorial.itext.acroform.ListFieldForm.java

License:Open Source License

public ListFieldForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ListFieldForm.pdf"));
    document.open();//from w ww. j ava 2  s.  co  m

    // Code 1
    String options[] = { "PS3", "XBOX 360", "Wii", "PSP", "NDS", "GBA" };

    // Code 2 create drop-down list
    PdfFormField dropDown = PdfFormField.createCombo(writer, true, options, 0);
    dropDown.setWidget(new Rectangle(50, 785, 120, 800), PdfAnnotation.HIGHLIGHT_INVERT);
    dropDown.setFieldName("dropDownList");
    dropDown.setValueAsString("PS3");
    dropDown.setMKBorderColor(Color.BLACK);
    writer.addAnnotation(dropDown);

    // Code 3 create scrollable list
    TextField scrollableList = new TextField(writer, new Rectangle(150, 740, 250, 800), "scrollableList");
    scrollableList.setBackgroundColor(Color.WHITE);
    scrollableList.setBorderColor(Color.BLUE);
    scrollableList.setBorderWidth(2);
    scrollableList.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    scrollableList.setFontSize(10);
    scrollableList.setChoices(options);
    scrollableList.setChoiceSelection(0);
    writer.addAnnotation(scrollableList.getListField());

    // Code 4 add function and button for showing state 
    writer.addJavaScript(
            "function showState(){" + "app.alert('DropDown:'+ this.getField('dropDownList').value +'\\n'+"
                    + "'Scrollable List:'+this.getField('scrollableList').value);" + "}");
    PushbuttonField push = new PushbuttonField(writer, new Rectangle(70, 710, 140, 730), "pushAction");
    push.setBackgroundColor(Color.LIGHT_GRAY);
    push.setBorderColor(Color.GRAY);
    push.setText("Show State");
    push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    push.setTextColor(Color.BLACK);
    PdfFormField pushbutton = push.getField();
    pushbutton.setAction(PdfAction.javaScript("showState()", writer));
    writer.addAnnotation(pushbutton);

    document.close();
}

From source file:com.geek.tutorial.itext.acroform.RadioCheckBoxForm.java

License:Open Source License

public RadioCheckBoxForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("RadioCheckBoxForm.pdf"));
    document.open();/* ww  w.  ja v  a  2 s.  c  o  m*/
    PdfContentByte cb = writer.getDirectContent();

    BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    Rectangle rect;

    // Code 1 create radio button
    String[] radios = { "Radio1", "Radio2", "Radio3" };
    PdfFormField radioField = PdfFormField.createRadioButton(writer, true);
    radioField.setFieldName("radioField");
    radioField.setValueAsName(radios[0]);
    for (int i = 0; i < radios.length; i++) {
        rect = new Rectangle(40, 815 - i * 30, 60, 797 - i * 30);
        addRadioButton(writer, rect, radioField, radios[i], i == 0);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(Element.ALIGN_LEFT, radios[i], 70, 802 - i * 30, 0);
        cb.endText();
    }
    writer.addAnnotation(radioField);

    // Code 2 create checkbox button
    String[] options = { "Check1", "Check2", "Check3" };
    for (int i = 0; i < options.length; i++) {
        rect = new Rectangle(160, 815 - i * 30, 180, 797 - i * 30);
        addCheckbox(writer, rect, options[i]);
        cb.beginText();
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(Element.ALIGN_LEFT, options[i], 190, 802 - i * 30, 0);
        cb.endText();
    }

    // Code 3 add function and button for showing state 
    writer.addJavaScript(
            "function showState(){" + "app.alert('Radio:'+ this.getField('radioField').value +'\\n\\n'+"
                    + "'Check1:'+this.getField('Check1').value +'\\n'+"
                    + "'Check2:'+this.getField('Check2').value +'\\n'+"
                    + "'Check3:'+this.getField('Check3').value);" + "}");
    PushbuttonField push = new PushbuttonField(writer, new Rectangle(80, 710, 150, 730), "pushAction");
    push.setBackgroundColor(Color.LIGHT_GRAY);
    push.setBorderColor(Color.GRAY);
    push.setText("Show State");
    push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    push.setTextColor(Color.BLACK);
    PdfFormField pushbutton = push.getField();
    pushbutton.setAction(PdfAction.javaScript("showState()", writer));
    writer.addAnnotation(pushbutton);

    document.close();
}

From source file:questions.javascript.TriggerMenuButtons.java

public static final void main(String[] args) {
    Document document = new Document();
    try {//from  www .  ja  va 2s . c om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        document.add(new Paragraph("Triggering Menu Items"));
        PushbuttonField saveAs = new PushbuttonField(writer, new Rectangle(40, 760, 100, 780), "Save");
        saveAs.setBorderColor(Color.BLACK);
        saveAs.setText("Save");
        saveAs.setTextColor(Color.RED);
        saveAs.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY);
        PdfFormField saveAsButton = saveAs.getField();
        saveAsButton.setAction(PdfAction.javaScript("app.execMenuItem('SaveAs')", writer));
        writer.addAnnotation(saveAsButton);
        PushbuttonField mail = new PushbuttonField(writer, new Rectangle(120, 760, 180, 780), "Mail");
        mail.setBorderColor(Color.BLACK);
        mail.setText("Mail");
        mail.setTextColor(Color.RED);
        mail.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY);
        PdfFormField mailButton = mail.getField();
        mailButton.setAction(PdfAction.javaScript("app.execMenuItem('AcroSendMail:SendMail')", writer));
        writer.addAnnotation(mailButton);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}