获取包含PdfTextField的PDF页面

时间:2012-10-29 14:17:52

标签: c# .net pdf pdfsharp

我们需要获取包含特定PdfTextField的Pdf页面,我们该怎么做?

代码:

PdfDocument document = PdfReader.Open("C:\\filex.pdf", PdfDocumentOpenMode.Modify);

// Get the root object of all interactive form fields
PdfAcroForm form = document.AcroForm;

// Get all form fields of the whole document
PdfAcroField.PdfAcroFieldCollection fields = form.Fields;

PdfTextField textfield1= (PdfTextField)fields["textfield1"];

//how to get the correct page reference respect the especified field?
PdfPage page = textfield1.Owner.Pages[???];

1 个答案:

答案 0 :(得分:0)

最后我们解决了它创建这个功能:

    protected int PaginaCampo(string campofirma, PdfDocument document)
{
    for (int i = 0; i < document.Pages.Count; i++)
    {
        PdfAnnotations anotations = document.Pages[i].Annotations;
        for (int j = 0; j < anotations.Count; j++)
        {
            if (anotations[j].Title != campofirma) continue;
            return i;
        }
    }
    return -1;
}

不是最好的解决方案,但它有效...如果有人添加更好的解决方案,我们会给他/她正确的答案