如何使用iText / Sharp从AcroFields获取TextField? [英] How do I get a TextField from AcroFields using iText/Sharp?

查看:505
本文介绍了如何使用iText / Sharp从AcroFields获取TextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iTextSharp循环遍历 AcroFields 集合中的字段,以便我可以在注释上设置各种属性。我已经研究了如何为每个注释字段提取大部分属性,但是希望能够将单个注释强制转换为正确的字段对象(即 TextField PushButtonField RadioCheckField 等。)

I am using iTextSharp to loop through the fields in the AcroFields collection so I can set a various properties on an annotation. I have worked out how to pull most of the properties for each of the annotation fields, but would like to be able to cast the individual annotation to the correct field object (i.e., TextField, PushButtonField, RadioCheckField, etc.).

如果没有创建新的 TextField ,读取然后设置与之关联的所有设置/属性,是否有简明的方法:

Short of creating a new TextField, reading and then setting all of the settings/properties associated with it, is there a concise way of getting to:

int index = 0;
AcroFields acroFields = stamper.AcroFields;
TextField tf = acroFields.GetTextField(acroField.Key.ToString(), index);

我使用的是非常旧版本的iTextSharp(4.0.6.0)。我无法升级到最新版本,因为4到5之间存在重大变化。

I am using a very old version of iTextSharp (4.0.6.0). I am unable to upgrade to the latest version as there are breaking changes between 4 and 5.

其他信息:
我的PDF文件具有多个重复字段(例如,两个页面具有客户名称),因此仅使用键名设置属性可能会产生意外的副作用。一个字段可能左对齐而另一个字段居中。

Additional Information: My PDF files have multiple repeated fields (e.g., two pages have the customer name), so setting a property by using just a key name can have unintended side effects. One field might be left justified while another is centered.

推荐答案

不幸的是, TextField PushButtonField 和其他都是iText文档创建抽象的一部分,没有内置的方法来反转 AcroFields.Item 回到其中一个对象。

Unfortunately no, TextField, PushButtonField and others are all part of iText's abstraction for document creation and there's no built-in way to reverse an AcroFields.Item object back to one of these.

这篇关于如何使用iText / Sharp从AcroFields获取TextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