Hey,
is it possible to get the PDF Fields (FieldsWidget) in the right tabulator order?
For i As Integer = 0 To _FW.FieldsWidget.List.Count - 1
_Field = _FW.FieldsWidget.List(i)
_FeldType = _Field.ToString
next
mfg GH
1.ErstDT 2. RNR 3. Mont_Start 4. Begründung 5. Beschreibung 6. Hinweis 7. Vorleistung 8. Mont_Ende 9. Kostenschätzung
static private List<PdfField> fieldNewList;
public static void T20012()
{
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(filePath + @"Anlage 04 - Regieantrag.pdf");
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
PdfFormFieldWidgetCollection collection = formWidget.FieldsWidget;
fieldNewList = SetFieldOrderNumber(collection);
for (int i = 0; i < fieldNewList.Count; i++)
{
PdfField PdfFieldfield = fieldNewList[i] as PdfField;
}
}
static private List<PdfField> SetFieldOrderNumber(PdfFormFieldWidgetCollection collection)
{
Dictionary<int, PointF> dictionary = new Dictionary<int, PointF>();
RectangleF rect = new RectangleF();
float x, y, height;
for (int i = 0; i < collection.Count; i++)
{ rect = (collection[i] as PdfStyledFieldWidget).Bounds;
x = rect.X;
y = rect.Y;
height = rect.Height;
dictionary.Add(i, new PointF(x, y + height));
}
return SetFieldOrderNumber(dictionary, collection);
}
static private List<PdfField> SetFieldOrderNumber(Dictionary<int, PointF> dictionary, PdfFormFieldWidgetCollection collection)
{
System.Collections.Generic.List<KeyValuePair<int, PointF>> oldList = new System.Collections.Generic.List<KeyValuePair<int, PointF>>(dictionary);
System.Collections.Generic.List<KeyValuePair<int, PointF>> tempList = new System.Collections.Generic.List<KeyValuePair<int, PointF>>();
System.Collections.Generic.List<KeyValuePair<int, PointF>> newList = new System.Collections.Generic.List<KeyValuePair<int, PointF>>();
oldList.Sort(delegate(KeyValuePair<int, PointF> s1, KeyValuePair<int, PointF> s2)
{
return s1.Value.Y.CompareTo(s2.Value.Y);
}
);
List<PdfField> fieldNewList = new List<PdfField>();
int count = 0;
while (count < oldList.Count)
{
while (true)
{
tempList.Add(oldList[count]);
if (count == oldList.Count - 1 || oldList[count].Value.Y != oldList[count + 1].Value.Y)
{
tempList.Sort(delegate(KeyValuePair<int, PointF> s1, KeyValuePair<int, PointF> s2)
{ return s1.Value.X.CompareTo(s2.Value.X); }
);
count++;
break;
}
count++;
}
newList.InsertRange(newList.Count, tempList);
tempList.Clear();
}
IList list = collection.List;
for (int i = 0; i < newList.Count; i++)
{
PdfField field = list[newList[i].Key] as PdfField;
fieldNewList.Add(field);
}
return fieldNewList;
}