Example #1
0
        private static string CheckFields(Document doc, int pageCount, string filename, string fields, double ratio, bool licensed = true)
        {
            double marginLeft = doc.Pages[pageCount].PageInfo.Margin.Left;
            double marginTop  = doc.Pages[pageCount].PageInfo.Margin.Top;

            int fieldcounter = 0;

            Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(doc);

            // Get values from all fields
            foreach (Field formField in doc.Form.Fields)
            {
                double lowerLeftY = (doc.Pages[pageCount].Rect.Height) - (formField.Rect.ToRect().Y + formField.Height);

                double lowerLeftX = formField.Rect.ToRect().X;
                var    fieldType  = formField.GetType().Name;             //pdfForm.GetFieldType(formField.FullName);
                var    imValue    = "";

                if (fieldType.ToString() == "CheckboxField" || fieldType.ToString() == "ComboBoxField" || fieldType.ToString() == "RadioButtonOptionField" || fieldType.ToString() == "TextBoxField")
                {
                    var value = formField.Value;

                    if (fieldType.ToString() == "TextBoxField")
                    {
                        fieldType = "Text";
                    }
                    if (fieldType.ToString() == "CheckboxField")
                    {
                        CheckboxField field = (CheckboxField)formField;
                        if (field.Parent != null)
                        {
                            imValue = field.Parent.FullName;
                        }
                        fieldType = "CheckBox";
                        if (field.Checked)
                        {
                            value = "true";
                        }
                        else
                        {
                            value = "false";
                        }
                    }
                    if (fieldType.ToString() == "RadioButtonOptionField")
                    {
                        RadioButtonOptionField field = (RadioButtonOptionField)formField;
                        RadioButtonField       rbf   = (RadioButtonField)field.Parent;

                        fieldType = "Radio";
                        if (field.Parent != null)
                        {
                            imValue = field.Parent.FullName;
                        }
                        if ((rbf.Options[field.OptionName].Index == rbf.Selected))
                        {
                            value = "true";
                        }
                        else
                        {
                            value = "false";
                        }
                    }
                    if (fieldType.ToString() == "ComboBoxField")
                    {
                        ComboBoxField field     = (ComboBoxField)formField;
                        string        optValues = value;
                        fieldType = "ComboBox";
                        foreach (Option opt in field.Options)
                        {
                            optValues = optValues + "^^^" + opt.Value;
                        }
                        value = optValues;
                    }

                    bool isRequired = pdfForm.IsRequiredField(formField.FullName);
                    //fields += "$#$" + (lowerLeftX * 2.08) * ratio + "$#$" + (lowerLeftY * 2.08) * ratio + "$#$" + (formField.Width * 2.08) * ratio + "$#$" + (formField.Height * 2.08) * ratio + "$#$" + formField.PageIndex + "$#$" + "image" + formField.PageIndex + ".png" + "$#$" + value + "$#$" + formField.DefaultAppearance.FontName + "$#$" + formField.DefaultAppearance.FontSize + "$#$" + " " + "$#$" + " " + "$#$" + " " + "$#$" + ratio + "$#$" + " " + "$#$" + formField.FullName.Replace('/', '-') + "$#$" + fieldType;
                    fields += "$#$" + (lowerLeftX * 2.08) * ratio + "$#$" + (lowerLeftY * 2.08) * ratio + "$#$" + (formField.Width * 2.08) * ratio + "$#$" + (formField.Height * 2.08) * ratio + "$#$" + formField.PageIndex + "$#$" + "image" + formField.PageIndex + ".png" + "$#$" + value + "$#$" + formField.DefaultAppearance.FontName + "$#$" + formField.DefaultAppearance.FontSize + "$#$" + " " + "$#$" + " " + "$#$" + isRequired + "$#$" + ratio + "$#$" + imValue + "$#$" + fieldcounter + "$#$" + fieldType;
                }
                int length = fields.Length;
                fieldcounter += 1;
                if (!licensed && fieldcounter == 5)
                {
                    break;
                }
            }



            return(fields);
        }
        private static string CheckFields(Document doc, int pageCount, string filename, string fields, double ratio, bool licensed)
        {
            double marginLeft = doc.Pages[pageCount].PageInfo.Margin.Left;
            double marginTop = doc.Pages[pageCount].PageInfo.Margin.Top;
                       
            int fieldcounter = 0;
            
            Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(doc);

            // Get values from all fields
            foreach (Field formField in doc.Form.Fields)
            {
                    

                    double lowerLeftY = (doc.Pages[pageCount].Rect.Height) - (formField.Rect.ToRect().Y + formField.Height);

                    double lowerLeftX = formField.Rect.ToRect().X;
                    var fieldType = formField.GetType().Name; //pdfForm.GetFieldType(formField.FullName);
                    var imValue = "";

                    if (fieldType.ToString() == "CheckboxField" || fieldType.ToString() == "ComboBoxField" || fieldType.ToString() == "RadioButtonOptionField" || fieldType.ToString() == "TextBoxField")
                    {
                        var value = formField.Value;

                        if (fieldType.ToString() == "TextBoxField")
                        {
                            fieldType = "Text";
                        }
                        if (fieldType.ToString() == "CheckboxField")
                        {
                            CheckboxField field = (CheckboxField)formField;
                            if (field.Parent != null) 
                            imValue = field.Parent.FullName;
                            fieldType = "CheckBox";
                            if (field.Checked)
                            {
                                value = "true";
                            }
                            else
                            {
                                value = "false";
                            }
                        }
                        if (fieldType.ToString() == "RadioButtonOptionField")
                        {
                            RadioButtonOptionField field = (RadioButtonOptionField)formField;
                            RadioButtonField rbf = (RadioButtonField)field.Parent;

                            fieldType = "Radio";
                            if (field.Parent != null)
                                imValue = field.Parent.FullName;
                            if ((rbf.Options[field.OptionName].Index == rbf.Selected))
                            {
                                value = "true";
                            }
                            else
                            {
                                value = "false";
                            }
                        }
                        if (fieldType.ToString() == "ComboBoxField")
                        {
                            ComboBoxField field = (ComboBoxField)formField;
                            string optValues = value;
                            fieldType = "ComboBox";
                            foreach (Option opt in field.Options)
                            {

                                optValues = optValues + "^^^" + opt.Value;

                            }
                            value = optValues;


                        }

                        bool isRequired = pdfForm.IsRequiredField(formField.FullName);
                        //fields += "$#$" + (lowerLeftX * 2.08) * ratio + "$#$" + (lowerLeftY * 2.08) * ratio + "$#$" + (formField.Width * 2.08) * ratio + "$#$" + (formField.Height * 2.08) * ratio + "$#$" + formField.PageIndex + "$#$" + "image" + formField.PageIndex + ".png" + "$#$" + value + "$#$" + formField.DefaultAppearance.FontName + "$#$" + formField.DefaultAppearance.FontSize + "$#$" + " " + "$#$" + " " + "$#$" + " " + "$#$" + ratio + "$#$" + " " + "$#$" + formField.FullName.Replace('/', '-') + "$#$" + fieldType;
                        fields += "$#$" + (lowerLeftX * 2.08) * ratio + "$#$" + (lowerLeftY * 2.08) * ratio + "$#$" + (formField.Width * 2.08) * ratio + "$#$" + (formField.Height * 2.08) * ratio + "$#$" + formField.PageIndex + "$#$" + "image" + formField.PageIndex + ".png" + "$#$" + value + "$#$" + formField.DefaultAppearance.FontName + "$#$" + formField.DefaultAppearance.FontSize + "$#$" + " " + "$#$" + " " + "$#$" + isRequired + "$#$" + ratio + "$#$" + imValue + "$#$" + fieldcounter + "$#$" + fieldType;
                    }
                    int length = fields.Length;
                    fieldcounter += 1;
                    if (!licensed && fieldcounter == 5)
                    {
                        break;
                    }
            }

            

            return fields;

        }