how to download jsreport without open using c# in .Net
-
I am Use JS Report for view. This code render the file and and Save in root directory. But I want file is directly download not open for view.
var header = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Header", new { }); var footer = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "Footer", new { }); HttpContext.JsReportFeature() .Recipe(Recipe.ChromePdf) .Configure((r) => { //r.Options = new RenderOptions //{ // Timeout = 600000 //}; r.Template.Chrome = new Chrome { HeaderTemplate = header, FooterTemplate = footer, DisplayHeaderFooter = true, MarginTop = "1cm", MarginLeft = "2cm", MarginBottom = "2cm", MarginRight = "1.5cm", Format = "A3" }; }); HttpContext.JsReportFeature().OnAfterRender((renderer) => { using (var file = System.IO.File.Open("EmployeesList.pdf", FileMode.Create)) { renderer.Content.CopyTo(file); } renderer.Content.Seek(0, SeekOrigin.Begin); });
-
If the browser tries to open the response or triggers its download is distinguished using the standard HTTP response header
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-DispositionYou can find the example here
https://github.com/jsreport/jsreport-dotnet-example-net-webapp/blob/master/Controllers/HomeController.cs#L28
-
Can we create multiple PDF ?
-
Please elaborate...
-
I want create multiple PDFs and download automatically as zip with JsReport in ASP.NET CORE. Is Possible?
-
Hi... Thanks for suggestion. But whole scenario I want single zip file of multiple PDFs and that file download as zip automatically. Is Possible? Is Possible give me any suggestion.
-
You can use the
_jsReportMVCService. RenderViewAsync
to render a view into a pdf.
You can render several of them, zip it and return stream with proper content-disposition header
-
Thanks for suggestions....
-
Hi...... Jan_Blaha thanks for suggestion.. I use _jsReportMVCService. RenderViewAsync as you recommended. But my css not work. My reginal invoice design is . But I get from _jsReportMVCService. RenderViewAsync is . How I resolve this issue?
-
You probably link styles with relative paths.
You either need to:embed whole styles content instead of linking with url
or
link with absolute path
or
set
RenderRequest.Options.Base = 'your app url'
, see how it's done here
https://github.com/jsreport/jsreport-dotnet-mvc/blob/master/jsreport.MVC/JsReportFeature.cs#L32
-
Thanks for suggestion jan_blaha.
-
hi... Now I want to known that How ViewBage value render on view with using
_jsReportMVCService. RenderViewAsync
Please suggest me any query. I stuck that point. I pass model object already to_jsReportMVCService. RenderViewAsync
but my ViewBage value did not render on view.
-
It's quite a while since I was developing the asp.net.
See the function implementation here, perhaps it helps you to figure it out.
https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMVCService.cs#L52
-
how get view bage Value in this method please help me.
and how pass to view.
https://github.com/jsreport/jsreport-dotnet-aspnetcore/blob/master/jsreport.AspNetCore/JsReportMVCService.cs#L52