I've written a PDF generation API that uses dinktopdf to convert some templated HTML to a byte array. This all works fine on my local machine but when I deploy to my azure web application the API only works once. When I try it a second time I get the following message and a 502 error:

The specified CGI application encountered an error and the server terminated the process.

Here's a stripped down version of my code that still presents the same error:

static IPdfConverter pdfConverter = new SynchronizedConverter(new PdfTools());

public static byte[] BuildPdf(string html)
{
    return pdfConverter.Convert(new HtmlToPdfDocument()
    {
        Objects =
        {
            new ObjectSettings
            {
                HtmlContent = html
            }
        }
    });
}

I've also tried using IronPDF to do the HTML to PDF conversion and gotten the same exact issue (works perfectly on local machine but only once on Azure deployment before giving consistent 502 errors).

1 Answers

1
user3053470 On Best Solutions

Update: Problem was solved by changing the Azure App Service Plan to Basic rather than free (PDF generation requires at minimum the Basic plan apparently).