How do I add borders to all Form Fields?

39 views
Skip to first unread message

Ryan

unread,
Aug 19, 2016, 3:06:52 PM8/19/16
to PDFTron PDFNet SDK
Question:

I am trying to add a border around forms in a PDF? How can I accomplish this?

Answer:

The following code will iterator through every field (or rather each Widget) of a field, and set its border appearance.

Note, you probably want to only do this to certain field types. In general you don't want to call RefreshAppearance on button widgets.

using (PDFDoc doc = new PDFDoc(output_path + "forms_test1.pdf"))
{
   doc
.InitSecurityHandler();


   
FieldIterator itr;
   
for(itr=doc.GetFieldIterator(); itr.HasNext(); itr.Next())
   
{
       
Field field = itr.Current();
       
if(your_conditional(field))
       
{
           
Widget widget = new Widget(field.GetSDFObj());
           widget
.SetBorderStyle(new Annot.BorderStyle(Annot.BorderStyle.Style.e_solid, width);
       
}
   
}
}

Note, a Widget annotation is the visual representation of a Field. A field can have multiple widgets, for example a single field could be repeated on multiple pages. While each Widget can have a separate appearance (e.g. background color can be different), they would all have the same value (e.g. they all show the same phone number).

Reply all
Reply to author
Forward
0 new messages