如何使用ABCpdf查看PDF文本框字段是否为多行?

时间:2014-01-27 19:25:02

标签: c# pdf abcpdf

我可以使用ABCpdf使用GetFieldNames()集合遍历PDF中的所有字段并获取它们的属性,但是我似乎无法获得的是该字段是否是多行文本字段。有没有关于如何找到这个属性的例子?如果它有用,我的代码在下面,但它可能是不必要的。

    ....

    foreach (string fieldName in doc.Form.GetFieldNames())
    {
        WebSupergoo.ABCpdf9.Objects.Field f = doc.Form[fieldName];
        dt = GetFieldInstances(dt,f);
    }

    ....

    private static DocumentTemplate GetFieldInstances(DocumentTemplate dt, WebSupergoo.ABCpdf9.Objects.Field f)
    {
        Field field;
        Instance inst = new Instance(); 
        int instanceCount = 0;
        bool fieldAlreadyExists = dt.Fields.Any(currentField => currentField.Name == f.Name);
        if (!fieldAlreadyExists)
        {
            field = new Field();
            field.Name = f.Name;
            field.Value = f.Value;
            field.Format = f.Format == null ? null : f.Format;
            field.PartialName = f.PartialName;
            field.TypeID = (int)f.FieldType;

            //field.IsMultiline = 
            //field.IsRequired = 
        }
        else
        {
            field = (from currentField in dt.Fields where currentField.Name == f.Name select currentField).SingleOrDefault();
            instanceCount = field.Instances.Count();
        }

        if ((Field.FieldTypes)f.FieldType == Field.FieldTypes.Radio || (Field.FieldTypes)f.FieldType == Field.FieldTypes.Checkbox)
        {
            inst.ExportValue = f.Options[instanceCount];
        }
        if (f.Kids.Count() > 0)
        {
            f = f.Kids[instanceCount];
        }
        inst.Bottom = (int)f.Rect.Bottom;
        inst.Height = (int)f.Rect.Height;
        inst.Left = (int)f.Rect.Left;
        inst.Width = (int)f.Rect.Width;
        inst.PageNumber = f.Page.PageNumber;




        field.Instances.Add(inst);

        if (!fieldAlreadyExists)
        {
            dt.Fields.Add(field);
        }
        return dt;
    }

1 个答案:

答案 0 :(得分:1)

我明白了:

public bool GetIsMultiLine(WebSupergoo.ABCpdf9.Objects.Field field)
{
    var flags = Atom.GetInt(Atom.GetItem(field.Atom, "Ff"));
    var isMultiLine = GetIsBitFlagSet(flags, 13);
    return isMultiLine;
}

public bool GetIsRequired(WebSupergoo.ABCpdf9.Objects.Field field)
{
    var flags = Atom.GetInt(Atom.GetItem(field.Atom, "Ff"));
    var isRequired = GetIsBitFlagSet(flags, 2);
    return isRequired;
}

public bool GetIsReadOnly(WebSupergoo.ABCpdf9.Objects.Field field)
{
    var flags = Atom.GetInt(Atom.GetItem(field.Atom, "Ff"));
    var isReadOnly = GetIsBitFlagSet(flags, 1);
    return isReadOnly;
}

private static bool GetIsBitFlagSet(int b, int pos)
{
    return (b & (1 << (pos - 1))) != 0;
}

如果您不熟悉无符号整数/二进制转换,I found this site really helpful to understand.

例如,让我们说为字段标记返回的整数等于4096.如果您将其输入该网站的online coversion tool,它将显示第13位打开位置(从右侧开始,第13个位置为1而不是0)。

在ABCPdf指南中,它表示Multi-Line位是位13,因此您知道该字段是多行字段。

同样,对于必需的第二个位置和只读的第一个位置。