Is it possible to modify PDF Form Field Names?

前端 未结 9 2179
一个人的身影
一个人的身影 2021-02-06 06:05

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 :

9条回答
  •  遇见更好的自我
    2021-02-06 06:28

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

    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.

    Here's a snippet:

    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,

提交回复
热议问题