Как создать Docker файл для SautinSoft.HtmlToRtf


    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.

Thanks.


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.