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 :
This worked for me using iText 7:
PdfReader reader = new PdfReader("Source.pdf");
using (FileStream fs = new FileStream("Dest.pdf", FileMode.Create))
{
using (var pdfDoc = new PdfDocument(reader, new PdfWriter(fs)))
{
PdfAcroForm pdfForm = PdfAcroForm.GetAcroForm(pdfDoc, true);
pdfDoc.GetWriter().SetCloseStream(true);
var Fields = pdfForm.GetFormFields().Select(x => x.Key).ToArray();
for (int i = 0; i < Fields.Length; i++)
{
pdfForm.RenameField(Fields[i], "new_" + Fields[i]);
}
}
}