Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var context = new HttpContext(new HttpRequest(null, "http://google.com", null), new HttpResponse(null));
- var contextBase = new HttpContextWrapper(context);
- var routeData = new System.Web.Routing.RouteData();
- routeData.Values.Add("controller", "ReportManager");
- var fakeControllerContext = new System.Web.Mvc.ControllerContext(contextBase,
- routeData, new EmptyController());
- Margins pageMargin = null;
- string filePath = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("/Reports"), fileName);
- var responseActionResult = new ViewAsPdf(viewName, reportData)
- {
- FileName = fileName + ".pdf",
- IsJavaScriptDisabled = false,
- // CustomSwitches = GetCustomSwitches(reportData.ClientId, viewName, ref pageMargin),
- PageOrientation = Rotativa.Options.Orientation.Portrait,
- PageSize = Rotativa.Options.Size.A4,
- PageMargins = pageMargin,
- };
- {
- };
- var ReportByteArray = responseActionResult.BuildPdf(fakeControllerContext);
- using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
- {
- fileStream.Write(ReportByteArray, 0, ReportByteArray.Length);
- }
- result = true;
Add Comment
Please, Sign In to add comment