0
votes

Using the Rotativa.aspnetcore package in Ubuntu doesn't know what's wrong?

  1. I use the Visual Studio 2017 MVC Default Template.
  2. Using nuget Rotativa.aspnetcore (https://www.nuget.org/packages/Rotativa.AspNetCore/)

Install-Package Rotativa.AspNetCore -Version 1.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.

  2. 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");
    }
    
  3. HomeController program code :

    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    
        public IActionResult DemoViewAsPDF()
        {
            return new ViewAsPdf("Index");
        }
    }
    
  4. 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)

1

1 Answers

-2
votes

In advance: I didn't test it.

You are trying to call http://localhost:5000/Home/DemoViewAsPDF with port 5000. Rotativa tries to redirect to http***s***://localhost:5000/Home/DemoViewAsPDF. The Port for https is different. Therefore you don't get a result.

Try to use https from the start. This might solve your problem.

You can test if Rotativa works as intended by accessing the program via the command prompt:

wkhtmltopdf.exe www.samplewebsite.com  outputfolder+filename+extension