Load a PDF form, add new elements with the Forms API, and return the updated definition to the browser.

Extending an existing form. The controller loads the form, creates new elements, gives them coordinates and sizes, and inserts them into the page collection.

Adding the elements. The relevant action in Adding Components from Code/Controllers/FormsController.cs shows the component hierarchy and the properties assigned to each new control:
static FormsController()
        {
        }

        [HttpPost]
        public IActionResult Action()
        {
            try
            {
                var data = JObject.Parse(this.HttpContext.Request.Form["data"]);
                var action = data["action"].ToString();
                switch (action)
                {
                    case "Initialize":
                        var initData = StiWebForm.Initialize(data, Initialize(data));
                        return Json(initData.Content);

                    default:
                        var result = StiWebForm.ProcessRequest(data);
                        return result.ContentType switch
                        {
                            "application/pdf" => new FileContentResult(result.Content as byte[], result.ContentType),

                            _ => Json(result.Content),
                        };
                }
            }
            catch (Exception e)
            {
                return new ContentResult()
                {
                    Content = e.Message,
                    ContentType = "text/plain"
                };
            }
        }

        private Hashtable Initialize(JObject data)
        {
            var form = new StiForm();
            form.Load(@"Data\SoftwareEvaluationSurvey.mrt");

            AddLogoAndCompanyName(form);

            var options = new Hashtable
            {
                ["form"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(form.SaveToString()))
            };

            return options;
        }

        private void AddLogoAndCompanyName(StiForm form)
        {
            var image = new StiImageElement()
            {
                Geometry = new Stimulsoft.Form.Properties.StiRectangleGeometry(0, 0, 200, 100),
                Image = System.IO.File.ReadAllBytes(@"Data\Logo.png")
            };

            var companyName = new StiLabelElement()
            {
                Geometry = new Stimulsoft.Form.Properties.StiRectangleGeometry(0, 20, 400, 70),
            };
            companyName.Text.Expression = "Company Name";
            companyName.Text.Font = new System.Drawing.Font("Arial", 22);

Back in the browser. After serialization, the updated definition is returned to the Angular component and can be edited like a form loaded from a file.

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.