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?
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.
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
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.
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.
Please refer the below kB documentation page
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
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?
...also, the Azure Function example does not show where to add the syncfusion license key.
Where in the Azure Function will this go?
Register the license key in the first line of Azure function class
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;
blinkBinariesPath = SetupBlinkBinaries(executionContext);
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.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
ms.Position = 0;
return new FileStreamResult(ms, "application/pdf");
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.