Beispiel #1
0
        public override Dictionary <string, Field> GetUpdateFields()
        {
            ComboBoxField primary     = new ComboBoxField(keyValueData.Keys, "Номер госрегистрации автомобиля");
            TextField     surname     = new TextField("Фамилия");
            TextField     name        = new TextField("Имя");
            TextField     second_name = new TextField("Отчество");
            TextField     address     = new TextField("Адрес");

            primary.SelectedValueChanged += (string newPrimary) =>
            {
                object[] newCurrent = keyValueData[newPrimary];

                surname.SetValue(newCurrent[1]);
                name.SetValue(newCurrent[2]);
                second_name.SetValue(newCurrent[3]);
                address.SetValue(newCurrent[4]);
            };

            primary.ResetSelectedItem();

            return(new Dictionary <string, Field>
            {
                { "auto_register_number", primary },
                { "surname", surname },
                { "name", name },
                { "second_name", second_name },
                { "address", address }
            });
        }
        public void ValueChanged(BaseEntryForm EntryForm, object sender)
        {
            BaseField field = sender as BaseField;

            switch (field.Name)
            {
            // Physical State Explication
            case nameof(Departure.Type):
            {
                ComboBoxField DepartureTypeField = field as ComboBoxField;

                DepartureType DepartureType = (DepartureType)DepartureTypeField.Value;

                if (DepartureType == DepartureType.Externe)
                {
                    EntryForm.Fields[nameof(Departure.Observations)].Hide();
                }
                else
                {
                    EntryForm.Fields[nameof(Departure.Observations)].Show();
                }
            }
            break;
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // create Document object
            Document doc = new Document();

            // add page to document object
            doc.Pages.Add();

            // instantiate ComboBox Field object
            ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));

            // add option to ComboBox
            combo.AddOption("Red");
            combo.AddOption("Yellow");
            combo.AddOption("Green");
            combo.AddOption("Blue");

            // add combo box object to form fields collection of document object
            doc.Form.Add(combo);

            // save the PDF document
            doc.Save(dataDir + "ComboBox_out.pdf");
        }
Beispiel #4
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

            // create Document object
            Document doc = new Document();

            // add page to document object
            doc.Pages.Add();

            // instantiate ComboBox Field object
            ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));

            // add option to ComboBox
            combo.AddOption("Red");
            combo.AddOption("Yellow");
            combo.AddOption("Green");
            combo.AddOption("Blue");

            // add combo box object to form fields collection of document object
            doc.Form.Add(combo);

            // save the PDF document
            doc.Save(dataDir + "ComboBox_out.pdf");

        }
Beispiel #5
0
 public ComboBoxFieldViewModel(ComboBoxField comboBoxField) : base(comboBoxField)
 {
     ComboBoxField       = comboBoxField;
     SelectedItem        = ComboBoxField.DefaultSelectedItem;
     DefaultSelectedItem = ComboBoxField.DefaultSelectedItem;
     Items = new ObservableCollection <string>(comboBoxField.Items);
 }
Beispiel #6
0
        public void PutComboBoxFieldTest()
        {
            const string name = "PdfWithAcroForm.pdf";

            UploadFile(name, name);
            var comboBox = new ComboBoxField(PageIndex: 1, IsGroup: false, Selected: 2)
            {
                Color       = new Color(255, 255, 0, 0),
                Rect        = new Rectangle(100, 100, 160, 140),
                PartialName = "testField",
                Margin      = new MarginInfo {
                    Bottom = 0, Left = 0, Right = 0, Top = 0
                },
                Options = new List <Option>
                {
                    new Option
                    {
                        Name  = "one",
                        Value = "one",
                    },
                    new Option
                    {
                        Name     = "two",
                        Value    = "two",
                        Selected = true,
                    },
                }
            };


            var response = PdfApi.PutComboBoxField(name, fieldName: "comboboxField", comboBox, folder: TempFolder);

            Assert.That(response.Code, Is.EqualTo(200));
        }
        public override Dictionary <string, Field> GetDeleteFields()
        {
            if (keyValueData.Count == 0)
            {
                throw new NoRowsToEditException();
            }

            User user = Program.Container.GetCurrentUser();

            IEnumerable <string> comboValues = user.Role.Name == "worker" ? GetCurrentUserKeys() : keyValueData.Keys;

            if (comboValues.Count() == 0)
            {
                throw new NoRowsToEditException();
            }

            ComboBoxField combo = new ComboBoxField(comboValues, "Id");

            combo.ResetSelectedItem();

            return(new Dictionary <string, Field>
            {
                { "id", combo }
            });
        }
