iTextSharp – 移动Acrofield
我有一个将内容表插入现有Acroform的过程,我能够跟踪启动该内容所需的位置。 但是,根据我插入的表的高度,我在该点之下存在需要向上或向下移动的Acrofield。 有了这个,我怎样才能改变Acrofield的位置? 下面是我可以用来“获得”位置的代码……但现在我还需要能够“设置”它。
….
// Initialize Stamper ("output" is a MemoryStream object) PdfStamper stamper = new PdfStamper(pdf_rdr, output); // Get Reference to PDF Document Fields AcroFields fields = stamper.AcroFields; //call method to get the field's current position AcroFields.FieldPosition pos = GetFieldPosition(fields, "txt_footer");
// **需要明确地为这里的场地设置一个新的位置
//assuming a call to "RegenerateField" will be required fields.RegenerateField(txt_footer);
….
//helper method for capturing the position of a field private static AcroFields.FieldPosition GetFieldPosition(AcroFields fields, string field_nm) { //////////////////////////////////////////////////////////////////////////////////// //get the left margin of the page, and the "top" location for starting positions //using the "regarding_line" field as a basis IList fieldPositions = fields.GetFieldPositions(field_nm); AcroFields.FieldPosition pos = fieldPositions[0]; return pos; }
首先是一些关于字段及其在一个或多个页面上的表示的信息。 PDF表单可以包含许多字段。 字段具有唯一名称,因为具有一个特定名称的一个特定字段具有一个和一个值。 字段使用字段字典定义。
每个字段在文档中可以具有零个,一个或多个表示。 这些可视化表示称为小部件注释 ,它们使用注释字典定义。
知道了这一点,您的问题需要重新定义: 如何更改特定字段的特定窗口小部件注释的位置?
为了回答这个问题,我在Java中创建了一个名为ChangeFieldPosition的示例。 您可以将它移植到C#(也许您可以在此处发布C#答案以供进一步参考)。
您已经拥有AcroFields
实例:
AcroFields form = stamper.getAcroFields();
您现在需要的是特定字段的Item
实例(在我的示例中:对于名称为"timezone2"
的字段):
Item item = form.getFieldItem("timezone2");
该位置是窗口小部件注释的属性,因此您需要询问该item
的小部件。 在下一行中,我获取第一个窗口小部件注释的注释字典(索引为0
):
PdfDictionary widget = item.getWidget(0);
在大多数情况下,只有一个窗口小部件注释:每个字段只有一个可视化表示。
注释的位置是一个包含四个值的数组:llx,lly,urx和ury。 我们可以这样得到这个数组:
PdfArray rect = widget.getAsArray(PdfName.RECT);
在下一行中,我更改了右上角的x值(索引2
对应于urx):
rect.set(2, new PdfNumber(rect.getAsNumber(2).floatValue() - 10f));
结果,场的宽度缩短了10pt。
上述就是C#学习教程:iTextSharp – 移动Acrofield分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1021602.html