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.
Unfortunately, activation email could not send to your email. Please try again.

How to convert HTML to PDF in Linux docker container

HTML to PDF conversion will be working in Linux docker container using ASP.NET Core.

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

Assemblies Required:

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

NuGet:

  • Syncfusion.HtmlConverter.NETStandard (http://nuget.syncfusion.com/nuget_aspnetcore/nuget/getsyncfusionpackages/aspnetcore)
  • QtBinaries

All the above-mentioned assemblies and QtBinaries can get by downloading the WebKit HTML converter for Linux available in the below link.

WebKit HTML Converter Linux (ZIP file): https://www.syncfusion.com/downloads/latest-version

Docker for windows:

Docker for windows can be downloaded from below link,

https://www.docker.com/docker-windows

Switch between Windows and Linux containers:

From the Docker for Windows menu, it is possible to toggle which daemon (Linux or Windows) the Docker CLI talks to. Select Switch to Windows containers to use Windows containers or select Switch to Linux containers to use Linux containers (the default).

Please refer below steps to convert HTML to PDF in Linux docker container with ASP.NET Core.

  1. Create a new ASP.NET core application.

 

  1. Enable docker support and select target OS with Linux.

 

  1. Install the Syncfusion assemblies and QtBinaries from NuGet package. Please refer below steps to install the Syncfusion.HtmlConverter.NETStandard package.

3.1Right click on the reference and select Manage NuGet Packages… option.

 

3.2Click on the settings icon on the NuGet Package Manager.

3.3 Add the package name and source URL to the below window. The source URL for the Syncfusion NuGet packages is available in the below link,

http://nuget.syncfusion.com/

 

3.3Select the added source name and install the Syncfusion.HtmlConverter.NetStandard package.

 

  1. Download the WebKit HTML converter for Linux (ZIP file) based on the NuGet Package version from below link and copy the QtBinaries folder to the project folder. Then include the QtBinaries folder in project and set copy always for all QtBinaries assemblies.

https://www.syncfusion.com/downloads/version-history

 

  1. Include the below highlighted line in Dockerfile to install the dependency packages in the docker container for converting HTML to PDF.

FROM microsoft/aspnetcore:2.0 AS base

RUN apt-get update && apt-get -y install xvfb && apt-get -y install fontconfig && apt-get -y install libssl1.0-dev && apt-get -y 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

WORKDIR /app

EXPOSE 80

  1. Add an Export To PDF button in index.cshtml.

 

  1. Include below namespace and code snippet in controller for converting HTML to PDF. Please refer below UG link,
  • using Syncfusion.HtmlConverter;
  • using Syncfusion.Pdf;

 

  1. Build and Run the sample in docker. It will pull the Linux docker image from the docker hub and run the project.

 

 

  1. It will prompt for accessing the windows drives and then the webpage will be opened in browser. Click export to PDF button to convert HTML to PDF in Linux docker container.

 

  1. Please refer the output PDF screen shot.

Sample can be downloaded from below location,

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/HTMLtoPDF_DockerLinux-951767502

Article ID: Published Date: Last Revised Date: Platform: Control:
8749 05/15/2018 05/15/2018 ASP.NET Core PDF
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.