Beispiel #8
0
        public override Dictionary <string, Field> GetUpdateFields()
        {
            ComboBoxField primary   = new ComboBoxField(keyValueData.Keys, "Номер госрегистрации");
            TextField     newRegNum = new TextField("Новый номер госрегистрации");
            TextField     mark      = new TextField("Марка");
            TextField     year      = new TextField("Год выпуска");
            TextField     creator   = new TextField("Изготовитель");

            primary.SelectedValueChanged += (string newPrimary) =>
            {
                object[] newCurrent = keyValueData[newPrimary];
                newRegNum.SetValue(newPrimary);
                mark.SetValue(newCurrent[1]);
                year.SetValue(newCurrent[2]);
                creator.SetValue(newCurrent[3]);
            };

            primary.ResetSelectedItem();

            return(new Dictionary <string, Field>
            {
                { "register_number", primary },
                { "new_register_number", newRegNum },
                { "mark", mark },
                { "year", year },
                { "creator", creator },
            });
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // create Document object
            Document doc = new Document();

            // add page to document object
            doc.Pages.Add();

            // instantiate ComboBox Field object
            ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));

            // add option to ComboBox
            combo.AddOption("Red");
            combo.AddOption("Yellow");
            combo.AddOption("Green");
            combo.AddOption("Blue");

            // add combo box object to form fields collection of document object
            doc.Form.Add(combo);

            // save the PDF document
            doc.Save(dataDir + "output.pdf");
        }
Beispiel #10
0
        public UpdateFieldsBuilder SetPrimary(string key, IEnumerable <string> values, string title = "")
        {
            primary     = new ComboBoxField(values, title);
            result[key] = primary;

            return(this);
        }
        /// <summary>
        /// CreateField in EntryForm
        ///
        /// </summary>
        /// <param name="param">
        /// param.PropertyInfo
        /// param.Location
        /// param.OrientationField
        /// param.SizeLabel
        /// param.SizeControl
        /// param.ConfigProperty
        /// param.TabIndex
        /// param.Service
        /// param.ConfigEntity
        /// param.TabControlForm
        /// param.Entity
        /// param.ConteneurFormulaire
        /// </param>
        /// <returns>the created field</returns>
        public BaseField CreateField_In_EntryForm(CreateFieldParams param)
        {
            ComboBoxField comboBoxField = new ComboBoxField();

            comboBoxField.StopAutoSizeConfig();
            comboBoxField.Name             = param.PropertyInfo.Name;
            comboBoxField.Location         = param.Location;
            comboBoxField.OrientationField = param.OrientationField;
            comboBoxField.SizeLabel        = param.SizeLabel;
            comboBoxField.SizeControl      = param.SizeControl;

            comboBoxField.TabIndex   = param.TabIndex;
            comboBoxField.Text_Label = param.ConfigProperty.DisplayProperty.Title;
            comboBoxField.ConfigSizeField();

            // DataSource
            //var DataObject = Activator.CreateInstance(param.ConfigProperty.DataSource.TypeObject);
            //IList ls_data = (IList)DataObject.GetType().GetMethod(param.ConfigProperty.DataSource.MethodeName).Invoke(DataObject, null);
            IList ls_data = param.ConfigProperty.DataSource.GetData();

            List <object> ls_data_object = ls_data.Cast <string>().ToList <object>();


            comboBoxField.DataSource = ls_data_object;

            // Insertion à l'interface
            param.ConteneurFormulaire.Controls.Add(comboBoxField);
            return(comboBoxField);
        }
        public BaseField CreateField_In_Filter(CreateField_In_Filter_Params param)
        {
            ComboBoxField stringFiled = new ComboBoxField();

            stringFiled.StopAutoSizeConfig();
            stringFiled.Name             = param.ConfigProperty.PropertyInfo.Name;
            stringFiled.SizeLabel        = param.SizeLabel;
            stringFiled.SizeControl      = param.SizeControl;
            stringFiled.OrientationField = Orientation.Horizontal;
            stringFiled.TabIndex         = param.TabIndex;
            stringFiled.Text_Label       = param.ConfigProperty.DisplayProperty.Title;

            stringFiled.ConfigSizeField();

            // DataSource
            IList         ls_data        = param.ConfigProperty.DataSource.GetData();
            List <string> ls_data_string = ls_data.Cast <Object>().Select(o => o.ToString()).ToList <string>();

            // Add Blank Data
            if (param.ConfigProperty.Filter.isDefaultIsEmpty)
            {
                ls_data_string.Insert(0, "");
            }
            stringFiled.DataSource = ls_data_string.ToList <object>();



            param.FilterContainer.Controls.Add(stringFiled);

            return(stringFiled);
        }
