I have created an ASP.NET MVC application (.NET Framework 4.6.2), and using HiqPDF (Version - 10.17.0) to generate PDF from HTML.
Following is the code:
public static string ConvertHtmlToPdf(string pdfContentFilePath, string pdfOutputPath)
{
try
{
string fileName = pdfOutputPath + DateTime.Now.ToString("ddMMyyyyHHmmssf") + ".pdf";
string pdfContents = System.IO.File.ReadAllText(pdfContentFilePath);
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.TrimToBrowserWidth = true;
PdfDocument pdfDocumentObject = htmlToPdfConverter.ConvertHtmlToPdfDocument(pdfContents, null);
pdfDocumentObject.WriteToFile(fileName);
return fileName;
}
catch(Exception ex)
{
throw ex;
}
}
I am trying with a very basic HTML (Only one bold text, no image, no other formatting).
This code is working fine on local environment, and generates PDF successfully. However, when I deploy this project on Azure, I am getting following error:
"Navigation Timeout"
I tried various other methods of the "HtmlToPdf" class, but getting the same error.
Can anyone please suggest what could be the reason, and how to fix this issue?
Any help on this will be much appreciated.
Most HTML to PDF libraries are blocked in the Azure Web App Sandbox.
All Azure Web Apps (as well as Mobile App/Services, WebJobs and Functions) run in a secure environment called a sandbox. Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available. The sandbox mechanism aims to ensure that each app running on a machine will have a minimum guaranteed level of service; furthermore, the runtime limits enforced by the sandbox protects apps from being adversely affected by other resource-intensive apps which may be running on the same machine
[...]
There are multiple libraries used to convert HTML to PDF. Many Windows/.NET specific versions leverage IE APIs and therefore leverage User32/GDI32 extensively. These APIs are largely blocked in the sandbox (regardless of plan) and therefore these frameworks do not work in the sandbox.
There are some frameworks that do not leverage User32/GDI32 extensively (wkhtmltopdf, for example) and we are working on enabling these in Basic+ the same way we enabled SQL Reporting.