Skip to main content
Participant
October 18, 2021
Question

Get field type C#

  • October 18, 2021
  • 2 replies
  • 1045 views

Hi,

I know there's 3rd party libraries that can integrate reading and writing to pdf's in c# but I'm trying not to use them at the moment.  I've figured out how to open and read the field names from the pdf, as well as getting a specific field by calling InvokeMember and and using GetJSObject to getNthFieldName.  What I'm trying to figure out now is by knowing the field name, is it possible to get the type of field i.e. text, radio button, checkbox, etc.  Also, if it's a radio button, the values that can be selected and so on.  Anyone able to help me figure this out? 

 

Here's a snippet of what I've tried:

Acrobat.AcroApp acroApp = new();
Acrobat.AcroPDDoc acroPDDoc = new();
acroPDDoc.Open($@"{filesHolder.PdfFile}");
object jso = acroPDDoc.GetJSObject();

object[] args = new object[] { fieldPair.Value }; // the value is the index number on the pdf sheet to get the nth field name.  this works for me.
object nthFieldName = jso.GetType().InvokeMember("getNthFieldName", BindingFlags.InvokeMethod, null, jso, args);
pdfField = nthFieldName.ToString();
args = new object[] { pdfField };

// not sure if this right, doesn't seem to be working for me, think this might be used for getting the value of the field and not the field type.
object nthField = jso.GetType().InvokeMember("GetField", BindingFlags.InvokeMethod, null, jso, args); 

 

I'm not sure which method to invoke to get the field type or if I'm completely on the wrong path for figuring it out.

 

Thanks,

Alan

This topic has been closed for replies.

2 replies

Legend
October 18, 2021

The interface is not designed for C#, and the interoperability can be tough to work with. Why not use VB? 

Participant
October 18, 2021

Yeah, I'm finding it to be challenging with C#.  Just building a standalone WPF app and was thinking it wouldn't be too tough in C# and wanting to not really use a 3rd party library.  I guess I could build the acrobat portion in VB and import it as a dll and call those functions or just build the app in VB.

 

Thank you for replying and helping me out.

try67
Community Expert
Community Expert
October 18, 2021
After getting the Field object using the getField method you can access its
type property to find out what kind of field it is.
Participant
October 18, 2021

Thanks, I'm still a little stuck on the process.

Is calling this first the correct step?

object nthField = jso.GetType().InvokeMember("getField", BindingFlags.InvokeMethod, null, jso, args); 

If so, I'm not sure how to get the properties from that.

nthField doesn't have any method to GetProperty after I invoke getField this way.

The only options I have for nthField is ToString, GetType, and GetHashCode.