Beispiel #13
0
        private static void CreateFields(RadFixedDocument document)
        {
            CheckBoxField check = new CheckBoxField("checkBox");

            document.AcroForm.FormFields.Add(check);
            check.IsChecked = true;

            ComboBoxField combo = new ComboBoxField("combo");

            document.AcroForm.FormFields.Add(combo);
            combo.Options.Add(new ChoiceOption("Combo choice 1"));
            combo.Options.Add(new ChoiceOption("Combo choice 2"));
            combo.Options.Add(new ChoiceOption("Combo choice 3"));
            combo.Options.Add(new ChoiceOption("Combo choice 4"));
            combo.Options.Add(new ChoiceOption("Combo choice 5"));
            combo.Value = combo.Options[2];

            CombTextBoxField comb = new CombTextBoxField("comb");

            document.AcroForm.FormFields.Add(comb);
            comb.MaxLengthOfInputCharacters = 10;
            comb.Value = "0123456789";

            ListBoxField list = new ListBoxField("list");

            document.AcroForm.FormFields.Add(list);
            list.AllowMultiSelection = true;
            list.Options.Add(new ChoiceOption("List choice 1"));
            list.Options.Add(new ChoiceOption("List choice 2"));
            list.Options.Add(new ChoiceOption("List choice 3"));
            list.Options.Add(new ChoiceOption("List choice 4"));
            list.Options.Add(new ChoiceOption("List choice 5"));
            list.Options.Add(new ChoiceOption("List choice 6"));
            list.Options.Add(new ChoiceOption("List choice 7"));
            list.Value = new ChoiceOption[] { list.Options[0], list.Options[2] };

            PushButtonField push = new PushButtonField("push");

            document.AcroForm.FormFields.Add(push);

            RadioButtonField radio = new RadioButtonField("radio");

            document.AcroForm.FormFields.Add(radio);
            radio.Options.Add(new RadioOption("Radio option 1"));
            radio.Options.Add(new RadioOption("Radio option 2"));
            radio.Value = radio.Options[1];

            SignatureField signature = new SignatureField("signiture");

            document.AcroForm.FormFields.Add(signature);

            TextBoxField textBox = new TextBoxField("textBox");

            document.AcroForm.FormFields.Add(textBox);
            textBox.Value = "Sample text...";
        }
Beispiel #14
0
        public override Dictionary <string, Field> GetDeleteFields()
        {
            ComboBoxField combo = new ComboBoxField(keyValueData.Keys, pasport.Title);

            combo.ResetSelectedItem();

            return(new Dictionary <string, Field>
            {
                { pasport.Code, combo }
            });
        }
Beispiel #15
0
        public override Dictionary <string, Field> GetDeleteFields()
        {
            ComboBoxField combo = new ComboBoxField(keyValueData.Keys, "Номер госрегистрации автомобиля");

            combo.ResetSelectedItem();

            return(new Dictionary <string, Field>
            {
                { "auto_register_number", combo }
            });
        }
        public object GetFieldValue_From_Filter(Control FilterContainer, ConfigProperty ConfigProperty)
        {
            ComboBoxField stringFiled = (ComboBoxField)FilterContainer.Controls.Find(ConfigProperty.PropertyInfo.Name, true).First();

            if (stringFiled.Value?.ToString() != "")
            {
                return(stringFiled.Value);
            }
            else
            {
                return(null);
            }
        }
        public object GetFieldValue_From_Filter(Control FilterContainer, ConfigProperty ConfigProperty)
        {
            ComboBoxField comboBoxField = (ComboBoxField)FilterContainer.Controls.Find(ConfigProperty.PropertyInfo.Name, true).First();

            var empty_instance = Activator.CreateInstance(ConfigProperty.PropertyInfo.PropertyType);

            if (comboBoxField.Value != empty_instance)
            {
                return(comboBoxField.Value);
            }
            else
            {
                return(null);
            }
        }
        public override void Create(VisualElement root)
        {
            var comboBox = new ComboBoxField("Ice Cream");

            comboBox.IsDelayed = true;
            comboBox.Options   = new List <string>
            {
                "Chocolate",
                "Vanilla",
                "Rocky Road",
                "Cookies and Cream",
                "Mint Chocolate Chip",
                "Moose Tracks"
            };

            comboBox.RegisterValueChangedCallback(evt => Debug.Log($"Selected {evt.newValue}"));
            root.Add(comboBox);
        }
