webgio / Rotativa

Rotativa, /rota'tiva/. Make Pdf from Asp.Net MVC. Available on Nuget https://www.nuget.org/packages/Rotativa
http://letsfollowtheyellowbrickroad.blogspot.it/search/label/Rotativa
MIT License
621 stars 224 forks source link

Rotativa Error: Exit with code 1 due to network error: HostNotFoundError #231

Open ayushagarwal181 opened 2 years ago

ayushagarwal181 commented 2 years ago

StackOverflow Link - https://stackoverflow.com/questions/73107390/rotativa-error-exit-with-code-1-due-to-network-error-hostnotfounderror

I am using Rotativa v1.7.3 with Asp.Net MVC.

I am getting the below error when i try to use views for header and footer page.

Qt: Could not initialize OLE (error 80070005) Error: Failed loading page https://mywebsite.com/SomeArea/SomeController/ReportHeader (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1 due to network error: HostNotFoundError | ExceptionSource - Rotativa | ExceptionStackTrace: at Rotativa.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html, String wkhtmlExe) at Rotativa.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html) at Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) at Rotativa.AsResultBase.BuildFile(ControllerContext context) at SomeProject.Areas.SomeArea.Controllers.SomeController.d__30.MoveNext() in E:\MyApplication\SomeProject\Areas\SomeArea\Controllers\SomeController.cs:line 1623

On local its working fine and the PDF is getting generated successfully, but is Server its not working.

Code Used

// Working
customSwitches = "--dpi 150 " +
              "--footer-left \"" + Session["Name"] + " printed report on: " + centralTimeZone.ToString("dddd, dd MMMM yyyy hh:mm tt") + "\" " +
              "--footer-right \"Page: [page] of [toPage]\" " +
              "--footer-line " +
              "--footer-font-size \"9\" " +
              "--footer-spacing 5 " +
              "--footer-font-name \"calibri light\"";

// Not Working
 customSwitches = string.Format("--allow {0} " +
                            "--header-html {0}",
                            Url.Action("ReportHeader", "Some", new { area = "SomeArea" }, Request.Url.Scheme));

var pdfResult = new Rotativa.ViewAsPdf("../Survey/FinalReport")
{
    FileName = pdfname,
    Model = reportModel,
    Cookies = cookieCollection,
    CustomSwitches = customSwitches,
    FormsAuthenticationCookieName = FormsAuthentication.FormsCookieName, // Removing this and adding anonymous authentication in header/footer action also does not work.
};

public ActionResult ReportHeader()
{
    ViewBag.LogoPath = Session["HeaderFileEntryString"] as string;
    return View("~/Areas/SomeArea/Views/Some/ReportHeader.cshtml");
}

Report Header View

@{ Layout = null; }
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Header</title>
</head>
<body>
    <img src="@ViewBag.LogoPath" height="185" width="1420"/>
</body>
</html>

When running without view for header/footer, pdf is getting generated successfully, but when using view for header/footer, pdf is not getting generated.

On using "--load-error-handling ignore", the PDF gets generated, but the header/footer are not coming.