Working with Forms from Code
Our sample projects and report templates can help you learn the basics of working with our products.This example is outdated, you can check out the many other new examples in this category.This example shows how to work with forms from code.
First, create action links:
Next, create
After that, create action methods. First, add
Then, add
Next, add
Finally, add
First, create action links:
@Html.ActionLink("Creating a Form", "Create")
@Html.ActionLink("Loading a Form", "Load")
@Html.ActionLink("Saving a Form", "Save")
@Html.ActionLink("Exporting a Form to PDF", "Export")
Next, create
StiForm object:
private static StiForm Form = new StiForm();
After that, create action methods. First, add
Create method:
public IActionResult Create()
{
var textBox = new StiTextBoxElement
{
Label = "Example Text Box",
Geometry = new StiRectangleGeometry(0, 0, 400, 100).WithMaxWidth(400).WithMaxHeight(100),
Text = "Initial Text",
};
var page = new StiFormPage();
page.Elements.Add(textBox);
HomeController.Form = new StiForm();
HomeController.Form.Pages.Add(page);
ViewBag.FormMessage = "A new Form has been created.";
return View("Index");
}
Then, add
Load method:
public IActionResult Load()
{
var mrtFileName = "Forms\\Order.mrt";
HomeController.Form = new StiForm();
HomeController.Form.Load(mrtFileName);
ViewBag.FormMessage = $"A new Form has been loaded from a file '{mrtFileName}'";
return View("Index");
}
Next, add
Save method:
public IActionResult Save()
{
var mrtFileName = $"Forms\\Form_{DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")}.mrt";
HomeController.Form.Save(mrtFileName);
ViewBag.FormMessage = $"The Form has been saved to a file '{mrtFileName}'";
return View("Index");
}
Finally, add
Export method:
public IActionResult Export()
{
var exporter = new StiPdfExporter(new StiPdfExporterSettings
{
UsePdfA = false,
ReadOnly = false,
});
var pdfFileBytes = exporter.ExportForm(HomeController.Form);
var pdfFileName = $"Forms\\Form_{DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss")}.pdf";
System.IO.File.WriteAllBytes(pdfFileName, pdfFileBytes);
ViewBag.FormMessage = $"The Form has been saved to a file '{pdfFileName}'";
return View("Index");
}