HTML to RTF not working in Docker container

Get technical support of HTML to RTF .Net in C# and VB.Net
Posts: 1
Joined: Tue Jul 20, 2021 5:02 am

HTML to RTF not working in Docker container

Post by aplant92 »

Hi all,

I've got a bit of a weird problem - I have a .NET 5.0 service that converts some HTML to RTF as part of it's responsibilities. This works fine when I run it locally on my machine (Linux), however when I run the same service dockerised, the OpenHtml() method returns false - indicating it can't process the HTML.

Is there some special setup required in a docker container to make sure it plays nice with Sautinsoft? The Dockerfile I'm using is as follows:


RUN apk add icu-libs wget
COPY artifacts/ App/

ENTRYPOINT ["dotnet", "WriteupLoaderService.Host.dll"]

Any help here would be much appreciated - there's next to no error logging around failure to load HTML text it seems, so I'm not sure where to go from here.

Posts: 55
Joined: Wed Aug 19, 2020 11:59 am

Re: HTML to RTF not working in Docker container

Post by Oliver »


Try to play with these settings:

The following is a project file for the .NET Core application with added Docker support.

<Project Sdk="Microsoft.NET.Sdk">


<PackageReference Include="SautinSoft.HtmlToRtf" Version="*" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="*" />
<PackageReference Include="System.Drawing.Common" Version="*" />
<PackageReference Include="System.Security.Permissions" Version="*" />


To configure or customize a Docker image, you'll need to edit the Dockerfile.

When creating HTML to RTF files with images, System.Drawing.Common is used to process image data, which requires a libgdiplus package on a Linux container.

When creating RTF /DOCX files, the font files need to be present in the container. The official Linux images for .NET won't have any fonts installed. So, you'll need to copy the necessary font files to the Linux container, or install a font package like ttf-mscorefonts-installer, or add them as Private Fonts.

The following example shows how you can create HTML to RTF files from Docker containers and configure Docker images with Dockerfile.


FROM AS base

FROM AS build
COPY ["HtmlToRtfDocker.csproj", ""]
RUN dotnet restore "./HtmlToRtfDocker.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "HtmlToRtfDocker.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HtmlToRtfDocker.csproj" -c Release -o /app/publish

FROM base AS final

# Update package sources to include supplemental packages (contrib archive area).
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list

# Downloads the package lists from the repositories.
RUN apt-get update

# Install System.Drawing.Common dependency.
RUN apt-get install -y libgdiplus

# Install Microsoft TrueType core fonts.
RUN apt-get install -y ttf-mscorefonts-installer

# Or install Liberation TrueType fonts.
# RUN apt-get install -y fonts-liberation

# Or some other font package...

COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HtmlToRtfDocker.dll"]

By the way, try to change versions of HTML to RTF.Net also.

I hope these recommendations will help you. If not, then we will definitely find the right solution together!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests