Download PDF with headers and footers from Phantom without return to view



  • How to Download PDF with headers and footers from Phantom without return to view server side in MVC, it is downloading after return view , but i want to download before return becuase i have multiple prints need to download all at one time.
    The following is my code pelase suggest very urgently .

    HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf).Configure((r) => r.Template.Phantom = new Phantom
            {
                Margin = "0.2.5in",
                HeaderHeight = "2in",
                FooterHeight = "2.1in",
                Height = "15in",
                Header = "<table style='width:100%; height:10px; padding-top :10px;border-top:none; border-left:none;  border-right:none;'><tr><td style='padding-left:90px;'><img src='" + qrcodeimgpath + "'/></td><td style='width:50%; float:right !important;'><img src='" + excelFileDirectory + "' style='height:100px;width:100px; float:right !important;' /></td></tr></table>",
                Footer = "<hr style='max-width:100%; border:1px solid #85929E;'><table style='width: 100%; padding: 5px;'><tbody><tr><td><div style='font-family: Arial !important;width:100%;font-size: 9px;'>Prepared By :" + userName + "</div></td><td><div style='font-family: Arial !important;width:100%;font-size: 9px;'>  Approved By :" + userName + "</div></td></tr></tbody></table> "
                 </td></tr></table></div>",
            }).OnAfterRender((r) =>
            {
                var streamIo = r.Content; // streamIo  is of type System.IO
                using (var fs = System.IO.File.OpenWrite("D:Prints\\" + No.Replace("/", "_") + ".pdf"))
                {
                    streamIo.CopyTo(fs);
                }
                streamIo.Seek(0, SeekOrigin.Begin);
            }).RenderRequest.Template.Content = RenderPartialViewToString("~/Areas/UW/Views/Process/DebitNoteDownload.cshtml", resuult);


  • Please note i need with hears without return view i have multiple prints the same order to print in one click



  • Try to use the IJsReportMVCService .RenderViewAsync

        public class HomeController : Controller
        {
            public IJsReportMVCService JsReportMVCService { get; }
    
            public HomeController(IJsReportMVCService jsReportMVCService)
            {
                JsReportMVCService = jsReportMVCService;
            }
    
           public async Task<IActionResult> ManyReports()
            {
                var rr1 = new RenderRequest { Template = new Template { Recipe = Recipe.ChromePdf, Engine = Engine.None } };
                var firstResult= await JsReportMVCService.RenderView(HttpContext, RouteData, "MyView", new { });
                var rr2 = new RenderRequest { Template = new Template { Recipe = Recipe.ChromePdf, Engine = Engine.None } };
                var secondResult = await JsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "MyView2", new { });
               // do something with the streams and return an action result
          }
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.