Syncfusion HTML to PDF for .NET Core used to convert web pages, and HTML to PDF. Using this library, you can convert any HTML strings or URL or web pages to PDF in Azure Functions 2.0.
In this tutorial, we will illustrate the conversion of HTML to PDF using C# with advanced WebKit rendering engine. In addition, our HTML to PDF converter will work seamlessly in various platforms like Azure cloud or web apps, Amazon Web Service (AWS), Docker, WinForms, WPF, ASP.NET MVC, ASP.NET Core with Windows, Linux, and MacOS.
Steps to convert HTML to PDF in Azure Functions 2.0
- Create an Azure Functions projects.

- Select framework to Azure Functions V2 (.NET Core) and select HTTP triggers as follows.

- Install the Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core NuGet package as a reference to the project.

- Copy the QtBinariesWindows folder from the NuGet package installed location and paste it into the application folder, which contains HTMLtoPDFV20.csproj


- Set Copy to Output Directory property to Copy if newer to all the QtWebKit binaries.

- Include the following namespace in Functions1.cs file to convert the HTML to PDF using C#.
C#
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;
- Add the following code snippet in Function1 class to convert HTML to PDF in Azure Functions V2.
string name = req.Query["url"];
//Initialize HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
WebKitConverterSettings settings = new WebKitConverterSettings();
//Set WebKit path
settings.WebKitPath = Path.Combine(executionContext.FunctionAppDirectory, "QtBinariesWindows");
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert(name);
MemoryStream ms = new MemoryStream();
//Save the PDF document
document.Save(ms);
ms.Position = 0;
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(ms.ToArray());
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "HTMLToPDFAzure.pdf"
};
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
return response;
- Right click the project and select publish. Create a new profile in the publish window.
When creating a publish target, please unselect the Run from package file option. So that, you can avoid the conversion failure due to the permission restrictions.
If you run from package file option, then the function permission becomes read only. But, the WebKit converter requires read/write/execute permission to perform the conversion. Refer to the following screenshot,

- Create App service using Azure subscription and select a hosting plan.

- HTML to PDF conversion will work from basic hosting plan (B1). So, select the hosing plan to B1 or greater and publish. HTML to PDF conversion will not work if the hosting plan is Consumption.

- Once the profile is created, click the publish button.

- Now, go to Azure portal and select the Functions Apps. After running the service, click the Get function URL -> Copy. Paste the same in the browser. In this example, need to pass the webpage URL in the query string, which needs to be converted to PDF.
(https://functionapp20190702110455.azurewebsites.net/api/Function1?url=http://www.google.com&code=***********************)

A complete working sample can be downloaded from HTMLToPDF_AzureFunctions2.0
Convert secured or https sites to PDF in Azure Functions 2.0
When converting HTTPS sites, empty PDF may generate due to missing of the OPENSSL assemblies in Azure website. To convert HTTPS sites, the converter requires OPENSSL assemblies. By default, some Azure websites do not have the OPENSSL assemblies. So, these assemblies should be added to the website explicitly.
You can get the OPENSSL assemblies from here.
- Copy the OPENSSL assemblies into the QtBinariesWindows folder. Refer below screenshot,

- Then set the copy to output directory as “Copy if newer” for all the files under QtBinariesWindows folder.
Hello I tried following this example and while it works well locally (the report takes 3 minutes to generate). However, when I publish to Azure I get a timeout after the function has been running for less than 4 minutes (3min 50s). The azure function is using a dedicated app plan and I have had no issues when running other products I have been evaluating for a longer period, so I am not sure if I am missing any settings on the converter.
Hi Miguel,
The converter may throws the exception under Consumption/Free/Shared hosting plans on Azure. Please make sure you are not using the mentioned hosting plans to publish on Azure environment. Due to the access restrictions and limitation of these hosting plan, it prevents the loading of the browser process. So, the conversion will be failed or timeout in the Consumption/Free/Shared hosting plans on Azure environment. Other hosting plans does not have the restriction for loading the browser process.
If still you are facing the same error, kindly contact us through our Direct Trac
Regards,
Gowthamraj K
The OPENSSL assemblies link above doesn't work. It just tosses you to an "Access Denied" error page on S3. Can that link be updated?
Hi Underwood,
Sorry for the inconvenience caused.
We have updated the proper OPENSSL assemblies link in this KB article. Now you can download the assemblies from below link,
OPENSSL: https://www.syncfusion.com/downloads/support/directtrac/general/ze/OPENSSL-1821714558
Please refer the below link for more details about OPENSSL,
UG: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#openssl
Please let us know if you need any further assistance with this.
Regards,
Gowthamraj K
On my local machine, it is working fine. But, when deploying to Azure It throws an error, HTML conversion failed.
I am hosting it on the b1 plan, I have also unchecked the run from the package file option.
Can you help me to find out what is the issue here?
Thank you,
Hi Jay,
Thank you for contacting Syncfusion support.
We already faced the similar issue in Azure functions 3.1. The reported issue may occurs due to QtBinaries assemblies are not copied properly with Azure SDK 3.0.11. Please follow the below steps to copy the files properly to resolve the reported issue.
Open the Azure portal in browser.
Navigate to the deployed Azure function in Azure portal.
Open the console of Azure function.
As we said earlier, QtBinaries assemblies are not copied properly while publish to Azure functions.
So, we need to manually copy all the assemblies from azure portal.
QtBinariesWindows from location “c:\home\site\wwwroot\QtBinariesWindows” does not have all the assemblies, so we need to copy all the assemblies and inner folder from bin folder.
Using cd command, navigate to the location “c:\home\site\wwwroot\bin\QtBinariesWindows” and run the below command.
cp . c:\home\site\wwwroot\QtBinariesWindows\
Then we need to copy the files from “platform” and “imageformats” folders using the same approach.
Using cd command, navigate to the location “c:\home\site\wwwroot\bin\QtBinariesWindows\platforms” and run the below command.
cp . c:\home\site\wwwroot\QtBinariesWindows\platforms
cp . c:\home\site\wwwroot\QtBinariesWindows\imageformats
Ensure the all the files are copied to “c:\home\site\wwwroot\QtBinariesWindows” location using dir command. Also, ensure the inner folders (imageformats, platforms) has all the files.
Now try the conversion from Azure function URL.
We need to copy this assemblies for the first time only.
Regards,
Gowthamraj K