Rename fields in pdf document


I am trying to rename fields in a pdfdocument using the following C#

byte[] file2 = RenameFields(File.ReadAllBytes(@"C:\Temp
\renameTest.pdf"), "_testing");
File.WriteAllBytes(@"C:\Temp\renamed.pdf", file2);

public byte[] RenameFields(byte[] source, string postfix)
        using (PDFDoc PDFDocument = new PDFDoc(source, source.Length))
            byte[] finalPdf = null;
            int finalSize = 0;

            int pageCount = PDFDocument.GetPageCount();

            for (int pageNo = 1; pageNo <= pageCount; pageNo++)
                pdftron.PDF.Page page = PDFDocument.GetPage(pageNo);
                if (page != null)
                    //Get number of controls on the page
                    int fieldCount = page.GetNumAnnots();

                    //loop through all those fields...
                    for (int loop = 0; loop < fieldCount; loop++)
                        Annot annot = page.GetAnnot(loop);

                        if (!annot.IsValid())

                        //if it is valid widget control
                        if (annot.GetType() == Annot.Type.e_Widget)
                            pdftron.PDF.Annots.Widget w = new
                            Field field = w.GetField();

                            if (field != null)
                               field.Rename(field.GetName() +

            PDFDocument.Save(ref finalPdf, ref finalSize,
            return finalPdf;

Question I have is, above code renames all the fields but it doesn’t
retain value of the fields. Data in the each field is lost. Can you
let me know the proper way to rename all fields in the PDF with their
values intact.


Thanks for reporting this issue. It was fixed and will be included as part of the next update (v.5.8).

An interim solution is to copy the old value explicitly:

Obj val = field.GetValue();


field.GetSDFObj.Put(“V”, val);