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
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
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
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.
|
cp *.* c:\home\site\wwwroot\QtBinariesWindows\ |
cp *.* c:\home\site\wwwroot\QtBinariesWindows\platforms |
cp *.* c:\home\site\wwwroot\QtBinariesWindows\imageformats |
Please refer the below
KB steps for more information,
Openssl : https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#openssl
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
...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>")
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.