iTextSharp的。如何从AcroFields获取特定类型?像PushButtonField,RadioCheckField等 [英] iTextSharp. How to get specific types from AcroFields? Like PushButtonField, RadioCheckField, etc
问题描述
我正在尝试将 AcroFields
投射到特定类型,以便我可以设置它们的属性。
I am trying to cast AcroFields
to the specific types so I can set properties on them.
我调用 AcroFields.GetField(字符串名称);
我得到的只是一个字符串。
When I call AcroFields.GetField(string name);
all I get is a string.
当我打电话给 AcroFields.GetFieldItem(字符串名称);
我得到一个对象,但无法将其转换为特定类型。
When I call AcroFields.GetFieldItem(string name);
I get an object but cannot cast it to the specific type.
我也有尝试:
AcroFields.SetFieldProperty(myfield,CheckType,RadioCheckField.TYPE_STAR,null);
每次都返回false。
This returned false every time.
为了更好地解释我的情况:
To better explain my scenario:
我有一个现有的PDF(我没有生成这个文件)。
I have an existing PDF ( I am NOT generating this file ).
里面有一个复选框。我想像这样更改CheckType:
myRadioCheckField.CheckType = RadioCheckField.TYPE_STAR
There is a checkbox in it. I want to change the "CheckType" like this: myRadioCheckField.CheckType = RadioCheckField.TYPE_STAR
但是因为我无法将AcroField强制转换为特定类型我不能访问该属性CheckType。
But since I cannot cast the AcroField to the specific type I cannot access that property "CheckType".
有没有办法实现这个目标?
Is there a way to achieve this?
请提供工作样本如果可能的话。
Please provide a working sample if possible.
谢谢。
推荐答案
这是无法做到的。
据我所知iTextSharp不支持从AcroField转换回用于生成字段的原始类(RadioCheckField)。
As far as I know iTextSharp does not support casting from AcroField back to the orginal class ( RadioCheckField ) that was used to generate the field.
您必须编写自己的代码来解析并检查PDF以实现此目的。
You would have to write your own code to parse and inspect the PDF to achieve this.
这篇关于iTextSharp的。如何从AcroFields获取特定类型?像PushButtonField,RadioCheckField等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!