Html to PDF Conversion using Blink engine in ASP.NET Core application running in Azure App Service

Hi - I am using the HTML to PDF conversion in an ASP.NET Core 3.1 application - it works perfectly in both the local development environment and when hosted on a standard Windows IIS server - however when I deploy to an Azure App Service I get the following exception at the point of conversion:

Syncfusion.Pdf.PdfException: Failed to convert webpage
 ---> Syncfusion.Pdf.PdfException: Failed to convert webpage
   at Syncfusion.HtmlConverter.BlinkConverter.BlinkResult(Stream outputStream)
   at Syncfusion.HtmlConverter.BlinkConverter.ConvertToPdf(String url, PdfDocument& document)
   --- End of inner exception stack trace ---
   at Syncfusion.HtmlConverter.BlinkConverter.Convert(String url)
   at Syncfusion.HtmlConverter.BlinkConverter.Convert(String htmlString, String baseurl)
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String html, String baseurl)
...

I have verified that the path is correct and all binaries are copied correctly (using the app service editor). I know it is locating the BlinkBinaries folder correctly because the error message is different if they are missing.  I have also added the OpenSSL libraries just in case that was the problem - but it makes no difference. 

I have worked through all the similar issues raised and their responses on this website, and the published tutorials on it - but none of it is getting me anywhere. Is there any way to - for example - get more detailed error information to tell us why it failed to convert the page? 

The relevant lines of code are...

using Syncfusion.Drawing;
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;

        private readonly string _root;

        public TestService(IHostEnvironment env)
        {
            _root = env.ContentRootPath;
        }

...

        protected override async Task DoWork()
        {
              ...
            //Initialize the HTML to PDF converter 
            var settings = new BlinkConverterSettings { BlinkPath = $"{_root}\\BlinkBinaries", PdfPageSize = PdfPageSize.A4, MediaType = MediaType.Print  };
            var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink) {ConverterSettings = settings };
            ...
            //Code to generate the HTML as a string (verified working)
            ...

          //Try the conversion. The wwwroot folder contains fonts and images that are referenced in the html         
           using var pdfDoc = htmlConverter.Convert(reportPage.Html, $"{_root}\\wwwroot");
          ...
        }

Any help you can give would be appreciated.




11 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team February 9, 2021 12:36 PM UTC

Hi Charles, 
 
Thank you for contacting Syncfusion support. 
 
Due to the GDI limitations and restriction of Azure App service environment, the Blink rendering engine does not support conversion in Azure app service (Azure websites) and Azure function. Azure app service environment does not have elevated permissions and enough rights to launch the browser for converting HTML to PDF. However, we can use Blink rendering engine in Azure cloud service, it has elevated permissions and enough rights to launch the browser. 

Please refer the below KB link for HTML to PDF conversion in Azure cloud service using Blink,   
 
We can also use Azure App service with docker for deploying the HTML to PDF conversion with Blink rendering engine. Please refer below link for more information,  
 
We have already raised a query about this error in the chromium forum. Once we got or find any solution to perform Html to PDF in the Azure environment, we will let you know the details in this forum. Please find the forum link.      
   
Please let us know if you need any further assistance with this.    
 
Regards, 
Gowthamraj K 



CH Charles February 9, 2021 11:15 PM UTC

Thanks for the response: that's a bit of a problem for us. Is it any different with the other rendering engines or do none of them work in App Services?


GK Gowthamraj Kumar Syncfusion Team February 10, 2021 12:17 PM UTC

Hi Charles, 

As we said earlier, due to the GDI limitations and restriction of Azure App service environment, the Blink rendering engine does not support conversion in Azure app service (Azure websites) and Azure function. HTML to PDF conversion with WebKit rendering engine will work in Azure app service. We internally make use of the QtWebKit rendering engine for converting HTML to PDF. QtWebKit rendering engine preserves the output PDF document like how the input HTML file/URL is displayed on the WebKit based web browsers (safari). The same behavior as replicates in our converter. We are suggested your to try our WebKit rendering engine for converting HTML to PDF In Azure app service. 

