1

I want to email a PDF sales report to all the agents and this PDF need to be generated dynamically for each agent. I used ItextSharp for that but that requires too much fiddling with html code. Finally I landed on Rotativa, it works well but there are almost more then few thousands of agents and I have a separate Business Layer to do this job. How do I make Rotativa to work in business layer?

 var pdfResult = new ViewAsPdf("CreateIMDStatmentReport", _IReportManagement.GetIMDStatmentReportByIMDCode(imdCode));
 var binary = pdfResult.BuildPdf(this.ControllerContext);     
 System.Net.Mail.Attachment data = new Attachment(new MemoryStream(binary), MediaTypeNames.Application.Pdf);
  1. How to get a view in separate Business Layer?
  2. How do I deal with ControllerContext?

Note: In future this view will be stored in database and will be rendered as VirtualPath

AlanT
  • 3,627
  • 20
  • 28

2 Answers2

1

I solved it!

For the view I used the absolute paths.
And for the ControllerContext ,I passed its object as a parameter from controller.
Also I used System.Web.Mvc package

Thank you to all!

0

Sound like you need Razor rendering outside ASP.NET MVC project, take a look at this discussion on this topic (link below). You will still need to figure out if this works with Rotavia, but I would start from this.

Is it possible to use Razor View Engine outside asp.net

From the discussion, following framework is addressing you scenarion, but again I can not confirm that it will work with Rotavia, perhaps you can use another HTML-to-PDF converter component.

"The framework helps you when you want to use Razor to render reports, e-mails, source code, HTML, or whatever, outside the MVC environment"

http://www.codeproject.com/Articles/423141/Razor-2-0-template-engine-supporting-layouts

Community
  • 1
  • 1
Edgars Pivovarenoks
  • 1,526
  • 1
  • 17
  • 31