Esempio n. 1
0
        public async Task <IActionResult> Invoice()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                QRCodeGenerator qrGenerator = new QRCodeGenerator();
                QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(InvoiceModel.Example().Number, QRCodeGenerator.ECCLevel.Q);
                QRCode          qrCode      = new QRCode(qrCodeData);

                using (Bitmap bitMap = qrCode.GetGraphic(20))
                {
                    bitMap.Save(ms, ImageFormat.Png);
                    ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
                }
            }

            HttpContext.JsReportFeature().Recipe(jsreport.Types.Recipe.ChromePdf)
            .Configure((r) => r.Template.Chrome = new Chrome
            {
                HeaderTemplate      = null,
                DisplayHeaderFooter = false,
                Format       = _config["ReportSetting:Format"],
                MarginTop    = _config["ReportSetting:MarginTop"],
                MarginLeft   = _config["ReportSetting:MarginLeft"],
                MarginBottom = _config["ReportSetting:MarginBottom"],
                MarginRight  = _config["ReportSetting:MarginRight"]
            });
            return(await Task.Run(() => View(InvoiceModel.Example())));
        }
Esempio n. 2
0
        //Without using JSReportAttibute registered in GlobalActionFilter
        public async Task <ActionResult> InvoiceDownloadAsync()
        {
            try
            {
                string filename     = "myReport.pdf";
                var    invoiceModel = InvoiceModel.Example();
                var    htmlContent  = MvcStringHelper.RenderViewToString(this.ControllerContext, "/Views/Home/Invoice.cshtml", invoiceModel);
                (var contentType, var generatedFile) = await GeneratePDFAsync(htmlContent);

                Response.Headers["Content-Disposition"] = $"attachment; filename=\"TestingApp.pdf\"";

                // You may save your file here
                //using (var fileStream = new FileStream(Path.Combine(folder, fileName), FileMode.Create))
                //{
                //    await generatedFile.CopyToAsync(fileStream);
                //}
                // You may need this for re-use of the stream
                generatedFile.Seek(0, SeekOrigin.Begin);
                return(File(generatedFile.ToArray(), "application/pdf", filename));
            }
            catch (Exception ex)
            {
                var test = ex;
                return(null);
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> InvoiceWithCover()
        {
            var coverHtml = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Cover", new { });

            HttpContext.JsReportFeature()
            .Recipe(Recipe.ChromePdf)
            .Configure((r) =>
            {
                r.Template.PdfOperations = new[]
                {
                    new PdfOperation()
                    {
                        Template = new Template
                        {
                            Content = coverHtml,
                            Engine  = Engine.None,
                            Recipe  = Recipe.ChromePdf
                        },
                        Type = PdfOperationType.Prepend
                    }
                };
            });

            return(View("Invoice", InvoiceModel.Example()));
        }
        public IActionResult Items()
        {
            HttpContext.JsReportFeature()
            .Recipe(Recipe.HtmlToXlsx);

            return(View(InvoiceModel.Example()));
        }
Esempio n. 5
0
        public ActionResult Invoice()
        {
            HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf);
            //HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf);

            return(View(InvoiceModel.Example()));
        }
Esempio n. 6
0
        public async Task <IActionResult> Print()
        {
            var header = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });

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

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


                                  //Orientation = PhantomOrientation.Portrait
                                  //WaitForJS = true

                                  //JavascriptDelay = 1000
            })
            .OnAfterRender((r) =>
                           HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\""
                           );

            //var result = await _viewRenderService.RenderToStringAsync("Home/Invoice", InvoiceModel.Example());

            //byte[] array = Encoding.ASCII.GetBytes(result);
            // Stream stream = new MemoryStream(array);

            // var response = FileStreamResult(array, "application/octet-stream"); // FileStreamResult

            return(View("Invoice", InvoiceModel.Example()));
        }
        public async Task <IActionResult> Invoice(string authToken, bool includeConsole, string format, bool landscape, bool attachment)
        {
            //It would be smarter to create and save a one time use token to a session store instead of hard coding _authToken
            if (_authToken == authToken)
            {
                //incoming request from Responsive Paper Service
                return(View(InvoiceModel.Example()));
            }

            //request conversion from Responsive Paper Service
            using var httpClient = new HttpClient();
            var content  = new StringContent(jsonBody(includeConsole, format, landscape), UnicodeEncoding.UTF8, "application/json");
            var response = await httpClient.PostAsync(_responsivePaperSettings.Value.Url, content);

            if (response.IsSuccessStatusCode)
            {
                if (attachment)
                {
                    HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"invoice.pdf\"";
                }
                var stream = await response.Content.ReadAsStreamAsync();

                return(new FileStreamResult(stream, "application/pdf"));
            }
            return(new ContentResult
            {
                Content = _hostingEnv.IsDevelopment() ? await response.Content.ReadAsStringAsync() : "{\"error\": \"Internal Server Error Occurred, please try again\"",
                ContentType = "application/problem+json",
                StatusCode = (int)response.StatusCode
            });
        }
Esempio n. 8
0
        public IActionResult InvoiceDownload()
        {
            HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf)
            .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\"");

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 9
0
        public ActionResult InvoiceDebugLogs()
        {
            HttpContext.JsReportFeature()
            .DebugLogsToResponse()
            .Recipe(Recipe.ChromePdf);

            return(View("Invoice", InvoiceModel.Example()));
        }
        public IActionResult ItemsExcelOnline()
        {
            HttpContext.JsReportFeature()
            .Configure(req => req.Options.Preview = true)
            .Recipe(Recipe.HtmlToXlsx);

            return(View("Items", InvoiceModel.Example()));
        }
        public IActionResult Invoice()
        {
            HttpContext.JsReportFeature()
            // the normal jsreport base url injection into the html doesn't work properly with docker and asp.net because of port mapping
            // the project typically starts with some http://localhost:1234 url but inside docker the url is http://localhost
            .Configure((req) => req.Options.Base = "http://webapp")
            .Recipe(Recipe.ChromePdf);

            return(View(InvoiceModel.Example()));
        }
Esempio n. 12
0
        public ActionResult InvoiceWithHeader()
        {
            HttpContext.JsReportFeature()
            .Recipe(Recipe.PhantomPdf)
            .Configure((r) => r.Template.Phantom = new Phantom {
                Header = this.RenderViewToString("Header", new { })
            });

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 13
0
        public ActionResult Items()
        {
            HttpContext.JsReportFeature()
            .Recipe(Recipe.HtmlToXlsx)
            .Configure((r) => r.Template.HtmlToXlsx = new HtmlToXlsx()
            {
                HtmlEngine = "chrome"
            });

            return(View(InvoiceModel.Example()));
        }
Esempio n. 14
0
        public ActionResult ItemsExcelOnline()
        {
            HttpContext.JsReportFeature()
            .Configure(req => req.Options.Preview = true)
            .Recipe(Recipe.HtmlToXlsx)
            .Configure((r) => r.Template.HtmlToXlsx = new HtmlToXlsx()
            {
                HtmlEngine = "chrome"
            });

            return(View("Items", InvoiceModel.Example()));
        }
        public async Task <IActionResult> InvoiceWithHeader()
        {
            var header = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });

            HttpContext.JsReportFeature()
            .Recipe(Recipe.PhantomPdf)
            .Configure((r) => r.Template.Phantom = new Phantom {
                Header = header
            });

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 16
0
        public async Task <FileResult> PDFAsync()
        {
            string filename     = "myReport.pdf";
            var    invoiceModel = InvoiceModel.Example();
            var    htmlContent  = MvcStringHelper.RenderViewToString(this.ControllerContext, "/Views/Home/Invoice.cshtml", invoiceModel);

            (var contentType, var generatedFile) = await GeneratePDFAsync(htmlContent);

            Response.Headers["Content-Disposition"] = $"attachment; filename=" + filename;
            generatedFile.Seek(0, SeekOrigin.Begin);

            return(File(generatedFile.ToArray(), "application/pdf", filename));
        }
Esempio n. 17
0
        public ActionResult InvoiceWithHeader()
        {
            HttpContext.JsReportFeature()
            .Recipe(Recipe.ChromePdf)
            .Configure((r) => r.Template.Chrome = new Chrome {
                HeaderTemplate      = this.RenderViewToString("Header", new { }),
                DisplayHeaderFooter = true,
                MarginTop           = "2cm",
                MarginLeft          = "1cm",
                MarginBottom        = "2cm",
                FooterTemplate      = " "
            });

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 18
0
        public ActionResult InvoiceDownload()
        {
            try
            {
                HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf)
                .OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\"");
            }
            catch (Exception ex)
            {
                var test = ex;
            }
            var invoiceModel = InvoiceModel.Example();

            return(View(invoiceModel));
        }
Esempio n. 19
0
        public async Task <IActionResult> InvoiceWithHeader()
        {
            var header = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });

            HttpContext.JsReportFeature()
            .Recipe(Recipe.ChromePdf)
            .Configure((r) => r.Template.Chrome = new Chrome {
                HeaderTemplate      = header,
                DisplayHeaderFooter = true,
                MarginTop           = "1cm",
                MarginLeft          = "1cm",
                MarginBottom        = "1cm",
                MarginRight         = "1cm"
            });

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 20
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()));
        }
Esempio n. 21
0
 public async Task <IActionResult> InvoicePrint()
 {
     //var header = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { });
     //var footer = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Footer", new { });
     HttpContext.JsReportFeature()
     //.DebugLogsToResponse()
     //.Engine(Engine.JsRender)
     .Recipe(Recipe.PhantomPdf)
     .Configure((r) => r.Template.Phantom = new Phantom
     {
         //Header = header,
         //Footer = footer,
         BlockJavaScript = false,
         Orientation     = PhantomOrientation.Portrait,
         Format          = PhantomFormat.A4,
         Margin          = "0 cm",
         WaitForJS       = true
     });
     //.Engine(Engine.EJS)
     //.OnAfterRender((r) =>
     //    HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\""
     //);
     return(View("~/Views/Report/Invoice.cshtml", InvoiceModel.Example()));
 }
Esempio n. 22
0
        public ActionResult InvoiceWithHeaderDownload()
        {
            try
            {
                HttpContext.JsReportFeature()
                .Recipe(Recipe.ChromePdf)
                .Configure((r) => r.Template.Chrome = new Chrome
                {
                    HeaderTemplate      = this.RenderViewToString("Header", new { }),
                    DisplayHeaderFooter = true,
                    FooterTemplate      = this.RenderViewToString("Footer", new { }),
                    MarginTop           = "1cm",
                    MarginLeft          = "1cm",
                    MarginBottom        = "1cm",
                    MarginRight         = "1cm"
                }).OnAfterRender((r) => HttpContext.Response.Headers["Content-Disposition"] = "attachment; filename=\"myReport.pdf\"");
            }
            catch (Exception ex)
            {
                var test = ex;
            }

            return(View("Invoice", InvoiceModel.Example()));
        }
Esempio n. 23
0
 public IActionResult Invoice()
 {
     return(View(InvoiceModel.Example()));
 }
        public IActionResult Invoice()
        {
            HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf);

            return(View(InvoiceModel.Example()));
        }
Esempio n. 25
0
 public IActionResult ViewInvoice()
 {
     return(View("~/Views/Report/Invoice.cshtml", InvoiceModel.Example()));
 }