简体   繁体   中英

HTML to PDF using ironPDF getting error "access to the path 'IronPdf.ChromeRenderingEngine.dll' is denied." in C#

We are using ironPDF to convert our document into PDF, it was working fine and was converting our documents (HTML) to PDF seamlessly in localhost, and after confirming everything we have bought a license of 1 year and uploaded the code to Production.

As soon as we have uploaded our code in Production, we are getting an error: access to the path 'IronPdf.ChromeRenderingEngine.dll' is denied.

Here is the code that we are using

   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();

I had the same problem as this. I managed to solve it by setting the temp folder path to a location that the code could reach and write to (I believe it unpacks the libraries to it when it performs the generation). This is especially relevant when you're using an application service such as Azure or AWS.

For ASP.NET applications I put this in Application_Start() in global.ascx.cs :

IronPdf.Installation.TempFolderPath = Server.MapPath(@"/tmp");

For .NET Core I put this in Startup constructor.

IronPdf.Installation.TempFolderPath = @"/tmp";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM