public void GenerateEventReport(int eventId) { var rs = new LocalReporting() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); var r = new PaxResult { pos = 1, number = 25, class_name = "GS", car = "GTI", name = "Aaron Hall", best_run = 33.456, pax_time = 30.234, diff = 0, from_first = 0, points = 10000 }; var p = new Pax { year = 2019, event_num = 5, date = "8/19/2018", drivers = new List <PaxResult>() }; for (int i = 0; i < 200; ++i) { p.drivers.Add(r); } var json = JsonConvert.SerializeObject(p); var invoiceReport = rs.RenderByNameAsync("EventPaxReport", json).Result; invoiceReport.Content.CopyTo(File.OpenWrite("event.pdf")); invoiceReport.Content.Close(); rs.KillAsync(); }
static void Main(string[] args) { Console.WriteLine("Initializing local jsreport.exe utility"); var rs = new LocalReporting() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsWebServer() .Create(); rs.StartAsync().Wait(); Console.ReadKey(); Console.WriteLine("Rendering localy stored template jsreport/data/templates/Invoice into invoice.pdf"); var invoiceReport = rs.RenderByNameAsync("Invoice", InvoiceData).Result; invoiceReport.Content.CopyTo(File.OpenWrite("invoice.pdf")); Console.WriteLine("Rendering custom report fully described through the request object into customReport.pdf"); var customReport = rs.RenderAsync(CustomRenderRequest).Result; customReport.Content.CopyTo(File.OpenWrite("customReport.pdf")); byte[] pdfByte = ReadFully(customReport.Content); }
static void Main(string[] args) { try { //Configure the Local JsReportServer as utility //This would save templates in the running application directory (bin/debug) var rs = new LocalReporting() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); //Render the invoice template as PDF, by default is renders as portrait. //If you want to render as landscape, set landscape=true in config.json file of invoice template //Here we are using saved templates in local server. Console.WriteLine("Rendering localy stored template jsreport/data/templates/Invoice into invoice.pdf"); var invoiceReport = rs.RenderByNameAsync("Invoice", InvoiceData).Result; invoiceReport.Content.CopyTo(File.OpenWrite("invoice.pdf")); //Render the sample template as PDF, by default is renders as portrait. //If you want to render as landscape, set landscape=true in below template object. //Here we are managing template from our code Console.WriteLine("Rendering custom report fully described through the request object into customReport.pdf"); var customReport = rs.RenderAsync(CustomRenderRequest).Result; customReport.Content.CopyTo(File.OpenWrite("customReport.pdf")); } catch (Exception ex) { throw ex; } }
public async Task <string> Generate(object data) { string msg = "success"; try { System.Diagnostics.Debug.WriteLine("Initializing local jsreport.exe utility"); Console.WriteLine("Initializing local jsreport.exe utility"); var rs = new LocalReporting() .RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")) .KillRunningJsReportProcesses() .UseBinary(JsReportBinary.GetBinary()) .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); Console.WriteLine("Rendering localy stored template jsreport/data/templates/Invoice into invoice.pdf"); var studentReport = rs.RenderByNameAsync("ReportTemplate", data).Result; using (var fs = File.Create("ReportCard\\StudentReport.pdf")) { studentReport.Content.CopyTo(fs); fs.Close(); } } catch (Exception ex) { msg = ex.Message; } return(msg); }
static void Main(string[] args) { Console.WriteLine("Rendering template"); var rs = new LocalReporting() .UseBinary(JsReportBinary.GetBinary()) .KillRunningJsReportProcesses() .Configure(cfg => cfg.FileSystemStore().BaseUrlAsWorkingDirectory()) .AsUtility() .Create(); var report = rs.RenderByNameAsync("myTemplate", null).Result; using (var fs = File.Create("test.pdf")) { report.Content.CopyTo(fs); } }