I want to create a pdf file using Rotativa framework from ApiController. In my project there is no any view. Content of pdf (HTML) is in the database.
Is it any way to generate pdf without View and ControllerContext ? Controller context is accessible only in Controller not in APIController...
I found this https://github.com/JustMaier/Rotativa/tree/ed7678eefdffb3995f5b6a3e9afb18903c648df8 but it needs View
Problem is in method BuildFile()...
Start from here
var a = new Rotativa.ViewAsPdf(pdfResult);
a.FileName = request.ResultFileName;
byte[] f = a.BuildFile();
ControlerContext can be null here
public byte[] BuildFile(ControllerContext context = null)
{
if (this.WkhtmlPath == string.Empty)
this.WkhtmlPath = context == null ? HttpContext.Current.Server.MapPath("~/Rotativa") : context.HttpContext.Server.MapPath("~/Rotativa");
var fileContent = this.CallTheDriver(context);
if (string.IsNullOrEmpty(this.SaveOnServerPath) == false)
{
File.WriteAllBytes(this.SaveOnServerPath, fileContent);
}
return fileContent;
}
...but here can't
protected override byte[] CallTheDriver(ControllerContext context)
{
// use action name if the view name was not provided
string viewName = ViewName;
if (string.IsNullOrEmpty(viewName))
viewName = context.RouteData.GetRequiredString("action");
ViewEngineResult viewResult = GetView(context, viewName, MasterName);
string html = context.GetHtmlFromView(viewResult, viewName, Model);
byte[] fileContent = WkhtmltopdfDriver.ConvertHtml(this.WkhtmlPath, this.GetConvertOptions(), html);
return fileContent;
}
What am i doing wrong ?