Combine 2 pdfs created using mvc razor views
-
Hi I am a bit confused on how I can combine the pdfs created from 2 separate razor views. One thing I was trying was to save the report content to a byte[] and then return that for both views and go from there to merge the pdfs but the byte[] is always empty:
[EnableJsReport()] public byte[] /*ActionResult*/ Overview() { MemoryStream buffer = new MemoryStream(); HttpContext.JsReportFeature().Recipe(Recipe.ChromePdf) .Configure((r) => { r.Template.Chrome = new Chrome { Landscape = true, Format = "A4", MediaType = MediaType.Screen, MarginBottom = "50px", MarginLeft = "0px", MarginRight = "50px", MarginTop = "50px" }; }) .OnAfterRender((r) => { r.Content.CopyTo(buffer); //r.Content.Seek(0, SeekOrigin.Begin); }); return buffer.ToArray(); }
The other option I was trying was to create a template which I found from another forum post, but I am not sure how to get the razor view content into the string content for the template:
var rs = new LocalReporting().UseBinary(JsReportBinary.GetBinary()).AsUtility().Create(); var report = await rs.RenderAsync(new RenderRequest() { Template = new Template() { Recipe = Recipe.ChromePdf, Engine = Engine.None, Content = "" //how to get razor view here? } }); var memoryStream = new MemoryStream(); await report.Content.CopyToAsync(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin);
-
Calling pdf utils from .net client can look like this
https://jsreport.net/learn/dotnet-client#pdf-utilsYou now need to call both views, get the string from it and pass it as
Content
.
I believe you can use controller extension methodRenderViewToString
.
Check its source here