Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 412
Chandresh Khambhayata Avatar asked Mar 03 '23 01:03

Chandresh Khambhayata


1 Answers

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";
like image 134
mjbates7 Avatar answered Mar 04 '23 13:03

mjbates7