Images missing when converting word to PDF in LINUX docker container

Hi Team,

i am trying to convert a word document to pdf and its working fine in my local windows machine. I have also installed SkiaSharp.NativeAssets.Linux version 1.68.1.1. and all my images are of type png or bmp. But in LINUX Docker container all my images are missing and here is my dockerfile that i am using

FROM mcr.microsoft.com/dotnet/core/runtime:2.1-stretch-slim AS base

WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build

WORKDIR /src

COPY ["./.", "PdfPOC/"]

RUN dotnet restore "PdfPOC/PdfPOC.csproj"

COPY . .

WORKDIR "/src/PdfPOC"

RUN dotnet build "PdfPOC.csproj" -c Release -o /app/build

FROM build AS publish

RUN dotnet publish "PdfPOC.csproj" -c Release -o /app/publish

FROM base AS final

WORKDIR /app

COPY --from=publish /app/publish .

#RUN apt-get install -y ttf-mscorefonts-installer

RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

RUN apt-get install -y libfreetype6

RUN apt-get install -y libfontconfig1

ENTRYPOINT ["dotnet", "PdfPOC.dll"]

UPDATE: Issue is Fixed by Installing the Nuget Package SkiaSharp.NativeAssets.Linux.NoDependencies

@adithya_sai

It is nice to hear from you that your problem has been solved.

We suggest you please read the following article.
How to Run Aspose.Words in Docker

Hi Team,

I’m facing same issues and Installed the Nuget Package but no use .

Below is the docker file:

FROM mcr.microsoft.com/dotnet/aspnet:3.1-alpine3.15 AS base 
WORKDIR /app

EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Kubernetes1.csproj", "./"]

RUN dotnet restore "./Kubernetes1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Kubernetes1.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app

RUN apk update && apk upgrade && apk add fontconfig
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Kubernetes1.dll"]
<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

Project file :

  <ItemGroup>
    <PackageReference Include="Aspose.Words" Version="21.11.0" />
    <PackageReference Include="Goelze.SkiaSharp.NativeAssets.AlpineLinux" Version="1.68.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Kubernetes.Tools.Targets" Version="1.1.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
    <PackageReference Include="WindowsAzure.StorageExtensions" Version="1.3.0" />
  </ItemGroup>

@svgvijay.chinna In your project file you have added several dependencies on Linux native assets for SkiaSharp. Please modify your project file like this:

  <ItemGroup>
    <PackageReference Include="Aspose.Words" Version="21.11.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Kubernetes.Tools.Targets" Version="1.1.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.1" />
    <PackageReference Include="WindowsAzure.StorageExtensions" Version="1.3.0" />
  </ItemGroup>

Note, I have changed the version of SkiaSharp.NativeAssets.Linux.NoDependencies to 2.80.1 this is the version of SkiaSharp Aspose.Words is tested with.

Also, please attach your input and output documents here for testing. We will check the conversion on our side and provide you more information.

Hi Alexey,

Thanks for responding.

I tried as you suggested but still it’s not working. Could you please find the attached input and output files.

Thanks & Regards.
Vijay.

(Attachment Input.HTML is missing)

Output.pdf (5.19 KB)Input.docx (13.1 KB)

@svgvijay.chinna Thank you for additional information. I have managed to reproduce the problem on my side. For a sake of correction it has been logged as WORDSNET-24110. We will keep you updated and let you know once it is resolved or we have more information for you.
It looks like the problem is specific for Alpine image, if use Debian image, the document is rendered fine. So as a temporary workaround you can try using buster image.

@svgvijay.chinna I have investigated the issue and determined that there is a missed dependency of libSkiaSharp.so on Alpine Linux. Running the following command in the docker:

ldd libSkiaSharp.so

Returns the following:

        /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
        libpthread.so.0 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
        libdl.so.2 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
        libm.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
        libc.so.6 => /lib/ld-musl-x86_64.so.1 (0x7ff838b7f000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by libSkiaSharp.so)