While hosting the application in Azure, the converter may throws an exception under Consumption/Free/Shared hosting plans on Azure. Due to the access restrictions and limitation of these hosting plan, it prevents the loading of the browser process. So, the conversion will be failed in the Consumption/Free/Shared hosting plans on Azure environment. Other hosting plans does not have the restriction for loading the browser process. Please try the conversion with Basic (B1) or above hosting plans in your end and let us know the result. 

Please follow the steps from below KB link for converting HTML to PDF in Azure app service.  
 
Kindly refer the below links for prerequisites of WebKit HTML converter,  

Please try the above suggestions in your end and let us know if you need any further assistance on this.  

Regards, 
Gowthamraj K 



CH Charles June 7, 2021 11:19 AM UTC

Hi,

I had this on hold for a while but I've come back to it. I'm now trying to get it to work in a Linux Docker container. I can get the ASP.NET application running in Linux/Docker without any difficulties, and have followed your documentation as closely as possible (albeit with an API controller rather than a Razor Page) - but all I get at the point of conversion is "Failed to convert webpage". Full details of the error are below. I have attached a copy of the test application. Details of the hosting environment are shown below the error:

======= Error Details ========

Syncfusion.Pdf.PdfException
  HResult=0x80131500
  Message=Failed to convert webpage
  Source=Syncfusion.HtmlConverter.Portable
  StackTrace:
   at Syncfusion.HtmlConverter.BlinkConverter.Convert(String url)
   at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String url)
   at pdfconverter.Controllers.PdfConvertController.Get() in E:\PDFConverter\pdfconverter\Controllers\PdfConvertController.cs:line 42
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()

  This exception was originally thrown at this call stack:
    Syncfusion.HtmlConverter.BlinkConverter.BlinkResult(System.IO.Stream)
    Syncfusion.HtmlConverter.BlinkConverter.ConvertToPdf(string, ref Syncfusion.Pdf.PdfDocument)

Inner Exception 1:
PdfException: Failed to convert webpage

========== Hosting Environment Details ============

Welcome to .NET

Environment

.NET 5.0.6 (X64)

Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020

Metrics
Containerizedtrue
CPU cores8
cgroup memory usage233218048
Memory, current usage (bytes)126418944
Memory, max available (bytes)9223372036854771712
Host name3b8bce5ef2ff
Server IP address172.17.0.2


Attachment: PDFConverter_307035a8.zip


PV Prakash Viswanathan Syncfusion Team June 8, 2021 05:34 PM UTC

Hi Charles, 

We have checked the reported issue with provided details and sample, the failed to convert web page occurs while running the sample in our side. The exception occurs due to missing of dependencies in Linux docker. We have installed the dependencies using docker and checked the conversion with the provided sample, it is working fine in our side. Please find the modified docker file from below link, 

Please refer below links for converting HTML to PDF with Linux docker, 

Please try the above solution and let us know the result.  

Regards, 
Prakash V 



CH Charles replied to Prakash Viswanathan June 24, 2021 01:29 AM UTC

Hi Prakash,


I've been trying to get this to work for some time now. It works in the development environment, but when I publish to Azure I get the  "blink files are missing" error - even though I have configured them to be copied to the output directory. The same happens with the "fully complete" example provided in your documentation. 


Qt Binaries are no good because their standards support is horribly out of date, IE is worse. There has to be an easier way to do this: have you tried it using Azure .net worker service? The "cloud service" option doesn't seem to exist any more.


Rgds,


Ch




GK Gowthamraj Kumar Syncfusion Team June 24, 2021 01:29 PM UTC

Hi Charles, 
 
Thank you for your update. 
 
As mentioned earlier, due to the GDI limitations and restriction of Azure App service environment, the Blink rendering engine does not support conversion in Azure app service (Azure websites) and Azure function. 
 
