using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using System.Data; using Stimulsoft.Report; using Stimulsoft.Report.Mvc; using Stimulsoft.Report.Components; using System.IO; using Stimulsoft.Report.Export; using Stimulsoft.Base; using Stimulsoft.Base.Json.Linq; namespace Show_Report_in_the_Viewer.Controllers { public class ViewerController : Controller { static ViewerController() { // How to Activate //Stimulsoft.Base.StiLicense.Key = "6vJhGtLLLz2GNviWmUTrhSqnO..."; //Stimulsoft.Base.StiLicense.LoadFromFile("license.key"); //Stimulsoft.Base.StiLicense.LoadFromStream(stream); } public IActionResult Index() { return View(); } public IActionResult GetReport(int id = 1) { var report = new StiReport(); report.Load(StiNetCoreHelper.MapPath(this, "Reports/PdfCutOffIssue.mrt")); report.CalculationMode = StiCalculationMode.Interpretation; report.Dictionary.Variables.Add("var1", typeof(object)); report.Pages[0].Rendering += (object sender, EventArgs args) => { var page = sender as StiPage; if (!(page is null)) { var isFirstSide = page.Report.PageNumber == 1; page.Margins = new StiMargins( isFirstSide ? 3.5 : 2.5, isFirstSide ? 2 : 0, 1, 0); } }; report.GetComponentByName("DataItems").GetTag += (object sender, Stimulsoft.Report.Events.StiValueEventArgs args) => { (sender as StiComponent).Report["var1"] = sender; }; report.GetComponentByName("DataItems").AfterPrint += (object sender, EventArgs args) => { StiContainer cont = (sender as StiComponent).Report["var1"] as StiContainer; cont.Width = cont.Page.GetColumnWidth(); cont.DockToContainer(); }; var data = JObject.Parse(System.IO.File.ReadAllText(StiNetCoreHelper.MapPath(this, "Reports/PdfCutOffIssue.json"))); var dataSet = StiJsonToDataSetConverterV2.GetDataSet(data); report.RegData(dataSet); report.Dictionary.Synchronize(); report.Render(); return StiNetCoreViewer.GetReportResult(this, report); } public IActionResult ViewerEvent() { return StiNetCoreViewer.ViewerEventResult(this); } } }