As you can see the dependency ld-linux-x86-64.so.2 is missed. I have installed gcompat package to resolve this:

RUN apk add --no-cache gcompat

Here is my full Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:6.0-alpine3.15 AS base
WORKDIR /app

# Required to make SkiaSharp 2.80.1 work. If use 2.80.3 SkiaSharp.NativeAssets.Linux.NoDependencies it is not required.
#RUN apk add --no-cache fontconfig
# Requred to make code works on 6.0-alpine3.15. See https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html
RUN apk add --no-cache icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
# For debug purposes.
RUN apk add --no-cache bash
# Add the missed ld-linux-x86-64.so.2 dependency.
RUN apk add --no-cache gcompat

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["TestNet6.csproj", "."]
RUN dotnet restore "./TestNet6.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestNet6.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestNet6.csproj" -c Release -r linux-x64 --no-self-contained -o /app/publish

FROM base AS final

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

I have tested with a simple .NET6 console application. Here is my .csproj file:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>
  
   <PropertyGroup>
     <InvariantGlobalization>false</InvariantGlobalization>
   </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Aspose.Words" Version="22.7.0" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.80.3" />
  </ItemGroup>

</Project>

Note, I have used 2.80.3 version of SkiaSharp.NativeAssets because there was a mistake in NoDependencies package in 2.80.1 and it still requires fontconfig package (See comments in Dockerfile).
And here is my source code:

using Aspose.Words;
using System;
using System.Diagnostics;

namespace Aspose.NetCore.TestRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            License lic = new License();
            lic.SetLicense("/temp/Aspose.Words.NET.lic");

            Document doc = new Document("/temp/in.html");
            doc.Save(@"/temp/out.pdf");

            Console.WriteLine("Done");
        }
    }
}

Commands to build and run the docker image are the following:

docker build -t awtest .
docker run --mount type=bind,source=C:\Temp,target=/temp --rm awtest from Docker

In case if you need to check what is published to the container you can run the container as the following:

docker run --rm -it --entrypoint=/bin/bash awtest

but since Alpine docker image doesn’t have bash installed by default. You will need to add it (See Dokerfile).

Thanks for workaround ,It’s working and below is the my Docker file

FROM mcr.microsoft.com/dotnet/aspnet:3.1-focal AS base 

WORKDIR /app

EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Kubernetes1.csproj", "./"]

RUN dotnet restore "./Kubernetes1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "Kubernetes1.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app

RUN apt-get update && apt-get install -y libfontconfig1
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "Kubernetes1.dll"]

@svgvijay.chinna It is perfect that you managed to resolve the problem on your end. I see you have decided to switch to Ubuntu image instead of Alpine. Please feel free to ask in case of any further issues. We will be glad to help you.

@alexey.noskov: Now we have another problem for font type.

While running local the font type is “ TimesNewRomanPSMT ” , but in Ubuntu getting different font type “DejaVuSerif”.

@svgvijay.chinna Upon rendering documents Aspose.Words requires the fonts. If Aspose.Words cannot locate the required fonts, the fonts are substituted. You can implement IWarningCallback to get notification when font substitution is performed.
I suspect DejaVu is the only available font family in your Docker container. To get more accurate result you can install the required fonts or put them in folder available to Aspose.Words.

Thanks for your response

RUN apt-get update
RUN apt-get -y install ttf-mscorefonts-installer

Added above lines in Dockerfile but now getting different issue that is French and Spanish language

Spanish

Excepted: Económicos
Current: Económicos

French

Excepted: l’Économie
Current: l’Économie

@svgvijay.chinna Could you please attach the problematic documents (both input and output) here for testing? We will check the issue and provide you more information.

Input.docx (12.4 KB)
Output.docx (11.8 KB)

Could you please find the attached input and output documents .

@svgvijay.chinna It looks like you are generating the document from HTML. Could you please provide code that you use and that will allow us to reproduce the problem?

The issues you have found earlier (filed as WORDSNET-24110) have been fixed in this Aspose.Words for .NET 23.9 update also available on NuGet.