• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Get field type C#

New Here ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

96

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

After getting the Field object using the getField method you can access its
type property to find out what kind of field it is.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2021 Oct 18, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines