2

如何使用 Aspose PDF 检索表单域的页码?我试图通过放置每个页面的图像并使用页码、坐标和尺寸覆盖每个字段来以 HTML 格式重新创建 PDF 表单。

这是我当前的代码:

public static List<PdfFieldDisplayModel> GetFieldPlacements(Stream stream)
    {
        var fields = new List<PdfFieldDisplayModel>();
        var doc = new Document(stream);
        var pdfForm = new Aspose.Pdf.Facades.Form(stream);

        foreach (Field ff in doc.Form)
        {
            var txt = doc.Form[ff.Name] as TextBoxField;
            var f = new PdfFieldDisplayModel();
            f.PageNumber = ??????????????
            f.Name = ff.Name;
            f.PartialName = ff.PartialName;
            f.Value = ff.Value;
            f.Width = txt.Rect.Width;
            f.Height = txt.Rect.Height;
            f.Left = txt.Rect.LLX;
            f.Bottom = txt.Rect.LLY;
            fields.Add(f);
        }
        return fields;
    }
4

1 回答 1

2

我叫 Nayyer,是 Aspose 的开发人员传播者。为了获取表单字段的页面索引,请尝试使用Aspose.Pdf.InteractiveFeatures.Forms.Field实例的PageIndex属性。

[C#]

//open document
Document pdfDocument = new Document("c:/pdftest/SingleField_output.pdf","password");
//get values from all fields

foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in pdfDocument.Form)
{
    //get field value
    Console.WriteLine("PartialName : {0} ", formField.PartialName);
    Console.WriteLine("Value : {0} ", formField.Value);
    Console.WriteLine("Value : {0} ", formField.PageIndex);
}
于 2015-07-06T08:56:23.923 回答