NReco.PdfGenerator error : AuthenticationRequiredError

NReco.PdfGenerator error : AuthenticationRequiredError

我将 "NReco.PdfGenerator.dll" 用于我的 Web 项目(Visual studio 2012,c#), 它可以从 Internet url(如 http://google.com.tw)成功导出 但是当我将 url 更改为内部 url (公司内部系统之外) 我收到了这个错误信息:

"Cannot generate PDF: Exit with code 1 due to network error: AuthenticationRequiredError(exit code: 1)"

这是我的代码:

new NReco.PdfGenerator.HtmlToPdfConverter().GeneratePdfFromFile("http://xxx.xxx.xxxx", null, AppDomain.CurrentDomain.BaseDirectory + "test.pdf");

谁能解决这个问题??? 非常感谢

当指定 URL returns HTTP 代码 401(未经授权)时,wkhtmltopdf(内部 PdfGenerator 在单独的进程中执行它)返回 AuthenticationRequiredError。

在大多数情况下,这意味着该网页只能由经过身份验证的用户访问;在大多数 Web 应用程序中,身份验证令牌是通过 cookie 或 HTTP header.

传递的

您可以使用特殊的 wkhtmltopdf 选项传递任一 cookie,例如:

var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
htmlToPdf.CustomWkHtmlArgs = " --cookie <name> <value>";

额外 HTTP 选项 header:

htmlToPdf.CustomWkHtmlArgs = " --custom-header <name> <value> ";

请注意,无法呈现需要 windows 身份验证的 URL;在这种情况下,应使用替代身份验证机制来通过 wkhmtltopdf 访问这些页面。