c# html 到 Pdf 转换器(Nreco)

c# html to Pdf Converter(Nreco)

我正在为我的项目使用 NReco html 到 pdf 转换器。 它在服务器机器上给了我 3 天的错误,它工作了几个月没有任何 problem.Worse 事情是,该项目在我的本地电脑上运行良好 codes.I 猜测,问题与已经在服务器 pc.I 上创建的一些文件夹授权或临时文件也删除了 /user 和 windows/temp 文件夹下的临时文件,但仍然出现错误:

简单的错误信息是:"The file exists"

代码:

   public static byte[] ToPDF(this HttpContext context, string htmlContent )
    {
        string logFile = context.Request.PhysicalApplicationPath + "\" +  "log.txt";
        try
        {
            var converter = new HtmlToPdfConverter();
            converter.Margins = new PageMargins { Bottom = 20, Top = 18 };
            var pdfBytes = converter.GeneratePdf(htmlContent); //THROW EXCEPTION ON THIS LINE
            errorMsg = "Error Code:00x1";
            return null;

        }
        catch (Exception exp)
        {
            errorMsg = "Error Code:00x2";
            CreateErrorLog(context ,exp);
            return null;
        }

    }

我已通过将 NReco.PdfGenerator.dll 版本更新为 1.1.11.0 来修复它,使用的是 out-of 日期版本(3 年前发布)并且错误消失了。

注意:当我使用 Nuget 包管理器卸载和安装 Nreco 时,它安装的是相同的旧版本,我不知道为什么所以我不得不从 :

https://pdfgenerator.codeplex.com/

并从项目的引用中手动删除旧的 .dll 并添加新的 NReco.PdfGenerator.dll