HTML to PDF conversion - Failed to convert webpage

Hello,


We want an API to convert a web page to PDF from a url. This API will be hosted on a Linux (Debian) server.

To start, we tested the conversion of the "www.google.com" page via a .NET Core console application on a Windows computer.

We then created a new project with the nuget package "Syncfusion.HtmlToPdfConverter.Blink.Net.Core.Linux" (19.3.0.43), and followed the procedure written on your website.

Despite this, we get an exception that we don't understand :

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.HtmlToPdfConverter.Convert(String url)

at HtmlToPdfConverter.Controllers.MainController.TestConvert() in C:\DEVELOPPEMENT\HTMLtoPDF\HtmlToPdfConverter\Controllers\MainController.cs:line 37

at lambda_method3(Closure , Object , Object[] )

at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.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()

--- End of stack trace from previous location ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()

--- End of stack trace from previous location ---

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)

at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

This error is not very explicit and we are running out of ideas.

Here's a snippet of the crashing code:

Sans titre.png


Do you have a solution to suggest?


Thanks in advance.


5 Replies

GK Gowthamraj Kumar Syncfusion Team October 26, 2021 11:31 AM UTC

Hi Karam, 
 
Thank you for your interest with Syncfusion products.  
  
The reported exception may occurs due to missing of prerequisties and dependent packages, kindly ensure that all the dependent packages are installed in the container. We need to have all the dependencies in the container in order to perform the conversion inside the container.   
  
 
Kindly try the conversion with below command line arguments and update us the results,  
  
public static string[] DefaultChromeArgs = new[]   
       {   
            "--disable-background-timer-throttling",   
            "--disable-breakpad",   
            "--disable-client-side-phishing-detection",   
            "--disable-cloud-import",   
            "--disable-default-apps",   
            "--disable-dev-shm-usage",   
            "--disable-extensions",   
            "--disable-gesture-typing",   
            "--disable-hang-monitor",   
            "--disable-infobars",   
            "--disable-notifications",   
            "--disable-offer-store-unmasked-wallet-cards",   
            "--disable-offer-upload-credit-cards",   
            "--disable-popup-blocking",   
            "--disable-print-preview",   
            "--disable-prompt-on-repost",   
            "--disable-setuid-sandbox",   
            "--disable-speech-api",   
            "--disable-sync",   
            "--disable-tab-for-desktop-share",   
            "--disable-translate",   
            "--disable-voice-input",   
            "--disable-wake-on-wifi",   
            "--disk-cache-size=33554432",   
            "--enable-async-dns",   
            "--enable-simple-cache-backend",   
            "--enable-tcp-fast-open",   
            "--enable-webgl",   
            "--hide-scrollbars",   
            "--ignore-gpu-blacklist",   
            "--media-cache-size=33554432",   
            "--metrics-recording-only",   
            "--mute-audio",   
            "--no-default-browser-check",   
            "--no-first-run",   
            "--no-pings",   
            "--no-sandbox",   
            "--no-zygote",   
            "--password-store=basic",   
            "--prerender-from-omnibox=disabled",   
            "--use-gl=swiftshader",   
            "--use-mock-keychain",   
            "--single-process",   
        };   
   
               HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);   
   
                BlinkConverterSettings settings = new BlinkConverterSettings();   
   
                //Set WebKit path   
                settings.BlinkPath = linuxBinariesPath;   
   
                foreach (string args in DefaultChromeArgs)   
                {   
                    settings.CommandLineArguments.Add(args);   
                }   
   
                //Assign Blink settings to HTML converter   
                htmlConverter.ConverterSettings = settings;   
  
If still you are facing the issue, kindly share us the docker file with complete code snippet and HTML URL/file to reproduce the issue in our side. It will be helpful for us to analyse and assist you further on this.   
 
Regards, 
Gowthamraj K 



KA Karam October 26, 2021 01:23 PM UTC

Hello,


Thank you for your reply.


The problem is solved with only two arguments:

--no-sandbox

--disable-setuid-sandbox


However, two library files were missing in a swiftshader folder in the BlinkBinariesLinux folder:

- libEGL.so

- libGLESv2.so


Thanks again, have a nice day.



GK Gowthamraj Kumar Syncfusion Team October 27, 2021 11:05 AM UTC

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

Please confirm us whether the conversion performed properly or not with these command line argument?  

Please let us know if you need any further assistance with this. 

Regards, 
Gowthamraj K 



KU Kundan October 20, 2023 09:47 PM UTC

Hi 

I am getting this error too


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)


tried above but nothing worked. I am using version 20.4.0.54
Below is the sample code

htmlText = "<html>" + style + "<body style=\"width:210mm;\">" + headerImage + htmlText + "</body></html>";


                        string baseUrl = _iconfiguration.GetValue<string>("AppSettingModel:TempFolderPath");

                        HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();


                        //Initialize blink converter settings.

                        BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

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

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


                        //Set Blink viewport size.

                        blinkConverterSettings.ViewPortSize = new Size(550, 0);

                        //Assign Blink converter settings to HTML converter.

                        htmlConverter.ConverterSettings = blinkConverterSettings;


                        PdfDocument document = htmlConverter.Convert(htmlText, baseUrl);

                        using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite))

                        {

                            //Save and close the PDF document

                            document.Save(fileStream);

                            document.Close(true);

                        }


Image_7658_1697838461857

pls help



SN Santhiya Narayanan Syncfusion Team October 23, 2023 10:43 AM UTC

The reported exception may occur due to the missing of prerequisites and dependent packages in the Linux Docker. And also please make sure to provide the read/write/execute permission for chrome and chrome-wrapper files inside the BlinkBinaries folder.

Please refer the below trouble shooting section for more information,

https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/troubleshooting#failed-to-convert-webpage-exception-in-linux-docker

https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/troubleshooting#failed-to-convert-webpage-exception


Loader.
Up arrow icon