【发布时间】:2018-01-29 06:29:38
【问题描述】:
我正在尝试使用 NRecosite HTML to PDF 生成器。
无论何时
new NReco.PdfGenerator.HtmlToPdfConverter()
抛出异常
FileNotFoundException: 无法加载文件或程序集 'System.Web, 版本=2.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a'。 系统找不到指定的文件。
[HttpPost]
public async Task<IActionResult> Login(RegistrationModel model, CommandType command)
{
int selectedTab = 9;
if (command == CommandType.SignApplication)
{
selectedTab = 10;
string htmlContent = await GetHtml(model.Review.PublishUrl);
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);
return File(pdfBytes, "application/pdf", "dd.pdf");
}
RegistrationManager mgr = new RegistrationManager(_registrationRepository);
var registrationModel = await mgr.CreateLoginModel(model.FormId, model.LeadId, selectedTab);
return registrationModel.IsRegistrationDisbaled ? View("Error", "The link is disabled for this account") : View("Index", registrationModel);
}
【问题讨论】:
-
我猜你使用'NReco.PdfGenerator' nuget 包,它嵌入了windows wkhtmltopdf 二进制文件并且只能与.NET Framework 一起使用。对于 .NET Core 应用程序,应使用“NReco.PdfGenerator.LT”nuget;它不嵌入 wkhtmltopdf 二进制文件,您需要自己为您的目标平台部署/安装它。 LT 版本不适用于免费用户(需要许可证密钥)。
标签: c# asp.net-core-2.0 nreco