1

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.

Nirman
  • 6,715
  • 19
  • 72
  • 139

1 Answers1

3

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

[...]

PDF Generation from HTML

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.

Ken W - Zero Networks
  • 3,533
  • 1
  • 13
  • 18
  • Thanks for clarifying why it is not supported. Hope this gets worked out with some other library. Until then we will need to turn off this feature in our application. Thanks once again. – Nirman Feb 14 '19 at 06:04
  • wondering if you can provide the tentative timeline by when this will be enabled in Basic+? Currently our Azure migration is nearly blocked due to this, and we are planning to convert this to SSRS reporting which is going to take some huge efforts considering our codebase. Information from your side at this this stage would help us in taking correct decision. – Nirman Feb 18 '19 at 13:46
  • Apologies but I can't comment on roadmap dates on a public forum. My suggestion is to reach out to your Microsoft Account team as they may be able to give you a roadmap under NDA. – Ken W - Zero Networks Feb 19 '19 at 01:51
  • Also this may be of use to you. https://msdn.microsoft.com/en-us/magazine/mt707529.aspx?f=255&MSPPError=-2147217396 – Ken W - Zero Networks Feb 19 '19 at 01:53