Question

I can loop through all the fields in a PDF using ABCpdf using the GetFieldNames() collection and get their properties but the one I can't seem to get is whether or not the field is multi-line text field or not. Is there any example out there of how to find this property? My code is below if it's helpful but it's probably unnecessary.

    ....

    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;
    }
Was it helpful?

Solution

I figured it out:

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

In case your not familiar with unsigned integer / binary conversions, I found this site really helpful to understand.

For example, let's say that the integer returned for a field's flags equals 4096. If you enter that into the online coversion tool in that website, it will show you that the 13th bit position is turned on (1 instead of a 0 in the 13th position starting from the right).

In the ABCPdf guide, it says that Multi-Line is bit position 13 so you know that field is a Multi-Line field.

Likewise for the 2nd position for Required and the 1st position for Read-only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top