title: How to create a button in PDF BOX?
body: <p>I want to create a button in PDFBOX i.e., validate or reset button which will call some function of embedded javascript in PDF.</p>
  
  <p>How can I create such button in PDFBOX?</p>
  
  <p>I have tried following code with PDPushButton snippet but it is now working properly. Here when I click on button area, then tick mark symbol is displayed and toggles on every click. Also border is not getting displayed.
  Instead I want to display normal button having label and border around it.</p>
  
  <p>I`m using pdfbox version 1.8.10.</p>
  
  <pre><code>PDDocument doc = new PDDocument();
  PDPage page = new PDPage();
  doc.addPage(page);            
  
  PDAcroForm acroForm = new PDAcroForm(doc);
          doc.getDocumentCatalog().setAcroForm(acroForm);
  
          PDActionJavaScript javascript = new PDActionJavaScript("function validate(index){ app.alert(index); }");
          doc.getDocumentCatalog().setOpenAction( javascript );
  
  COSDictionary cosDict = new COSDictionary();
              COSArray rect = new COSArray();
              rect.add(new COSFloat(100));
              rect.add(new COSFloat(10));
              rect.add(new COSFloat(200));
              rect.add(new COSFloat(60));
  
              cosDict.setItem(COSName.RECT, rect);
              cosDict.setItem(COSName.FT, COSName.getPDFName("Btn")); // Field Type
              cosDict.setItem(COSName.TYPE, COSName.ANNOT);
              cosDict.setItem(COSName.SUBTYPE, COSName.getPDFName("Widget"));
              cosDict.setItem(COSName.T, new COSString("My Btn"));
              cosDict.setItem(COSName.V, new COSString("Validate"));
              cosDict.setItem(COSName.DA, new COSString("/Helv 7 Tf 0 g"));
  
              PDPushButton button = new PDPushButton(acroForm, cosDict);
              button.setValue("Validate Button");
  
              PDActionJavaScript tfJs = new PDActionJavaScript("validate("+index+");");
              PDAnnotationAdditionalActions tfAction = new PDAnnotationAdditionalActions();
              tfAction.setU(tfJs);
              button.getWidget().setActions(tfAction);
  
              PDGamma colourBlack = new PDGamma();
              PDAppearanceCharacteristicsDictionary fieldAppearance = 
                      new PDAppearanceCharacteristicsDictionary(cosDict);
              fieldAppearance.setBorderColour(colourBlack);
              button.getWidget().setAppearanceCharacteristics(fieldAppearance);
  
              page.getAnnotations().add(button.getWidget());
  
              acroForm.getFields().add(button);
  </code></pre>