Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Dec 20, 2019 7:55 am

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

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Fri Dec 20, 2019 8:58 am

Hi GH,

Thanks for your inquiry.
In general, we get the fields in tabulator order.
Do you encounter any issue? Please provide your input PDF and the detailed information along with the order you want for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Dec 20, 2019 9:18 am

Hi Betsy,

I think the fields come in the order in which I created the fields

lg GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Fri Dec 20, 2019 9:56 am

Hi GH,

Thanks for your file.
We just checked the order of the fields in PDF tool(PDFPatcher), and our Spire gets the correct corresponding order:
Code: Select all
1.ErstDT 2. RNR 3. Mont_Start 4. Begründung  5. Beschreibung  6. Hinweis  7. Vorleistung  8. Mont_Ende  9. Kostenschätzung

What is your desired order?
Besides, if you want to fill the fields, the better way is filling it according to the name of the field.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Dec 20, 2019 12:46 pm

Hi Betsy,
I'll don't think so.
A placed a pciture inside the zip-file.


1.RNR 2. ErstDT 3. Beschreibung 4.Mont_Start 5.Mont-Ende 6.Begründung 7.Kostenschätzung 8. Hinweis 7. Vorleistung

lg Gh

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Mon Dec 23, 2019 2:51 am

Hi GH,

Thanks for your information.
I have transferred your information to our Dev team. We will do further investigation and keep you informed about the progress.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jan 21, 2020 3:29 am

Hi GH,

Thanks for waiting.
After further investigation, we found a solution to achieve your target. Please refer to following code:
Code: Select all
       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;
        }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Feb 05, 2020 10:04 am

Hi,

Hope you are doing well.
Do you try the code I provided? Has your issue been resolved?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF