Guest User

Untitled

a guest
Jan 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. var context = new HttpContext(new HttpRequest(null, "http://google.com", null), new HttpResponse(null));
  2. var contextBase = new HttpContextWrapper(context);
  3. var routeData = new System.Web.Routing.RouteData();
  4. routeData.Values.Add("controller", "ReportManager");
  5. var fakeControllerContext = new System.Web.Mvc.ControllerContext(contextBase,
  6. routeData, new EmptyController());
  7.  
  8.  
  9.  
  10. Margins pageMargin = null;
  11. string filePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("/Reports"), fileName);
  12.  
  13. var responseActionResult = new ViewAsPdf(viewName, reportData)
  14. {
  15. FileName = fileName + ".pdf",
  16. IsJavaScriptDisabled = false,
  17. // CustomSwitches = GetCustomSwitches(reportData.ClientId, viewName, ref pageMargin),
  18. PageOrientation = Rotativa.Options.Orientation.Portrait,
  19. PageSize = Rotativa.Options.Size.A4,
  20. PageMargins = pageMargin,
  21. };
  22. {
  23. };
  24.  
  25. var ReportByteArray = responseActionResult.BuildPdf(fakeControllerContext);
  26. using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
  27. {
  28. fileStream.Write(ReportByteArray, 0, ReportByteArray.Length);
  29. }
  30. result = true;
Add Comment
Please, Sign In to add comment