We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to convert HTML to PDF in ASP.NET Core Linux

Platform: ASP.NET Core |
Control: PDF

Syncfusion HTML to PDF for .NET used to convert webpages, SVG, MHTML, and HTML to PDF. Using this library, you can convert HTML to PDF in ASP.NET Core application using .Net Standard 2.0.

Minimum product version:

Minimum .NET core version: 2.0.0

For converting HTML to PDF in Linux, the following pre-requisite packages should be installed in the Linux machine. To do that, enter the following commands in the terminal:

$ sudo apt-get update

$ sudo apt-get install xvfb

$ sudo apt-get install libssl-dev

$ sudo apt-get install libx11-dev libx11-xcb-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-render0-dev libxcb-shm0-dev libxcb-util0-dev libxcb-xfixes0-dev libxcb-xkb-dev libxcb1-dev libxfixes-dev libxrandr-dev libxrender-dev

The following assemblies or NuGet package is required for converting HTML to PDF in ASP.NET Core Linux.

Assemblies required:

  • Syncfusion.Compression.Portable.dll
  • Syncfusion.Pdf.Portable.dll
  • Syncfusion.HtmlConverter.Portable.dll
  • QtBinaries

You can get all the previously mentioned assemblies, QtBinaries, and working samples by installing the HTML converter installer for Linux available in the following link.

HTML converter Linux (zip file): https://www.syncfusion.com/downloads/latest-version

HTML converter Linux


Install the Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core NuGet package as reference to your .NET Core application from NuGet.org. The NuGet package contains QtBinaries for all platforms (Windows, Linux and Mac). Copy the QtBinariesLinux folder from the NuGet package installed location and paste it into your application folder to use it for conversion.

NuGet Installed location: /.nuget/packages/syncfusion.htmltopdfconverter.qtwebkit.net.core/XX.X.X.XX/lib

Steps to convert HTML to PDF in ASP.NET Core Linux programmatically:

  1. Extract the zip file (syncfusionessentialwebkit.zip) in Linux and open the QtBinaries folder in file explorer.
  2. Provide the execute permission for Syncfusion.WebKitWrapper file inside the QtBinaries folder. Refer to the following screenshot. Allow permission
  3. Open the project folder (HtmlToPdf.csproj) in Linux terminal, then, enter the following commands one by one to run the sample.
  • dotnet restore
  • dotnet build
  • dotnet run
  1. Enter the localhost server path in the web browser to view the result. Localhost server path

Use the following code snippet to convert HTML to PDF in ASP.NET Core Linux.


//To get content root path of the project
private readonly IHostingEnvironment _hostingEnvironment;
public HomeController(IHostingEnvironment hostingEnvironment)
   _hostingEnvironment = hostingEnvironment;
public IActionResult ExportToPDF()
 //Initialize HTML to PDF converter 
 HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
 WebKitConverterSettings settings = new WebKitConverterSettings();
  //Set WebKit path
  settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesLinux");
  //Assign WebKit settings to HTML converter
  htmlConverter.ConverterSettings = settings;
  //Convert URL to PDF
  PdfDocument document = htmlConverter.Convert("https://www.google.com");
  MemoryStream stream = new MemoryStream();
  return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf");


A complete working sample can be downloaded from HTMLtoPDF_Linux.zip

Take a moment to peruse the documentation for Converting HTML to PDF, where you will find various options for URL to PDF, HTML string to PDF, and hyperlinks.

2X faster development

The ultimate ASP.NET Core UI toolkit to boost your development speed.
You must log in to leave a comment
Muhammad Saad Shaukat
Jan 24, 2022

In addition to above this package https://pkgs.org/download/libqt5webkit5 was also needed when I used it on Ubuntu 20.04, without it Syncfusion.WebKitWrapper generates error.

Sep 18, 2022

did you copy QtBinaries folder manually? I have no problem on windows, but on Ubuntu 20.04 wont work. Installed webkit5 as well, but always got this error: "Message":"Syncfusion.Pdf.PdfException: An error occurred trying to start process \u0027xvfb-run\u0027 with working directory \u0027/app\u0027. No such file or directory\n at Syncfusion.HtmlConverter.HtmlConverter.ConvertHtmlToPdf(String url, Int32 width, Int32 height, String tempFile)\n

My code is:

 _logger.LogInformation("###################### Usao u pdf generator");

            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

            string baseUrl = string.Empty;

            PdfDocument document = htmlConverter.Convert(htmlFile, baseUrl);

            MemoryStream ms = new MemoryStream();
            // Save and close the document.

            //Reset the memory stream position.  
            ms.Position = 0;

             var fileBytes = ms.ToArray();

            return fileBytes;
Gowthamraj Kumar [Syncfusion]
Sep 19, 2022

Hi Nikola,

The reported exception may occur due to missing of prerequisites and dependent packages in the Linux environment. Kindly ensure that all the required prerequisites and dependent packages are installed in the machine/container. We need to have all the dependencies in the machine/container in order to perform the conversion inside the machine/container,


Please follow the below 5th steps to install the required dependencies package,

KB: https://www.syncfusion.com/kb/8749/how-to-convert-html-to-pdf-in-linux-docker-container

Please let us know if you need any further assistance in this.


Gowthamraj K


Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile