0

I have a pdf file in an iframe and i want to check the pdf file to know the names of fields to allow user to fill this fields from textboxes.

This is my iframe and textbox for example:

 <iframe id="frmDoc" runat="server"  style="width:800px;height:1200px;"></iframe>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

and this is the code to show the pdf in the iframe:

protected void Page_Load(object sender, EventArgs e)
        {
            frmDoc.Attributes["src"] = "~/admin/minufia/6   نموذج إحصائي رقم.pdf";
        }

Please help me to solve this problem.

Mahmoud Abdo
  • 1
  • 1
  • 1
  • In this example your textbox is not in the iframe. – ErTR Mar 20 '17 at 20:16
  • In a comment to an answer you clarified: *"i already have iTextSharp but i don't know how to use it to search about the input fields in my pdf file"*. If you use iTextSharp 5.x, [How do I enumerate all the fields in a PDF file in ITextSharp](http://stackoverflow.com/q/3041883/1729265) might help you. – mkl Mar 21 '17 at 13:23

2 Answers2

0

What you're wanting to do will not be a simple programming task. PDF file format is very complex, so you will almost certainly need to use a third-party code library to read/modify the contents of a PDF. I've used a library called iTextSharp before with good results, but it costs money.

Once you've found a PDF manipulation library and read how to use it, you can use it to search the PDF for input fields, and read/write the values of those fields within the file. However, you'll probably have to write all of the web code yourself to get the user inputs and pass them into your PDF code library.

Joe Irby
  • 649
  • 6
  • 7
  • i already have iTextSharp but i don't know how to use it to search about the input fields in my pdf file – Mahmoud Abdo Mar 21 '17 at 11:00
  • @MahmoudAbdo Please add important information like your PDF library of choice to the question and update the tags accordingly. Please indicate the iText version you use. – mkl Mar 21 '17 at 13:13
0

You can take a look at Spire.PDF. It provides rich features to manipulate PDF files in .NET applications. It has both commercial and free versions. Check below code to see if it helps, I assume the fields type you mentioned is Text Box field.

//Load the PDF document
        PdfDocument document = new PdfDocument("Input.pdf");

        //Load the existing forms 
        PdfFormWidget loadedForm = document.Form as PdfFormWidget;

        //Go through the forms
        for (int i = 0; i < loadedForm.FieldsWidget.List.Count; i++)
        {                
            PdfField field = loadedForm.FieldsWidget.List[i] as PdfField;
            //Fill textbox form field
            if (field is PdfTextBoxFieldWidget)
            {
                PdfTextBoxFieldWidget textField = field as PdfTextBoxFieldWidget;
                //Get the field name and fill with content
                switch (textField.Name)
                {
                    case "fieldName":
                        textField.Text = "text";
                        break;
                    //```
                }
            }
        }
        //Save and close
        document.SaveToFile("Output.pdf");
        document.Close();

Note: I am an employee of Spire.

Dheeraj Malik
  • 703
  • 1
  • 4
  • 8