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.
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.
at Microsoft.AspNetCore.Routing.EndpointMiddleware.
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:
Do you have a solution to suggest?
Thanks in advance.
|
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; |
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.
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);
}
pls help
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,