Earlier, we did not checked the compatibility of HTML to PDF conversion with Azure worker service, we will check the conversion in Azure worker service  and update you further details by June 28, 2021 
 
Regards, 
Gowthamraj K 



CH Charles replied to Gowthamraj Kumar June 24, 2021 04:06 PM UTC

Hi,

I understand that it cannot be used directly in an Azure App Service, but the proposed solution to use Linux Docker is also not working for me. Please find attached a sample I prepared to illustrate this: again I have removed the Blink Binaries from the folder for reasons of space in the upload so you will need to replace them.

This application - based on the Syncfusion documentation - works perfectly in the development environment with Docker Desktop. On startup it lists on the home page all the files in the directory in which it's running, so you can see that the BlinkBinariesLinux files are included. Then you can click the convert button at the bottom and it renders a conversion of the Google home page.

When you deploy it to an Azure Linux Docker Container Instance (as per the instructions here: https://www.syncfusion.com/kb/11299/how-to-convert-html-to-pdf-using-blink-in-linux-docker) it runs OK, but when you click the 'Convert' button it shows the error:

{

  "message": "Blink files are missing at /app/BlinkBinariesLinux",

  "stackTrace": " at Syncfusion.HtmlConverter.BlinkConverter.Convert(String url)\n at Syncfusion.HtmlConverter.HtmlToPdfConverter.Convert(String url)\n at PDFConverter.Controllers.HomeController.ExportToPDF() in /src/PDFConverter/Controllers/HomeController.cs:line 77"

}.

Are you saying that the "Blink in Linux Docker" solution no longer works either? If it works, please can you demonstrate how?


Thank you,


Charles


Attachment: PDFConverter_4ba7318b.zip


GK Gowthamraj Kumar Syncfusion Team June 25, 2021 02:10 PM UTC

Hi Charles, 
 
Thank you for your update. 
 
We have checked the given samples and you have included the BlinkBinariesWindows files to BlinkBinariesLinux folder. So, while running the sample in Linux docker, it throws BlinkBinaries missing exception. So, kindly try the conversion with proper BlinkBinariesLinux folder and files. Please refer below screenshot for more information, 
 
 
You can get the BlinkBinariesLinux folder by installing Syncfusion.HtmlToPdfConverter.Blink.Net.Core.Linux package. Please refer steps 2, 3 and 4 for more information in below KB link. 
Note: Please make sure you are using Linux based images as base image in the docker file.  
 
Also, your sample using .NET 5.0 and using .NET 5.0 base image for the docker. Currently we are checking the conversion in .NET 5.0 sample and update you the details by June 29, 2021.  
 
Regards, 
Gowthamraj K 


Marked as answer

CH Charles June 26, 2021 10:18 AM UTC

Hi - many thanks: that was the problem with this one - although I cannot understand how because I repeatedly started again from scratch and took the files from the Linux version. 

However one of the problems that made debugging this so difficult is that when deploying Linux docker images to Azure it often runs the previous version (or an earlier version) - not the one you just deployed. That might be worth highlighting in your documentation - in the end I had to completely delete and re-provision the app service every time to ensure it was running the right version.

BTW for reference (based on my researches):

  • The Linux / docker solution works fine with .NET 5.0, and for now seems to be the best option.
  • Using Azure "Web Jobs" in the App Service is not an option to resolve the original problem because they are subject to the same limitations on GDI etc. as a normal App Service deployment.
  • Using "Cloud Services (extended support)" does work - but it's more complex to set up and you have to use an older-style .NET Framework application (.NET Core does not seem to be supported).
  • Using the Qt or IE rendering engines is a non-starter for any HTML produced in the last five years - they're just too far out of date in terms of their support for modern HTML/CSS (e.g. no Grid support).


GK Gowthamraj Kumar Syncfusion Team June 28, 2021 12:38 PM UTC

Hi Charles, 
 
Thank you for your update. We are glad to know that your problem has been solved. 

Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon