Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
        public async Task <Report> Render <T>(string template, string format, T content)
        {
            var rs = new LocalReporting()
                     .UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                jsreport.Binary.JsReportBinary.GetBinary() :
                                jsreport.Binary.Linux.JsReportBinary.GetBinary())
                     .AsUtility()
                     .Create();

            var report = await rs.RenderAsync(new RenderRequest
            {
                Template = new Template
                {
                    Recipe  = MapFormatToRecipe(format),
                    Engine  = Engine.Handlebars,
                    Content = template
                },
                Data = new
                {
                    trades = content
                }
            });

            return(report);
        }
        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);
        }
        public HttpResponseMessage Get()
        {
            var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();



            var report = rs.RenderAsync(new RenderRequest()
            {
                Template = new Template()
                {
                    Recipe  = Recipe.PhantomPdf,
                    Engine  = Engine.Handlebars,
                    Content = "Hello from pdf, {{message}}",
                    Phantom = new Phantom {
                        Header = "<div style='text-align:center'>Page number {#pageNum}/{#numPages}</div>"
                    }
                },
                Data = new
                {
                    message = "B&A Migrando a jsreport for .NET!!!"
                }
            }).Result;



            string nombre = "Test";
            HttpResponseMessage response = DescargarPdf(ReadFully(report.Content), nombre);

            return(response);
        }
Beispiel #5
0
        public async Task <IActionResult> Get()
        {
            var html = await RazorTemplateEngine.RenderAsync("~/Views/PdfTemplate.cshtml");

            var rs = new LocalReporting()
                     .KillRunningJsReportProcesses()
                     .UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? JsReportBinary.GetBinary() : jsreport.Binary.Linux.JsReportBinary.GetBinary())
                     .Configure(cfg => cfg.AllowedLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
                     .AsUtility()
                     .Create();

            var generatedPdf = await rs.RenderAsync(new RenderRequest
            {
                Template = new Template
                {
                    Recipe  = Recipe.ChromePdf,
                    Engine  = Engine.None,
                    Content = html,
                    Chrome  = new Chrome
                    {
                        MarginTop    = "10",
                        MarginBottom = "10",
                        MarginLeft   = "50",
                        MarginRight  = "50"
                    }
                }
            });

            return(File(generatedPdf.Content, generatedPdf.Meta.ContentType, "GeneratedPdfFile.pdf"));
        }
        public async Task <IHttpActionResult> Post(CertificateGeneratorDTO payload)
        {
            var ex  = new Exception();
            var msg = string.Empty;

            try
            {
                var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary())
                         .Configure(cfg => cfg.AllowedLocalFilesAccess().BaseUrlAsWorkingDirectory())
                         .AsUtility().Create();

                var report = await rs.RenderAsync(new RenderRequest()
                {
                    Template = new Template()
                    {
                        Recipe  = Recipe.PhantomPdf,
                        Engine  = Engine.Handlebars,
                        Content = "Hello from pdf"
                    }
                });

                return(Ok(new { data = string.Empty, msg }));
            }
            catch (Exception caughtEx)
            {
                return(BadRequest(msg));
            }
        }
        public HttpResponseMessage GetMultiple()
        {
            var           rs       = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();
            List <string> mensajes = new List <string> {
                "1", "2", "3"
            };

            List <Stream> streamPdfs = new List <Stream>();


            foreach (var m in mensajes)
            {
                var report = rs.RenderAsync(new RenderRequest()
                {
                    Template = new Template()
                    {
                        Recipe  = Recipe.PhantomPdf,
                        Engine  = Engine.Handlebars,
                        Content = "Hello from pdf, {{message}}",
                        Phantom =
                            new Phantom {
                            Header = "B&A Systems SAS",
                            Footer = "<div style='text-align:center'>Page number {#pageNum}/{#numPages}</div>",
                        }
                    },
                    Data = new
                    {
                        message = $"B&A Migrando a jsreport for .NET!!! {m}"
                    }
                }).Result;

                streamPdfs.Add(report.Content);
            }
            byte[] result = null;

            using (MemoryStream ms = new MemoryStream())
            {
                Document pdfDoc   = new Document(PageSize.A4);
                PdfCopy  pdfUnido = new PdfCopy(pdfDoc, ms);
                pdfDoc.Open();
                streamPdfs.ForEach(item =>
                {
                    var itemPdf = new PdfReader(item);
                    pdfUnido.AddDocument(itemPdf);
                });
                pdfDoc.Close();
                result = ms.ToArray();
                result = ms.ToArray();
            }
            string nombre = "Test Multiple";
            HttpResponseMessage response = DescargarPdf(result, nombre);

            return(response);
        }
Beispiel #8
0
        public async Task <ActionResult <string> > GeneratePdf(string semestre)
        {
            var rs           = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();
            var templateHtml = @"<h1 style='color: #5e9ca0;'>Hola</h1>
                                <h2> &nbsp;</h2>
                                <table>
                                <thead>
                                <tr>
                                <td> Example </td>
                                <td>Default</td>
                                </tr>
                                </thead>
                                <tbody>
                                <tr>
                                <td> {{nombre}}</td>
                                <td> {{semestre}}</td>
                                </tr>
                                </tbody>
                                </table>
                                <p><strong>&nbsp;</strong></p>";
            var report       = await rs.RenderAsync(new RenderRequest()
            {
                Template = new Template
                {
                    Content = templateHtml,

                    Engine = Engine.Handlebars,
                    Recipe = Recipe.ChromePdf
                },
                Data = new
                {
                    nombre   = $"Programación Web - Unicesar!!!",
                    semestre = semestre
                }
            });

            return(new FileStreamResult(report.Content, "application/pdf"));
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            var rs = new LocalReporting()
                     .UseBinary(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                jsreport.Binary.JsReportBinary.GetBinary() :
                                jsreport.Binary.Linux.JsReportBinary.GetBinary())
                     .AsUtility()
                     .Create();

            var report = rs.RenderAsync(new RenderRequest()
            {
                Template = new Template()
                {
                    Recipe  = Recipe.PhantomPdf,
                    Engine  = Engine.None,
                    Content = "Hello"
                }
            }).Result;

            var content = new StreamReader(report.Content).ReadToEnd();

            Console.WriteLine(content);
        }
Beispiel #10
0
        public async Task <IActionResult> Localreport()
        {
            var header = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });

            var footer = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Footer", new { });

            var body = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Invoice", new { });

            var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create();

            var report = await rs.RenderAsync(new RenderRequest()
            {
                Template = new Template()
                {
                    Recipe  = Recipe.PhantomPdf,
                    Engine  = Engine.None,
                    Content = body
                }
            });

            HttpContext.JsReportFeature()
            //.DebugLogsToResponse()
            .Recipe(Recipe.PhantomPdf)
            .Configure((r) => r.Template.Phantom = new Phantom
            {
                Header          = header,
                Footer          = footer,
                Format          = PhantomFormat.A4,
                Margin          = "0cm",
                BlockJavaScript = false
            })

            .OnAfterRender((r) =>
                           HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\""
                           );
            return(View("../Report/Invoice", InvoiceModel.Example()));
        }
Beispiel #11
0
        GeneratePdf(string solicitud2)
        {
            var       response  = _service.BuscarSolicitud(solicitud2);
            Solicitud solicitud = new Solicitud();

            if (response.Error)
            {
            }
            else
            {
                solicitud = response.Solicitud;
            }
            var rs =
                new LocalReporting()
                .UseBinary(JsReportBinary.GetBinary())
                .AsUtility()
                .Create();
            var templateHtml =
                @"<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <link href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css' rel='stylesheet'
        integrity='sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1' crossorigin='anonymous'>
    <title>Document</title>
</head>

<body>
    <div class='container'>
        <div>
            <form>
                <header style='text-align: center;'>
                    <h1>Consulta de solicitud</h1>
                </header>

                <div style='padding-top: 50px;'>

                </div>

                <div class='card'>
                    <table class='table table-striped table-bordered table-sm'>
                        <tbody>
                            <tr>
                                <td>ID</td>
                                <td>{{solicitud.Persona.Identificacion}}</td>
                            </tr>

                            <tr>
                                <td>Docente</td>
                                <td>{{solicitud.Persona.Nombre}} {{solicitud.Persona.Apellidos}}</td>
                            </tr>

                            <tr>
                                <td>Estado</td>
                                <div>
                                    <td>{{solicitud.Estado}}</td>
                                </div>
                            </tr>

                            <tr>
                                <td>Periodo Academico</td>
                                <td>{{solicitud.PeriodoAcademico.Periodo}} Corte: {{solicitud.PeriodoAcademico.Corte}}</td>
                            </tr>

                            <tr>
                                <td>Asignatura</td>
                                <td>{{solicitud.Asignatura.Nombre}}</td>
                            </tr>

                            <tr>
                                <td>Monitor</td>
                                <td>{{solicitud.Monitor}}</td>
                            </tr>

                            <tr>
                                <td>Cantidad Insumos</td>
                                <td>{{solicitud.CantidadInsumos}}</td>
                            </tr>
                            <tr>
                                <td>Fecha y hora solicitud</td>
                                <td>{{solicitud.SolicitudFecha}}</td>
                            </tr>
                            <tr>
                                <td>Fecha y Hora entrega</td>
                                <td>{{solicitud.Fecha}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

                <table class='table'>
                    <thead>
                        <tr>
                            <th scope='col'>Items</th>
                            <th scope='col'>Descripción</th>
                            <th scope='col'>Marca</th>
                            <th scope='col'>Cantidad</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{#each detalles}}
                            <tr>
                                <td> {{NumeroDetalle}} </td>
                                <td> {{Insumo.Descripcion}} </td>
                                <td> {{Insumo.Marca}} </td>
                                <td> {{Cantidad}} </td>
                            </tr>
                        {{/each}}
                    </tbody>
                </table>
            </form>
        </div>
    </div>
    <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js'
        integrity='sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW'
        crossorigin='anonymous'></script>
</body>

</html>";
            var report =
                await rs
                .RenderAsync(new RenderRequest()
            {
                Template =
                    new Template {
                    Content = templateHtml,
                    Engine  = Engine.Handlebars,
                    Recipe  = Recipe.ChromePdf
                },
                Data =
                    new {
                    nombre    = $"Programación Web - Unicesar!!!",
                    solicitud = solicitud,
                    detalles  = solicitud.Detalles
                }
            });

            return(new FileStreamResult(report.Content, "application/pdf"));
        }