使用ironPDF 将 HTML 转换为 PDF 时出现错误“访问路径‘IronPdf.ChromeRenderingEngine.dll’被拒绝”。在 C# 中

Cha*_*ata 6 c# pdf asp.net html-to-pdf ironpdf

我们正在使用ironPDF将我们的文档转换为PDF,它运行良好,并且在本地主机中将我们的文档(HTML)无缝转换为PDF,在确认所有内容后,我们购买了1年的许可证并将代码上传到生产。

一旦我们在生产中上传代码,就会收到错误:对路径“IronPdf.ChromeRenderingEngine.dll”的访问被拒绝。

这是我们正在使用的代码

   string file = $"{Guid.NewGuid().ToString().Replace("-", "")}.pdf";
   IronPdf.License.LicenseKey = ConfigurationManager.AppSettings["IronPdf.LicenseKey"];
   IronPdf.Installation.TempFolderPath = ironPdf;
   var pdfPrintOptions = new PdfPrintOptions()
   {
       InputEncoding = Encoding.UTF8,
       PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait,
       MarginTop = 10,
       MarginBottom = 10,
       MarginLeft = 10,
       MarginRight = 10,
       Footer = new SimpleHeaderFooter()
       {
           RightText = "Page {page} of {total-pages}",
           DrawDividerLine = true,
           FontSize = 10,
           FontFamily = "Open Sans"
       },
       CssMediaType = PdfPrintOptions.PdfCssMediaType.Print
   };
   var Renderer = new HtmlToPdf(pdfPrintOptions);
   var PDF = Renderer.RenderHtmlAsPdf(htmlContent.ToString());
   PDF.SaveAs($"{sourceUrl}{file}");
   PDF.Dispose();
Run Code Online (Sandbox Code Playgroud)

mjb*_*es7 7

我有同样的问题。我设法通过将临时文件夹路径设置为代码可以到达并写入的位置来解决这个问题(我相信它在执行生成时会将库解压到其中)。当您使用 Azure 或 AWS 等应用程序服务时,这一点尤其重要。

对于 ASP.NET 应用程序,我将其Application_Start()放入global.ascx.cs

IronPdf.Installation.TempFolderPath = Server.MapPath(@"/tmp");
Run Code Online (Sandbox Code Playgroud)

对于 .NET Core,我将其放入Startup构造函数中。

IronPdf.Installation.TempFolderPath = @"/tmp";
Run Code Online (Sandbox Code Playgroud)

  • IronPdf.Installation.TempFolderPath 文档的链接 https://ironpdf.com/object-reference/api/IronPdf.Installation.html#IronPdf_Installation_TempFolderPath (3认同)