I am trying to use Rotativa to Generate a PDF and return the bytes, however I am getting the error:
Value cannot be null. Parameter name: context
Here is my code:
public string getReportsPDF(string community, string procedure)
{
SiteSuperReportsController controller = new SiteSuperReportsController();
string value = "";
byte[] pdfBytes = new byte[] { };
if (procedure == "GetProductionTasks")
{
var actionPDF = new Rotativa.ActionAsPdf("RedBluePDF", new { community = community, procedure = procedure })
{
PageSize = Size.A4,
PageOrientation = Rotativa.Options.Orientation.Landscape,
PageMargins = { Left = 1, Right = 1 }
};
try
{
pdfBytes = actionPDF.BuildFile(controller.ControllerContext);
value = "Works";
}
catch(Exception e)
{
value = e.Message.ToString();
}
}
return value;
}
The value returned is Value cannot be null. Parameter name: context
What am I doing wrong?