0

I am stuck here. actually I am trying to fill a PDF form using asp.net. I get some help and write the following code:

private void fillForm()
{
    try
    {
        string formFile = Server.MapPath("") + @"\Forms\fw4.pdf";
        string savepath = Server.MapPath("") + @"\Forms\new_fw4.pdf";
        PdfReader pdfReader = new PdfReader(formFile);
        using (FileStream stream = new FileStream(savepath, FileMode.Create))
        {
            PdfStamper pdfStamper = new PdfStamper(pdfReader, stream);
            AcroFields formFields = pdfStamper.AcroFields;

            foreach (DictionaryEntry de in formFields.Fields)
             {
                 formFields.SetField("field name", "field value");
             }            
            pdfStamper.FormFlattening = true;
            pdfStamper.Close();
        }
    }
    catch
    {
    }
}

I want the program to show all fields in a List. I am unable to iterate all available fields using the foreach loop. Its giving me this error:

Cannot convert type System.Collections.Generic.KeyValuePair<string,iTextSharp.text.pdf.AcroFields.Item> to System.Collections.DictionaryEntry

any help would be greatly appreciated.

2
  • 1
    And what about using KeyValuePair<,> instead of DictionaryEntry? Commented Apr 6, 2012 at 11:33
  • 1
    thnaks for the reply, it works with just var. but now I want to listdown all fields present in the file in an array or some other way. Commented Apr 6, 2012 at 11:39

1 Answer 1

2

As you have updated KeyValuePair try using item.Key & item.Value

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.