[英]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.