[英]HTML to PDF using ironPDF getting error "access to the path 'IronPdf.ChromeRenderingEngine.dll' is denied." in C#
我們正在使用 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();
我有同樣的問題。 我設法通過將臨時文件夾路徑設置為代碼可以到達和寫入的位置來解決它(我相信它在執行生成時將庫解壓縮到它)。 當您使用 Azure 或 AWS 等應用程序服務時,這一點尤其重要。
對於 ASP.NET 應用程序,我將其放在global.ascx.cs
中的Application_Start()
中:
IronPdf.Installation.TempFolderPath = Server.MapPath(@"/tmp");
對於 .NET Core,我把它放在Startup
構造函數中。
IronPdf.Installation.TempFolderPath = @"/tmp";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.