We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Syncfusion.Pdf.PdfException: Failed to convert webpage

Hi

I can't seem to find current info on the Syncfusion forum for doing "HTML to PDF". It appears outdated with links to old packages, etc.

I have a .NET 7 Blazor app that converts my HTML page to PDF (with an error on the footer of the PDF) but that's a problem for later. The real issue is when publishing to Azure, there is complete failure of the page and it needs to be reloaded. Error is:


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 ---


What is different about local vs Azure App Service?

Thanks

Mike



6 Replies

PV Prakash Viswanathan Syncfusion Team February 14, 2023 03:33 PM UTC

HTML to PDF converter with Blink rendering engine supports conversion in azure app service Linux and Azure functions Linux. The converter does not work in Azure App Service for windows due to the GDI and sandbox limitation. Please refer below links for converting HTML to PDF in Azure with Linux and docker.

We suggest you to try the Azure App Service Linux or with Azure app service with Linux docker.

https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/azure

Azure App Service Linux: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/azure#azure-app-service-linux

Azure app Service with Linux docker: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/azure#azure-app-service-linux-with-docker



MI Mike February 15, 2023 09:57 AM UTC

Hi Prakash

This is really sad to hear. My project must run on Windows hosted App Service so that means Syncfusion does not have a solution for me.

Thanks

Mike



SN Santhiya Narayanan Syncfusion Team February 16, 2023 04:45 PM UTC

As we said earlier, the Blink rendering engine does not support conversion in Azure App Service windows. So we are suggesting that you use the WebKit rendering engine to perform the conversion in Azure app service windows. We created the sample in a.NET 6.0 solution using an Azure Function and attached it for your convenience. 


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/FunctionApp1-1490144865

Please refer the  below  kB documentation page

https://www.syncfusion.com/kb/9779/how-to-convert-html-to-pdf-in-azure-using-net-core

Please ensure all the files and inner folder are properly copied in Azure server using console in Azure portal. If it is not copied, kindly add all the files manually to resolve that issue. This is not an issue in our library.  Please follow the below steps to copy the files properly to resolve the reported issue.  

  1. Open the Azure portal in browser.
  2. Navigate to the deployed Azure function in Azure portal.
  3. Open the console of Azure function.

              

  

  1. As we said earlier, QtBinaries assemblies are not copied properly while publish to Azure functions.
  2. So, we need to manually copy all the assemblies from azure portal.
  3. QtBinariesWindows from location “c:\home\site\wwwroot\QtBinariesWindows” does not have all the assemblies, so we need to copy all the assemblies and inner folder from bin folder.
  1. Using cd command, navigate to the location “c:\home\site\wwwroot\bin\QtBinariesWindows” and run the below command.

cp *.* c:\home\site\wwwroot\QtBinariesWindows\ 


  


  1. Then we need to copy the files from “platform” and “imageformats” folders using the same approach.
  1. Using cd command, navigate to the location “c:\home\site\wwwroot\bin\QtBinariesWindows\platforms” and run the below command.

cp *.* c:\home\site\wwwroot\QtBinariesWindows\platforms 


  1. Using cd command, navigate to the location “c:\home\site\wwwroot\bin\QtBinariesWindows\imageformats” and run the below command.

cp *.* c:\home\site\wwwroot\QtBinariesWindows\imageformats 


  1. Ensure the all the files are copied to “c:\home\site\wwwroot\QtBinariesWindows” location using dir command. Also, ensure the inner folders (imageformats, platforms) has all the files.

            

  1. Now try the conversion from Azure function URL.
  2. We need to copy this assemblies for the first time only.


Please refer the below KB steps for more information,
Openssl : https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#openssl



MI Mike February 18, 2023 08:23 AM UTC

Hi Santhiya


Thanks for that detailed reply. I have managed to get an endpoint for the Function to work.


How worried should I be that Syncfusion says "WebKit" is the old library and Blink Engine the new/better one?


Thanks

Mike




MI Mike February 18, 2023 08:53 AM UTC

...also, the Azure Function example does not show where to add the syncfusion license key.

Where in the Azure Function will this go?

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("<key>")



SN Santhiya Narayanan Syncfusion Team February 20, 2023 08:59 AM UTC

Azure function:

Register the license key in the first line of Azure function class

[FunctionName("Function1")]

public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext executionContext)

{

    Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");

     string blinkBinariesPath = string.Empty;

     try

     {

     blinkBinariesPath = SetupBlinkBinaries(executionContext);

     }

     catch

     {

         throw new Exception("BlinkBinaries initialization failed");

     }

 

     string url = req.Query["url"];

 

     //Initialize the HTML to PDF converter with the Blink rendering engine.

     HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);

     BlinkConverterSettings settings = new BlinkConverterSettings();

 

     //Set command line arguments to run without sandbox.

     settings.CommandLineArguments.Add("--no-sandbox");

     settings.CommandLineArguments.Add("--disable-setuid-sandbox");

 

     settings.BlinkPath = blinkBinariesPath;

 

     //Assign WebKit settings to the HTML converter

     htmlConverter.ConverterSettings = settings;

 

     //Convert URL to PDF

     PdfDocument document = htmlConverter.Convert(url);

 

     MemoryStream ms = new MemoryStream();

    

     //Save and close the PDF document 

     document.Save(ms);

     document.Close();

 

     ms.Position = 0;

 

     return new FileStreamResult(ms, "application/pdf");

}


OR

could you please register the licence key where you create the PdfDocument object instance? You can register the licensing before using Syncfusion PDF library. Please try this and let us know the result.


Loader.
Live Chat Icon For mobile
Up arrow icon