locked
problem using ITextSharp RRS feed

  • Question

  • User-1719701746 posted

    Error 1 Cannot convert type 'System.Collections.Generic.KeyValuePair<string,iTextSharp.text.pdf.AcroFields.Item>' to 'System.Collections.DictionaryEntry' D:\Projects\FillPDFForm\FillPDFForm\Form1.cs 45 13 FillPDFForm

    hi All,

    Can any body tell me.... How to get rid off this error.........??


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

    Saturday, November 27, 2010 12:31 AM

Answers

  • User384031199 posted

    Hi,

    Try KeyValuePair instead of DictionaryEntry as given below.

    foreach (KeyValuePair<string, AcroFields.Item> de in pdfReader.AcroFields.Fields)
    {
        sb.Append(de.Key.ToString() + Environment.NewLine);
    }
    

    Hope this helps.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 27, 2010 5:00 AM

All replies

  • User384031199 posted

    Hi,

    It's a type casting error. Please post the code here, if possible, to help you out.

     

    Saturday, November 27, 2010 2:47 AM
  • User-1719701746 posted

    private void ListFieldNames()
            {
                string pdfTemplate = "Sample_form.pdf";
                // title the form
                this.Text += " - " + pdfTemplate;
                // create a new PDF reader based on the PDF template document
                PdfReader pdfReader = new PdfReader("~/Sample_form.pdf");
                // create and populate a string builder with each of the
                // field names available in the subject PDF
                StringBuilder sb = new StringBuilder();
                //foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
                //{
                //    sb.Append(de.Key.ToString() + Environment.NewLine);
                //}
                // Write the string builder's content to the form's textbox
                textBox1.Text = sb.ToString();
                textBox1.SelectionStart = 0;
            }
    private void ListFieldNames()
            {
                string pdfTemplate = "Sample_form.pdf";

                // title the form
                this.Text += " - " + pdfTemplate;

                // create a new PDF reader based on the PDF template document
                PdfReader pdfReader = new PdfReader("~/Sample_form.pdf");

                // create and populate a string builder with each of the
                // field names available in the subject PDF
                StringBuilder sb = new StringBuilder();

               foreach (DictionaryEntry de in pdfReader.AcroFields.Fields)
               {
                  sb.Append(de.Key.ToString() + Environment.NewLine);
              }

                // Write the string builder's content to the form's textbox
                textBox1.Text = sb.ToString();
                textBox1.SelectionStart = 0;
            }

    foreach loop giving error

    Saturday, November 27, 2010 4:53 AM
  • User384031199 posted

    Hi,

    Try KeyValuePair instead of DictionaryEntry as given below.

    foreach (KeyValuePair<string, AcroFields.Item> de in pdfReader.AcroFields.Fields)
    {
        sb.Append(de.Key.ToString() + Environment.NewLine);
    }
    

    Hope this helps.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 27, 2010 5:00 AM
  • User-1719701746 posted

    Thanks..

    Saturday, November 27, 2010 5:39 AM
  • User-777992925 posted

    Know this post is a more than a month old but the solution also works in VB code as well...

    For Each de As KeyValuePair(Of String, AcroFields.Item) In pdfReader.AcroFields.Fields
                sb.Append(de.Key.ToString() + Environment.NewLine)
    Next</ST< PRE>
    


     

    Tuesday, January 11, 2011 10:10 AM