是否有可能修改PDF表单字段名称?有可能、字段、表单、名称

2023-09-03 13:21:59 作者:我在时间尽头等你

这里的情况。我有一个自动生成的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,