ButtonField + Submit Pdf Action + Style on Button

Hi,

I want to add a button to pdf with following properties:

  • Have background color and font color.
  • Have action that submit pdf to the specified url.

I have following code but that button does not allow styling within button but allow to submit pdf to url:
FormEditor add = new com.aspose.pdf.facades.FormEditor(document);
add.setFieldAppearance(“btnSubmit”, AnnotationFlags.Print);
add.addSubmitBtn(“btnSubmit”, 0, “Submit”, “WebService/uploadpdf”, 10, 5, 50, 25);
add.setSubmitFlag(“btnSubmit”, com.aspose.pdf.facades.SubmitFormFlag.Pdf);

I also tried following but that does not allow to set the style and action as needed:
ButtonField button = (ButtonField)document.getForm().get_Item(“buttonField”);
ButtonField button = new ButtonField(document.getPages().get_Item(0), new Rectangle(5, 5, 40, 25));
button.setContents(“SUBMIT”);
button.setColor(Color.getWhite());
button.getCharacteristics().setBackground(Color.getBlue());
button.getPdfActions().add(new GoToURIAction(“WebService//uploadpdf”));
document.getForm().add(button, 0);

Please provide me some code to achieve desired functionality as above.

I need button style as below
image.png (3.8 KB)

Please don’t request for pdf as I have already provided the snippet that I am using and I am not allowed to share pdf that I am using.

Thanks,
Darshit Patel

@darshpatel

You can change the button style after adding it to PDF and retrieving later by Document.getForm(). For example, please check the below code snippet:

Document document = new Document();
document.getPages().add();
com.aspose.pdf.facades.FormEditor add = new com.aspose.pdf.facades.FormEditor(document);
add.setFieldAppearance("btnSubmit", AnnotationFlags.Print);
add.addSubmitBtn("btnSubmit", 1, "Submit", "WebService/uploadpdf", 10, 5, 50, 25);
add.setSubmitFlag("btnSubmit", com.aspose.pdf.facades.SubmitFormFlag.Pdf);
add.save(dataDir + "saved.pdf");

document = new Document(dataDir + "saved.pdf");
ButtonField button = ((ButtonField)document.getForm().get_Item("btnSubmit"));
button.setColor(Color.getWhite());
button.getCharacteristics().setBackground(Color.getBlue());

document.save(dataDir + "newButtonStyle.pdf");

@asad.ali

Thanks for your example.

It sort of worked but having red border around the button as below, I am not sure how to get rid of it.

image.png (911 Bytes)

Also when button is pressed it all appeared in red even though no property is set to red color for button.

image.png (6.7 KB)

Besides, I want corner on all edge of the button to make it more round edges, how can that be achieved?

Thanks,
Darshit Patel

@darshpatel

We have logged an investigation ticket as PDFJAVA-40346 in our issue tracking system in order to determine whether required styling can be achieved or not. We will further look into it and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We apologize for the inconvenience.