繁体   English   中英

如何从pdf文件中获取字段名称?

[英]How to get the fields name from a pdf file?

我在iframe中有一个pdf文件,我想检查pdf文件以了解字段名称,以允许用户从文本框中填充此字段。

这是我的iframe和文本框,例如:

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

这是在iframe中显示pdf的代码:

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

请帮我解决这个问题。

您要做的并不是简单的编程任务。 PDF文件格式非常复杂,因此您几乎肯定会需要使用第三方代码库来读取/修改PDF的内容。 我以前使用过一个名为iTextSharp的库,效果不错,但是要花钱。

找到PDF操作库并阅读使用方法后,您可以使用它在PDF中搜索输入字段,并在文件中读取/写入这些字段的值。 但是,您可能必须自己编写所有Web代码才能获取用户输入并将其传递到您的PDF代码库中。

您可以查看Spire.PDF。 它提供了丰富的功能来处理.NET应用程序中的PDF文件。 它有商业版和免费版 检查下面的代码以查看是否有帮助,我假设您提到的字段类型是“文本框”字段。

//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();

注意:我是Spire的员工。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM