Using the Rotativa.aspnetcore package in Ubuntu doesn't know what's wrong?
- I use the Visual Studio 2017 MVC Default Template.
- Using nuget Rotativa.aspnetcore (https://www.nuget.org/packages/Rotativa.AspNetCore/)
Install-Package Rotativa.AspNetCore -Version 1.1.1
Perform sudo apt-get install Xvfb libfontconfig wkhtmltopdf in Linux Ubuntu OS. wkhtmltopdf and wkhtmltoimage copy it to Web MVC project wwwroot/Rotativa.
According to Rotativa.aspnetcore Git (https://github.com/webgio/Rotativa.AspNetCore) file Needs configuration settings configuration done in Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { ... app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Faceapirequestrecords}/{action=Index}/{id?}"); }); RotativaConfiguration.Setup(env, "/usr/bin"); }
HomeController program code :
public class HomeController : Controller { public IActionResult Index() { return View(); } public IActionResult DemoViewAsPDF() { return new ViewAsPdf("Index"); } }
Deploy and execute MVC applications. URL : http://localhost:5000/Home/DemoViewAsPDF
Error Message:
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect.
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.Exception: QXcbConnection: Could not connect to display
at Rotativa.AspNetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe) at Rotativa.AspNetCore.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html) at Rotativa.AspNetCore.ViewAsPdf.CallTheDriver(ActionContext context) at Rotativa.AspNetCore.AsResultBase.BuildFile(ActionContext context) at Rotativa.AspNetCore.AsResultBase.ExecuteResultAsync(ActionContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsyncTFilter,TFilterAsync at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)