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

HTML To PDF conversion using Blink - Failed to convert webpage error on docker linux

Hi Team,


I am using HtmlToPdfConverter with Blink to convert an html string content to pdf in our application.

Ours is .net 6, Blazor application.

Everything works fine on local Windows machine. But on server its deployed in Docker Linux container.

So, I have added both Windows and Linux NuGet packages on to the application:

syncfusion.htmltopdfconverter.net.linux - 20.3.0.58

syncfusion.htmltopdfconverter.net.windows - 20.3.0.58


I also followed the below url to make it work on Docker Linux platform

https://www.syncfusion.com/kb/11299/how-to-convert-html-to-pdf-using-blink-in-linux-docker


Still, I am getting the "Failed to convert webpage" error

I am trying to troubleshoot using the below link

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


I have few queries on this.

  1. Is there an alternative for Newtonsoft.Json assembly binding redirection on .net 6? as this is mentioned as one of the possibilities.
  2. Which Newtonsoft.Json version does it actually support without throwing error?
  3. If I set the TempPath, will the BlinkPath be updated to this new path? or should I set the BlinkPath manually? or can the BlinkPath be left as is?
  4. Instead of installing the additional assemblies mentioned for Docker Linux usage, every time the docker image is created, can these assemblies be copied to any particular location so that this can be used by blink assemblies?
  5. Can we somehow get more specific error message on these scenarios.
  6. Are there any other reference materials or samples that can be of use in this scenario?

5 Replies

SN Santhiya Narayanan Syncfusion Team January 6, 2023 04:51 PM UTC

We have checked the reported issue with provided details on our end but it is working properly. We have attached the sample for your reference and try the sample on your end and let us know the result


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/HTMLBlzorApplication803260995


Please make sure to add the below command line argument in our converter

//Set command line arguments to run without sandbox.

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

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


1.Is there an alternative for Newtonsoft.Json assembly binding redirection on .net 6? as this is mentioned as one of the possibilities.

The reported issue does not occur due to NewtonSoft. Json assembly

2.Which Newtonsoft.Json version does it actually support without throwing error?

 

You should use NewtonSoft. JSON 13.0.1 or 13.0.2 version It does not throw errors.

3.If I set the TempPath, will the BlinkPath be updated to this new path? or should I set the BlinkPath manually? or can the BlinkPath be left as is?

 

TempPath and BlinkPath are both different.

The BlinkBinaries folder will be copied from the NuGet package to your application's bin folder. So there is no need to manually set BlinkPath.

If we set the TempPath, then the conversion will use that path to generate the temporary files. During the HTML to PDF conversion process, internally, the converter will create a temporary process file, a PDF file, and a text file in a temporary folder. These files will be deleted once the conversion process is complete.

4.Instead of installing the additional assemblies mentioned for Docker Linux usage, every time the docker image is created, can these assemblies be copied to any particular location so that this can be used by blink assemblies?

 

Yes. You can copy the assemblies to any particular location, but you will get some problems while upgrading the nuget package.

As of now, we are installing the assemblies. So we have suggested that it is better to install it every time.

 

5.Can we somehow get more specific error message on these scenarios.

 

The "Failed to convert webpage" error will occur when a document is not generated properly in Chrome. Other types of exceptions are handled properly.

This exception could happen for the following reasons:
1.The NewtonSoft.Json package is missing or mismatched in the project.
2. If the temporary folder does not have elevated permission for the respective user, then the Blink HTML converter may throw this exception.
3. Sometimes this exception occurs for only one particular URL.

All of the above We can't identify the cause, but we can identify the failure when conversion fails. We didn't get a proper exception at chrome level.

Please refer below documentation page

 

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

6.Are there any other reference materials or samples that can be of use in this scenario?

 

You can download the sample from below link

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

 

https://github.com/SyncfusionExamples/html-to-pdf-csharp-examples/tree/master/Docker

 

https://www.syncfusion.com/kb/8749/how-to-convert-html-to-pdf-in-linux-docker-container

 

 



DT Dinesh Thamby Ambookkan January 18, 2023 07:28 PM UTC

Hi, 


The 3 main causes that you mentioned above:

  1. Newtonsoft.JSON package missing or mismatch - 
    • I am using 13.0.2 in our application. Which you said should be fine.
  2. Temporary folder does not have elevated permission. - 
    • I gave full permission on the temporary folder and tried creating and deleting file in this temporary folder location from within the application to test it. This was happening without any issue. So that rules out this possibility.
  3. Sometimes this exception occurs for only one particular URL. - 
    • I am not giving direct url, instead I am giving the html content. So, I believe this also should be good.

From the troubleshooting site, I could see that the 2 files chrome and chrome-wrapper from BlinkBinariesLinux folder should have execution permissions. 
  • I tried doing that as well. As that still did NOT work, I provided full permission for everything inside BlinkBinariesLinux!
Even then HtmlToPdfConverter throws error saying, "Failed to convert webpage".

Please find the code in below screenshot:




I am not sure what else I am missing. 

I have done everything mentioned in the troubleshooting website except the below one:

So, I am still asking if this can create any issue? If yes, how to do this in .net 6 core? 
If this is not the issue, please help me on what else can be an issue?

It will be great if we can set up a call to figure out this issue. Any working day 10 AM EST should be a good time for me. Let me know your thoughts.

Thanks,
Dinesh T A


SN Santhiya Narayanan Syncfusion Team January 19, 2023 02:33 PM UTC

We have checked the reported issue with given details but its working properly on our end.We have attached the sample for your reference.Please try the sample on your end and let us know the result.

Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Linuxdocker1119983433

If still you have facing any issue,Can we have web meeting to directly look into the reported issue on your machine.Please let us know your availability for a web meeting, we will make every effort to have this scheduled at a date and time of your convenience.

Note: We work during IST hours.(8 am to 7.30 PM IST)



DT Dinesh Thamby Ambookkan March 1, 2023 04:25 AM UTC

HI Santhiya,


Thanks for the sample project. I tried your solution. It's all working fine in my local machine.

I had some doubts about the solution in which I added this HtmlToPdfConverter. As this solution contains so many other features implemented in it. So, I separated it into a new service that we are currently introducing.

Even now, everything works fine in local machine. But once deployed to server, I still get the same error, "Failed to convert webpage"



I tried adding code to create a dummy file and delete from the TempPath folder. It works fine. So, TempPath has enough elevated permissions.


I checked the BlinkBinariesLinux path as well in the server.