How to consume the HTML to PDF conversion from Azure App Service (Windows) via Azure functions (Linux)?
The Syncfusion® HTML to PDF converter is a .NET library that uses C# for converting webpages, SVG, MHTML, and HTML to PDF. It is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage.
Due to GDI limitations in Azure App Service windows, the Blink rendering engine does not support HTML conversion directly. As a workaround, we can use Azure functions on Linux to perform HTML to PDF conversion using Blink in the Azure App Service on Windows.
How to use Blink HTML to PDF conversion in Azure App Service windows using Azure functions on Linux:
- To achieve this, we need to create an Azure function app and publish the function to Azure Function Linux. Get the function URL and ensure that the functions are working properly after publishing the Azure Function App.
Kindly refer the following KB documentation to create and publish the Azure function Linux with the Blink rendering engine: https://www.syncfusion.com/kb/12908/how-to-convert-html-to-pdf-using-blink-in-azure-functions-linux
- Create a new ASP.NET Core MVC application.
- Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your project from NuGet.org.
- Add a Convert To PDF button in index.cshtml.
@{ Html.BeginForm("ConvertToPDF ", "Home", FormMethod.Post); { <input type="submit" value="Convert To PDF" class=" btn" /> } }
- Include the following namespaces and code snippet in controller for calling your azure function URL from your azure app service:
you can load the converted PDF document and perform the post processing functionalities such as adding encryption, digital signature etc., to the output PDF document.
// [C# Code] using System.IO; using Syncfusion.Pdf; using Microsoft.AspNetCore.Hosting; public IActionResult ConvertToPDF() { //Add the Azure function URL to convert HTML to PDF string functionURL = "https://binkhtmltopdflinuxappp.azurewebsites.net/api/Function1?"; //URL to convert to PDF document string url = "https://www.syncfusion.com"; string functionUrlwithParameter = functionURL + "url=" + url; //Create HttpWebRequest with azure functions URL. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(functionUrlwithParameter); //Gets the response from the Azure Functions. HttpWebResponse res = (HttpWebResponse)req.GetResponse(); MemoryStream stream = new MemoryStream(); res.GetResponseStream().CopyTo(stream); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream); //Document security. PdfSecurity security = loadedDocument.Security; security.Algorithm = PdfEncryptionAlgorithm.AES; security.OwnerPassword = "syncfusion"; security.UserPassword = "password"; loadedDocument.Save(stream); loadedDocument.Close(); // Save the response stream as PDF document. return File(stream.ToArray(), "application/pdf", "Output.pdf"); }
Refer to the following steps to publish as Azure App Windows:
- Right-click the project and select Publish.
- Create a new profile in publish target window.
- Create an App service using Azure subscription and select a hosting plan.
- After creating a profile, click the publish button.
- The published webpage will now be shown in the browser. Click Convert to PDF to convert the Google webpage to a PDF.
A complete work sample for consuming the HTML to PDF conversion from Azure App Service (windows) via Azure functions (linux) can be downloaded from HtmlToPDF_Azure.zip
Take a moment to peruse the documentation, where you will find other Blink rendering engines supported by Syncfusion .NET PDF library for converting HTML pages to PDF document along with respective customization options and features.
Click here to explore the rich set of Syncfusion Essential® PDF features.
An online sample link to convert HTML to PDF.
HTML to PDF conversion in Linux docker container
HTML to PDF conversion in Azure Function
HTML to PDF conversion in ASP .Net Core Linux
HTML to PDF conversion in Azure App Service
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.