HTML to RTF not working in Docker container

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

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:


FROM mcr.microsoft.com/dotnet/aspnet:5.0.6-alpine3.13-amd64

RUN apk add icu-libs wget
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
COPY artifacts/ App/
WORKDIR /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.

Cheers!
Oliver
Posts: 27
Joined: Wed Aug 19, 2020 11:59 am
Contact:

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">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<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="*" />
</ItemGroup>

</Project>


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.

DockerFile:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
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...

WORKDIR /app
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 1 guest