Beispiel #19
0
        protected override void CopyProperties(DataControlField newField)
        {
            base.CopyProperties(newField);

            ComboBoxField field = newField as ComboBoxField;

            if (field != null)
            {
                field.AppendDataBoundItems = this.AppendDataBoundItems;
                field.AutoPostBack         = this.AutoPostBack;
                field.DataSource           = this.DataSource;
                field.DataSourceId         = this.DataSourceId;
                field.DataTextField        = this.DataTextField;
                field.DataValueField       = this.DataValueField;
                field.Description          = this.Description;
                field.SelectedValue        = this.SelectedValue;
                field.HtmlEncode           = this.HtmlEncode;
            }
        }
        public void ValueChanged(BaseEntryForm EntryForm, object sender)
        {
            BaseField field = sender as BaseField;

            switch (field.Name)
            {
            // Physical State Explication
            case nameof(Material.PhysicalState):
            {
                ComboBoxField PhysicalstateField = field as ComboBoxField;

                PhysicalStates PhysicalState = (PhysicalStates)PhysicalstateField.Value;

                if (PhysicalState == PhysicalStates.autre)
                {
                    EntryForm.Fields[nameof(Material.PhysicalStateExplication)].Show();
                }
            }
            break;
            }
        }
        /// <summary>
        /// CreateField in EntryForm
        ///
        /// </summary>
        /// <param name="param">
        /// param.PropertyInfo
        /// param.Location
        /// param.OrientationField
        /// param.SizeLabel
        /// param.SizeControl
        /// param.ConfigProperty
        /// param.TabIndex
        /// param.Service
        /// param.ConfigEntity
        /// param.TabControlForm
        /// param.Entity
        /// param.ConteneurFormulaire
        /// </param>
        /// <returns>the created field</returns>
        public BaseField CreateField_In_EntryForm(CreateFieldParams param)
        {
            // Create Field
            ComboBoxField comboBoxField = new ComboBoxField();

            comboBoxField.StopAutoSizeConfig();
            comboBoxField.Name             = param.PropertyInfo.Name;
            comboBoxField.Location         = param.Location;
            comboBoxField.OrientationField = param.OrientationField;
            comboBoxField.SizeLabel        = param.SizeLabel;
            comboBoxField.SizeControl      = param.SizeControl;
            comboBoxField.TabIndex         = param.TabIndex;
            comboBoxField.Text_Label       = param.ConfigProperty.DisplayProperty.Title;
            comboBoxField.ConfigSizeField();

            // DataSource
            comboBoxField.DataSource = Enum.GetValues(param.PropertyInfo.PropertyType).Cast <object>().ToList <object>();

            // Insert field in Form
            param.ConteneurFormulaire.Controls.Add(comboBoxField);
            return(comboBoxField);
        }
Beispiel #22
0
        public override object ReadJson(JsonReader reader,
                                        Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jo = JObject.Load(reader);

            var type = jo["Type"]?.Value <string>();

            FormElement item = null;

            switch (type)
            {
            case nameof(ButtonElement):
                item = new ButtonElement();
                break;

            case nameof(HtmlElement):
                item = new HtmlElement();
                break;

            case nameof(TextField):
                item = new TextField();
                break;

            case nameof(ComboBoxField):
                item = new ComboBoxField();
                break;

            case nameof(CheckBoxField):
                item = new CheckBoxField();
                break;

            default:
                return(null);
            }

            serializer.Populate(jo.CreateReader(), item);

            return(item);
        }
        /// <summary>
        /// Create Field in Filter
        /// </summary>
        /// <param name="param"></param>
        /// <returns>Created field instance</returns>
        public BaseField CreateField_In_Filter(CreateField_In_Filter_Params param)
        {
            // Create Field
            ComboBoxField comboBoxField = new ComboBoxField();

            comboBoxField.StopAutoSizeConfig();
            comboBoxField.Name             = param.ConfigProperty.PropertyInfo.Name;
            comboBoxField.SizeLabel        = param.SizeLabel;
            comboBoxField.SizeControl      = param.SizeControl;
            comboBoxField.OrientationField = Orientation.Horizontal;
            comboBoxField.TabIndex         = param.TabIndex;
            comboBoxField.Text_Label       = param.ConfigProperty.DisplayProperty.Title;
            comboBoxField.ConfigSizeField();

            // DataSource
            comboBoxField.DataSource = Enum.GetValues(param.ConfigProperty.PropertyInfo.PropertyType).Cast <object>().ToList <object>();

            // Insert Field in Filter
            param.FilterContainer.Controls.Add(comboBoxField);

            return(comboBoxField);
        }
        public FormElementEditorViewModel()
        {
            _elementNameTextBox = new TextField("elementNameTextBox", LabelPosition.AboveElement, "Name",
                                                new ValidationRule <TextField>[]
            {
            });

            _elementLabelTextBox = new TextField("elementLabelTextBox", LabelPosition.AboveElement, "Label",
                                                 new ValidationRule <TextField>[]
            {
            });

            _elementTypeComboBox = new ComboBoxField("elementTypeComboBox", LabelPosition.AboveElement,
                                                     "Type",
                                                     new ValidationRule <ComboBoxField>[]
            {
                new ComboBoxSelectionRequiredValidationRule()
            }, new[] { "Button", "Html", "CheckBox", "ComboBox", "TextBox" });

            _elementTypeComboBox.OnFormEvent += ElementTypeComboBoxOnOnFormEvent;
            _elementNameTextBox.OnFormEvent  += ElementNameTextBoxOnOnFormEvent;
            _elementLabelTextBox.OnFormEvent += ElementLabelTextBoxOnOnFormEvent;
        }
        public static void Run()
        {
            try
            {
                // ExStart:ComboBox
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

                // Create Document object
                Document doc = new Document();

                // Add page to document object
                doc.Pages.Add();

                // Instantiate ComboBox Field object
                ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));

                // Add option to ComboBox
                combo.AddOption("Red");
                combo.AddOption("Yellow");
                combo.AddOption("Green");
                combo.AddOption("Blue");

                // Add combo box object to form fields collection of document object
                doc.Form.Add(combo);
                dataDir = dataDir + "ComboBox_out.pdf";
                // Save the PDF document
                doc.Save(dataDir);
                // ExEnd:ComboBox
                Console.WriteLine("\nCombobox field added successfully.\nFile saved at " + dataDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #26
0
        public static void Run()
        {
            try
            {
                // ExStart:ComboBox
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

                // Create Document object
                Document doc = new Document();

                // Add page to document object
                doc.Pages.Add();

                // Instantiate ComboBox Field object
                ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));

                // Add option to ComboBox
                combo.AddOption("Red");
                combo.AddOption("Yellow");
                combo.AddOption("Green");
                combo.AddOption("Blue");

                // Add combo box object to form fields collection of document object
                doc.Form.Add(combo);
                dataDir = dataDir + "ComboBox_out_.pdf";
                // Save the PDF document
                doc.Save(dataDir);
                // ExEnd:ComboBox
                Console.WriteLine("\nCombobox field added successfully.\nFile saved at " + dataDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #27
0
 public ComboBoxFieldResult(ComboBoxField comboBoxField, IEnumerable <string> items, string selectedItem) : base(
         comboBoxField)
 {
     Items        = items;
     SelectedItem = selectedItem;
 }
Beispiel #28
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);
        }
Beispiel #29
0
        public IHttpActionResult UploadPic(UploadPicModel uploadPicModel)
        {
            var      fullPath         = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId);
            var      downloadFileName = "document.pdf";
            var      documentFileName = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId, downloadFileName);
            Document doc = new Document(documentFileName);

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("/img/Test.png"));

            for (int i = 0; i < uploadPicModel.shapes.Count; i++)
            {
                //create stamp
                Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

                float shapeX = (uploadPicModel.shapes[i].x * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeY = (uploadPicModel.shapes[i].y * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeW = (uploadPicModel.shapes[i].w * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeH = (uploadPicModel.shapes[i].h * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);

                double yaxis = (float)(doc.Pages[uploadPicModel.shapes[i].p].Rect.URY - (shapeH + shapeY));

                var isSpecial = true;                //regexItem.IsMatch(uploadPicModel.shapes[i].imName);

                if (uploadPicModel.shapes[i].Itype == "highlight" || uploadPicModel.shapes[i].Itype == "image")
                {
                    imageStamp = uploadPicModel.shapes[i].Itype == "highlight"
                                                ? new ImageStamp(HttpContext.Current.Server.MapPath("/img/test.png"))
                                                : new ImageStamp(fullPath + uploadPicModel.shapes[i].imName);

                    imageStamp.Background = false;
                    imageStamp.XIndent    = (float)(shapeX);
                    imageStamp.YIndent    = (float)(yaxis);
                    imageStamp.Height     = shapeH;
                    imageStamp.Width      = shapeW;

                    //Add stamp to particular page
                    doc.Pages[uploadPicModel.shapes[i].p].AddStamp(imageStamp);
                }
                else if (uploadPicModel.shapes[i].Itype == "text")
                {
                    //create text stamp
                    TextStamp textStamp = new TextStamp(uploadPicModel.shapes[i].t);
                    textStamp.XIndent = (float)(shapeX);
                    textStamp.YIndent = (float)(yaxis);
                    //rotate stamp
                    textStamp.RotateAngle = 360 - (Convert.ToDouble(uploadPicModel.shapes[i].fieldType) * 180 / Math.PI);

                    //set text properties
                    textStamp.TextState.Font     = FontRepository.FindFont(uploadPicModel.shapes[i].n);
                    textStamp.TextState.FontSize = Convert.ToInt32(uploadPicModel.shapes[i].s) * 0.75f;

                    if (uploadPicModel.shapes[i].wt == "bold")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Bold;
                    }

                    if (uploadPicModel.shapes[i].st == "italic")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Italic;
                    }


                    textStamp.TextState.ForegroundColor = GetColor(uploadPicModel.shapes[i].c);
                    //add stamp to particular page
                    doc.Pages[uploadPicModel.shapes[i].p].AddStamp(textStamp);
                }
                else if (uploadPicModel.shapes[i].Itype == "field" && isSpecial)
                {
                    if (uploadPicModel.shapes[i].fieldType == "Text")
                    {
                        // Get a field
                        TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as TextBoxField;
                        // Modify field value
                        textBoxField.Value = uploadPicModel.shapes[i].t;
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "CheckBox")
                    {
                        // Get a field
                        CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as CheckboxField;
                        if (uploadPicModel.shapes[i].t != "")
                        {
                            // Modify field value
                            checkBoxField.Checked = Convert.ToBoolean(uploadPicModel.shapes[i].t);
                        }
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "Radio")
                    {
                        RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)];

                        RadioButtonField rbf = (RadioButtonField)field.Parent;
                        if (Convert.ToBoolean(uploadPicModel.shapes[i].t))
                        {
                            rbf.Selected = rbf.Options[field.OptionName].Index;
                        }
                        else
                        {
                            field.ActiveState = "Off";
                        }
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "ComboBox")
                    {
                        // Get a field
                        ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as ComboBoxField;
                        var           values        = uploadPicModel.shapes[i].t.Split(new[] { "^^^" }, StringSplitOptions.None)[0];

                        foreach (var item in comboBoxField.Options.Cast <Option>())
                        {
                            if (item.Value == values)
                            {
                                comboBoxField.Selected = item.Index;
                            }
                        }
                    }
                }
            }

            doc.Save(Config.Configuration.OutputDirectory + "/Export.pdf");

            return(Ok(new DocStatusModel()));
        }
Beispiel #30
0
        public static void UploadPic(List <shap> shapes, string filename, string aspectRatio)
        {
            Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf"));

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));

            for (int i = 0; i < shapes.Count; i++)
            {
                //create stamp
                Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

                float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);

                double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY));

                var isSpecial = true;//regexItem.IsMatch(shapes[i].imName);

                if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image")
                {
                    if (shapes[i].Itype == "highlight")
                    {
                        imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));
                    }
                    else
                    {
                        imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/" + shapes[i].imName));
                    }

                    imageStamp.Background = false;
                    imageStamp.XIndent    = (float)(shapeX);
                    imageStamp.YIndent    = (float)(yaxis);
                    imageStamp.Height     = shapeH;
                    imageStamp.Width      = shapeW;

                    //Add stamp to particular page
                    doc.Pages[shapes[i].p].AddStamp(imageStamp);
                }
                else if (shapes[i].Itype == "text")
                {
                    /*
                     * // create TextBuilder for first page
                     * TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]);
                     *
                     * // TextFragment with sample text
                     * TextFragment fragment = new TextFragment(shapes[i].t);
                     *
                     * // set the font for TextFragment
                     * fragment.TextState.Font = FontRepository.FindFont(shapes[i].n);
                     * fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s);
                     * if (shapes[i].wt == "bold")
                     * {
                     *  fragment.TextState.FontStyle = FontStyles.Bold;
                     * }
                     *
                     * if (shapes[i].st == "italic")
                     * {
                     *  fragment.TextState.FontStyle = FontStyles.Italic;
                     * }
                     *
                     * // set the formatting of text as Underline
                     * // fragment.TextState.Underline = true;
                     * fragment.TextState.ForegroundColor = GetColor(shapes[i].c);
                     * // specify the position where TextFragment needs to be placed
                     * fragment.Position = new Position((float)(shapeX), (float)(yaxis));
                     *
                     * // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);
                     *
                     * // append TextFragment to PDF file
                     * tb.AppendText(fragment);
                     */

                    //create text stamp
                    TextStamp textStamp = new TextStamp(shapes[i].t);
                    //set whether stamp is background
                    // textStamp.Background = true;
                    //set origin
                    textStamp.XIndent = (float)(shapeX);
                    textStamp.YIndent = (float)(yaxis);
                    //rotate stamp
                    textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);

                    //set text properties
                    textStamp.TextState.Font     = FontRepository.FindFont(shapes[i].n);
                    textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f;

                    if (shapes[i].wt == "bold")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Bold;
                    }

                    if (shapes[i].st == "italic")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Italic;
                    }


                    textStamp.TextState.ForegroundColor = GetColor(shapes[i].c);
                    //add stamp to particular page
                    doc.Pages[shapes[i].p].AddStamp(textStamp);
                }
                else if (shapes[i].Itype == "field" && isSpecial)
                {
                    if (shapes[i].fieldType == "Text")
                    {
                        // Get a field
                        TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField;
                        // Modify field value
                        textBoxField.Value = shapes[i].t;
                    }
                    else if (shapes[i].fieldType == "CheckBox")
                    {
                        // Get a field
                        CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField;
                        if (shapes[i].t != "")
                        {
                            // Modify field value
                            checkBoxField.Checked = Convert.ToBoolean(shapes[i].t);
                        }
                    }
                    else if (shapes[i].fieldType == "Radio")
                    {
                        RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)];

                        RadioButtonField rbf = (RadioButtonField)field.Parent;
                        if (Convert.ToBoolean(shapes[i].t))
                        {
                            rbf.Selected = rbf.Options[field.OptionName].Index;
                        }
                        else
                        {
                            field.ActiveState = "Off";
                        }
                    }
                    else if (shapes[i].fieldType == "ComboBox")
                    {
                        // Get a field
                        ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField;
                        var           values        = shapes[i].t.Split(new string[] { "^^^" }, StringSplitOptions.None)[0];

                        foreach (var item in comboBoxField.Options.Cast <Option>())
                        {
                            if (item.Value == values)
                            {
                                comboBoxField.Selected = item.Index;
                            }
                        }
                    }
                }
            }

            doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf"));
        }
Beispiel #31
0
        private static void DrawPageWithWidgets(RadFixedDocument document)
        {
            RadFixedPage page = document.Pages.AddPage();

            FixedContentEditor editor = new FixedContentEditor(page);

            using (editor.SaveGraphicProperties())
            {
                editor.GraphicProperties.IsFilled        = true;
                editor.GraphicProperties.IsStroked       = false;
                editor.GraphicProperties.StrokeThickness = 0;
                editor.GraphicProperties.FillColor       = new RgbColor(209, 178, 234);
                editor.DrawRectangle(new Rect(50, 50, editor.Root.Size.Width - 100, editor.Root.Size.Height - 100));
            }

            editor.Position.Translate(100, 100);
            Size widgetDimensions = new Size(200, 30);

            foreach (FormField field in document.AcroForm.FormFields)
            {
                switch (field.FieldType)
                {
                case FormFieldType.CheckBox:
                    CheckBoxField check = (CheckBoxField)field;
                    DrawNextWidgetWithDescription(editor, "CheckBox", (e) => e.DrawWidget(check, widgetDimensions));
                    break;

                case FormFieldType.ComboBox:
                    ComboBoxField combo = (ComboBoxField)field;
                    DrawNextWidgetWithDescription(editor, "ComboBox", (e) => e.DrawWidget(combo, widgetDimensions));
                    break;

                case FormFieldType.CombTextBox:
                    CombTextBoxField comb = (CombTextBoxField)field;
                    DrawNextWidgetWithDescription(editor, "Comb TextBox", (e) => e.DrawWidget(comb, widgetDimensions));
                    break;

                case FormFieldType.ListBox:
                    ListBoxField list = (ListBoxField)field;
                    DrawNextWidgetWithDescription(editor, "ListBox", (e) => e.DrawWidget(list, new Size(widgetDimensions.Width, widgetDimensions.Width)));
                    break;

                case FormFieldType.PushButton:
                    PushButtonField push = (PushButtonField)field;
                    DrawNextWidgetWithDescription(editor, "Button", (e) => e.DrawWidget(push, widgetDimensions));
                    break;

                case FormFieldType.RadioButton:
                    RadioButtonField radio = (RadioButtonField)field;
                    foreach (RadioOption option in radio.Options)
                    {
                        DrawNextWidgetWithDescription(editor, option.Value, (e) => e.DrawWidget(radio, option, widgetDimensions));
                    }
                    break;

                case FormFieldType.Signature:
                    SignatureField signature = (SignatureField)field;
                    DrawNextWidgetWithDescription(editor, "Signature", (e) => e.DrawWidget(signature, widgetDimensions));
                    break;

                case FormFieldType.TextBox:
                    TextBoxField textBox = (TextBoxField)field;
                    DrawNextWidgetWithDescription(editor, "TextBox", (e) => e.DrawWidget(textBox, widgetDimensions));
                    break;
                }
            }
        }
Beispiel #32
0
        public void CreatePDF(Stream stream)
        {
            var        doc  = new GcPdfDocument();
            var        page = doc.NewPage();
            var        g    = page.Graphics;
            TextFormat tf   = new TextFormat();

            tf.Font     = StandardFonts.Times;
            tf.FontSize = 14;
            PointF ip        = new PointF(72, 72);
            float  fldOffset = 72 * 2;
            float  fldHeight = tf.FontSize * 1.2f;
            float  dY        = 32;

            // Text field:
            g.DrawString("Text field:", tf, ip);
            var fldText = new TextField();

            fldText.Value                      = "Initial TextField value";
            fldText.Widget.Page                = page;
            fldText.Widget.Rect                = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldText.Widget.TextFormat.Font     = tf.Font;
            fldText.Widget.TextFormat.FontSize = tf.FontSize;
            doc.AcroForm.Fields.Add(fldText);
            ip.Y += dY;

            // Checkbox:
            g.DrawString("Checkbox:", tf, ip);
            var fldCheckbox = new CheckBoxField();

            fldCheckbox.Value       = true;
            fldCheckbox.Widget.Page = page;
            fldCheckbox.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight);
            doc.AcroForm.Fields.Add(fldCheckbox);
            ip.Y += dY;

            // Radio button:
            g.DrawString("Radio button:", tf, ip);
            var fldRadio = new RadioButtonField();

            fldRadio.Value = 1;
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight)));
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y + fldHeight * 1.2f, fldHeight, fldHeight)));
            fldRadio.Widgets.Add(new WidgetAnnotation(page, new RectangleF(ip.X + fldOffset, ip.Y + (fldHeight * 1.2f) * 2, fldHeight, fldHeight)));
            doc.AcroForm.Fields.Add(fldRadio);
            ip.Y = fldRadio.Widgets[fldRadio.Widgets.Count - 1].Rect.Y + dY;

            // CombTextField:
            g.DrawString("CombText field:", tf, ip);
            var fldCombText = new CombTextField();

            fldCombText.Value = "123";
            fldCombText.Widget.TextFormat.FontSize = 12;
            fldCombText.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldCombText.Widget.Page = page;
            doc.AcroForm.Fields.Add(fldCombText);
            ip.Y += dY;

            // Combo-box:
            g.DrawString("Combo box:", tf, ip);
            var fldComboBox = new ComboBoxField();

            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 1"));
            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 2"));
            fldComboBox.Items.Add(new ChoiceFieldItem("ComboBox Choice 3"));
            fldComboBox.SelectedIndex = 1;
            fldComboBox.Widget.Rect   = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
            fldComboBox.Widget.Page   = page;
            doc.AcroForm.Fields.Add(fldComboBox);
            ip.Y += dY;

            // List box:
            g.DrawString("List box:", tf, ip);
            ListBoxField fldListBox = new ListBoxField();

            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 1"));
            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 2"));
            fldListBox.Items.Add(new ChoiceFieldItem("ListBox Choice 3"));
            fldListBox.SelectedIndexes   = new int[] { 0, 2 };
            fldListBox.MultiSelect       = true;
            fldListBox.CommitOnSelChange = true;
            fldListBox.Widget.Rect       = new RectangleF(ip.X + fldOffset, ip.Y, 100, 50);
            fldListBox.Widget.Page       = page;
            doc.AcroForm.Fields.Add(fldListBox);
            ip.Y = fldListBox.Widget.Rect.Bottom - fldHeight + dY;

            // Signature field:
            g.DrawString("Signature field:", tf, ip);
            var fldSignature = new SignatureField();

            fldSignature.AlternateName = "All fields locked when the document is signed";
            fldSignature.LockedFields  = new SignatureLockedFields();
            fldSignature.Widget.Rect   = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 2, 72 - dY);
            fldSignature.Widget.TextFormat.FontSize      = 8;
            fldSignature.Widget.ButtonAppearance.Caption = "Click to sign";
            fldSignature.Widget.Border = new Border()
            {
                Width = 0.5f, Color = Color.DarkSeaGreen
            };
            fldSignature.Widget.Page = page;
            doc.AcroForm.Fields.Add(fldSignature);
            ip.Y += 72 - fldHeight;

            // Buttons:
            g.DrawString("Push buttons:", tf, ip);

            // Submit form button:
            var btnSubmit = new PushButtonField();

            btnSubmit.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72, fldHeight);
            btnSubmit.Widget.ButtonAppearance.Caption = "Submit";
            btnSubmit.Widget.Highlighting             = HighlightingMode.Invert;
            btnSubmit.Widget.Events.Activate          = new ActionSubmitForm("Sample Form Submit URI");
            btnSubmit.Widget.Page = page;
            doc.AcroForm.Fields.Add(btnSubmit);
            // ip.Y += dY;

            // Reset form button:
            var btnReset = new PushButtonField();

            btnReset.Widget.Rect = new RectangleF(ip.X + fldOffset + 72 * 1.5f, ip.Y, 72, fldHeight);
            btnReset.Widget.ButtonAppearance.Caption = "Reset";
            btnReset.Widget.Highlighting             = HighlightingMode.Invert;
            btnReset.Widget.Events.Activate          = new ActionResetForm();
            btnReset.Widget.Page = page;
            doc.AcroForm.Fields.Add(btnReset);
            ip.Y += dY;

            // Done:
            doc.Save(stream);
        }