Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ayushagarwal181 opened this issue Jul 29, 2022 · 0 comments

Comments

@ayushagarwal181
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant