jsreport API .net Wrapper
Inheritance: IReportingService
Exemple #1
0
        private static void Main(string[] args)
        {
            var service = new ReportingService("https://playground.jsreport.net");

            using (var fileStream = File.Create("report.pdf"))
            {
                var report = service.RenderAsync("eyaNpy1ho", 11, new {
                        books = new[]
                            {
                                new Book() {name = "A Tale of Two Cities", author = "Charles Dickens", sales = 351},
                                new Book() {name = "The Lord of the Rings", author = "J. R. R. Tolkien", sales = 156},
                                new Book() {name = "The Da Vinci Code", author = "Dan Brown", sales = 280},
                                new Book() {name = "The Hobbit", author = "J. R. R. Tolkien", sales = 170}
                            }}).Result;

            report.Content.CopyTo(fileStream);
        }
    }
Exemple #2
0
        public static void Main()
        {
            var embededReportingServer = new EmbeddedReportingServer();
            embededReportingServer.StartAsync().Wait();

            var reportingService = new ReportingService(embededReportingServer.EmbeddedServerUri);
            reportingService.SynchronizeTemplatesAsync().Wait();
            Thread.Sleep(15000);

            var rs = new ReportingService("http://localhost:2000");
            var r = rs.GetServerVersionAsync().Result;

           
            var result = rs.RenderAsync("Report1", null).Result;
            
            Console.WriteLine("Done");
            embededReportingServer.StopAsync().Wait();
        }
Exemple #3
0
        public FileStreamResult PdfView(string viewPath, object model)
        {
            var rgx = new Regex (@"(src|href)\s?=\s?('|"")/");
            var content = RenderView (viewPath, model);
            string result = rgx.Replace (content, string.Format ("$1=$2{0}/", WebConfig.AppServerUrl));
            var reportingService = new ReportingService (ReportServerUrl);
            var report = reportingService.RenderAsync (new RenderRequest {
                template = new Template {
                    content = result,
                    engine = "none",
                    recipe = "phantom-pdf",
                    phantom = new Phantom {
                        format = "Letter",
                        headerHeight = "0 mm",
                        footerHeight = "0 mm",
                        margin = "6 mm"
                    }
                }
            }).Result;

            return File (report.Content, MIME_TYPE_PDF);
        }
Exemple #4
0
        public Stream GetPdf(string viewPath, object model, Phantom phantom)
        {
            var rgx = new Regex (@"(src|href)\s?=\s?('|"")/");
            string content = rgx.Replace (RenderView (viewPath, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl));

            var reportingService = new ReportingService (ReportServerUrl);

            if (!string.IsNullOrWhiteSpace (phantom.header)) {
                phantom.header = rgx.Replace (RenderPartialView (phantom.header, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl));
            }

            if (!string.IsNullOrWhiteSpace (phantom.footer)) {
                phantom.footer = rgx.Replace (RenderPartialView (phantom.footer, model), string.Format ("$1=$2{0}/", WebConfig.AppServerUrl));
            }

            if (string.IsNullOrWhiteSpace (phantom.format)) {
                phantom.format = "Letter";
            }

            if (string.IsNullOrWhiteSpace (phantom.margin)) {
                phantom.margin = "6 mm";
            }

            var report = reportingService.RenderAsync (new RenderRequest {
                template = new Template {
                    content = content,
                    engine = "none",
                    recipe = "phantom-pdf",
                    phantom = phantom
                }
            }).Result;

            return report.Content;
        }