Search code examples
c#asp.netitext7

Itext7 Fill and modiffy PDF in c# asp.net


I am looking at this example

I am trying the code below to run to fill a document in c# asp.net.

string src = @"C:\documents\BlankContracts\Document 50.pdf";
    string dest = @"C:\documents\BlankContracts\123.pdf";
    PdfDocument pdfDoc =
new PdfDocument(new PdfReader(src), new PdfWriter(dest));
    // add content
    PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
            Map<string, PdfFormField> fields = form.GetFormFields();

It keeps giving me an error on the part where it tries to get the list of fields. It keep asking me to create a class for Map. If any one know how to do this please let me know. I have been going all over the place but couldn't find place where it shows how exactly can I fill out a PDF using the newer version Itext7 Thanks


Solution

  • Of course the compiler want you to specify Map. Also, according to examples which you shared, you should change it

    Map<string, PdfFormField> fields = form.GetFormFields();
    

    to;

    IDictionary<String, PdfFormField> fields = form.GetFormFields();