Rotativa BuildPdf works on local machine but not on production server
I am using Rotativa to generate a pdf from a view I created. Locally this works fine, the PDF is stored on my local machine, and the email function then attaches and sends the file. But when I release it on our server, it basically breaks down into this part:
var binary = pdf.BuildPdf(this.ControllerContext);
The website takes a while to load and then finally just says
An error occurred while processing your request.
What I did to test this was redirecting to the actual view to be generated in pdf until this error is shown. I thought the problem was that the website doesn't have any write permissions, but can create directories in the required folder up to the above part.
What can I do to fix this problem?
Here is my complete section of code for this part:
string Switches = string.Format("--print-media-type --header-html {0} --footer-html {1}", Url.Action("Header", "Home", new { area = "" }, "http"), Url.Action("Footer", "Home", new { area = "" }, "http"));
var fileName = ReportName+objScor.Name+"_"+objScor.Surname + DateTime.Now.ToString("dd MMM yyyy HHmmss") + ".pdf";
var filePath =(@"C:\\PDFReport\\" + fileName);
if (!System.IO.File.Exists(@"C:\\PDFReport\\"))
{
Directory.CreateDirectory(@"C:\\PDFReport\\");
}
var pdf = new Rotativa.ViewAsPdf("Report", report)
{
FileName = fileName,
CustomSwitches = Switches
};
var binary = pdf.BuildPdf(this.ControllerContext);
Thanks in advance.
source to share
No one has answered this question yet
Check out similar questions: