是否有可能修改PDF表单字段名称? [英] Is it possible to modify PDF Form Field Names?

查看:643
本文介绍了是否有可能修改PDF表单字段名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的情况。我有一个自动生成的PDF表单字段名称的PDF文件。的问题是,这些名称不是非常用户友好的。他们看起来是这样的: topmostSubform [0] .Page1 [0] .Website_Address [0]

Here's the situation. I have a PDF with automatically generated pdf form field names. The problem is that these names are not very user friendly. They look something like : topmostSubform[0].Page1[0].Website_Address[0]

我希望能够改变他们,使他们像WebsiteAddress。我有机会获得ABCPDF和我有iTextSharp的经验,但我已经使用这些API的做到这一点(访问表单字段并尝试重命名)试过了,但它似乎并不仿佛是可能的。

I want to be able to change them so that they are something like WebsiteAddress. I have access to ABCPDF and I have experience with iTextSharp, but I have tried using these API's to do this (access form fields and try to rename), but it does not seem as if it is possible.

没有任何人有任何试图通过某种(preferably开源)的API来完成这方面的经验。 code是净也。

Does anybody have any experience trying to do this via an API of some sort (preferably open source). Code is .Net also.

推荐答案

好消息:你可以在iTextSharp的改变字段名称

The good news: you can change field names in iTextSharp.

您不能真正编辑PDF,虽然。你会阅读现有的PDF,更新记忆了字段名称,然后写出修改后的PDF文件。要改变字段名呼叫AcroFields.RenameField方法。

You can't actually edit a PDF though. You'd read in an existing PDF, update your field names in memory and then write out your revised PDF. To change a field name call the AcroFields.RenameField method.

下面是一个片断:

PdfReader reader = new PdfReader(PDF_PATH);
using (FileStream fs = new FileStream("Test Out.pdf", FileMode.Create)) {
    PdfStamper stamper = new PdfStamper(reader, fs);
    AcroFields fields = stamper.AcroFields;
    fields.RenameField("oldFieldName", "newFieldName");
    stamper.Close();
}

现在的坏消息:有似乎是你可以重命名字段使用的字符限制

Now the bad news: there appear to be limitations in the characters you can use in the renamed fields.

我测试上面的代码片段与你的榜样字段名称和它没有工作。虽然卸下周期和它的工作。我不知道是否有一个解决办法,但这可能是你的问题,

I tested the snippet above with your example field name and it didn't work. Remove the periods though and it does work. I'm not sure if there's a workaround but this may be a problem for you,

这篇关于是否有可能修改PDF表单字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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