[英]Can not find compilation library location for package 'NReco.PdfGenerator'
我正在尝试使用NRecosite HTML到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);
}
看来您缺少指向Webkit PDF生成器exe的链接。
// Let's add the recovery demand to the right folder
var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
htmlToPdf.License.SetLicenseKey("genertor","Your license key");
htmlToPdf.PdfToolPath = _env.ContentRootPath + "\\lib\\PdfGenerator";;
htmlToPdf.TempFilesPath = _env.ContentRootPath + "\\lib\\PdfGenerator";;
htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4;
htmlToPdf.Orientation = NReco.PdfGenerator.PageOrientation.Portrait;
htmlToPdf.LowQuality = false;
因此,您需要设置许可证密钥(可能取决于版本以及是否需要许可)-此处的代码适用于ASP.NET Core。 并且您具有Core 2.0的标签。
但是该工具需要在项目中某处为wkhtmltopdf.exe
定义一个路径。
您需要从这里获得一份副本: https : //wkhtmltopdf.org/
我已将我的文件放在\\lib\\PdfGenerator
下的项目根目录中,但将其放置在适合您项目的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.