【问题标题】:Get the PDF page that contains the PdfTextField获取包含 PdfTextField 的 PDF 页面
【发布时间】:2012-10-18 20:57:50
【问题描述】:

我们需要获取包含特定PdfTextField的PpdfPage,怎么做?

代码:

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[???];

【问题讨论】:

  • 你用的是什么库 itextsharp?
  • 根据标签是pdfsharp。
  • @retslig PdfSharp,我们过去使用过 itextsharp,但 PdfSharp 许可证更加开放

标签: c# .net pdf pdfsharp


【解决方案1】:

最后我们解决了这个问题:

    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;
}

不是最好的解决方案,但它确实有效...如果有人添加了更好的解决方案,我们将为他/她提供正确的答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-06
    • 2014-10-23
    • 2020-02-17
    • 2013-11-02
    • 2014-06-10
    • 2016-10-17
    • 2019-04-25
    • 2010-10-14
    相关资源
    最近更新 更多