1

我正在尝试使用 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);
}
4

1 回答 1

0

您似乎缺少指向 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但将您放在适合您项目的位置。

于 2018-01-29T11:54:24.297 回答