Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image missing when converting a word document to pdf in linux docker container. #302

Closed
sunilshahi opened this issue Jul 24, 2021 · 9 comments
Assignees

Comments

@sunilshahi
Copy link

sunilshahi commented Jul 24, 2021

testfile.docx

I create a ASP.NET core 3.1 Web Application and enabled docker suppot with Linux.

image

image

Then added nuget packages Aspose.Words 21.7.0
And added the above attached testfile.docx to the project.

On the privacy sample razor page, I changed the OnGet Method to look like this.

image

I then ran the project with docker.
Then when I navigate to "/Privacy" I get a pdf download file however the images are missing.

Orginal Docx document.

image

Downloaded Pdf document

image

infact even Aspose watermark image is missing when I do not apply license.

@AlexNosk
Copy link

@sunilshahi Aspose.Words for .NET Standard uses SkiaSharp to deal with graphics. To make it work on Linux, you should add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies
If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.
Please let us know if you still face any issue while using Aspose.Words.

@AlexNosk AlexNosk self-assigned this Jul 26, 2021
@sunilshahi
Copy link
Author

sunilshahi commented Jul 26, 2021

@AlexNosk Thank you for your reply.
I tried installing SkiaSharp.NativeAssets.Linux.NoDependencies that worked as expected.

However, when I tested with SkiaSharp.NativeAssets.Linux and installing libfontconfig1 it did not work. I can use the no dependencies package and move on for now. Just wanted to let you know.

My Dockerfile if you are interested.

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

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

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

FROM base AS final
WORKDIR /app
RUN apt-get update
RUN apt-get install -y libfontconfig1 
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestAsposeImage.dll"]

Thank for help.

@AlexNosk
Copy link

@sunilshahi Which versions of Aspose.Words and SkiaSharp.NativeAssets.Linux do you use in your project? I will check and let you know how it goes on my side.

@sunilshahi
Copy link
Author

Here are my nuget versions from csproj.

  <ItemGroup>
	  <PackageReference Include="Aspose.PDF" Version="21.7.0" />
	  <PackageReference Include="Aspose.Words" Version="21.7.0" />
	  <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
	  <PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.80.3" />
  </ItemGroup>

Also this is the project that I was testing with if you are interested. Test Repo

@AlexNosk
Copy link

AlexNosk commented Nov 2, 2021

@sunilshahi Most likely the problem you have encountered is related to mono/SkiaSharp#1846. I would suggest you to use SkiaSharp 2.80.1, which is used in our internal tests and shows itself as quite stable.

@AlexNosk AlexNosk closed this as completed Nov 2, 2021
@joshfria
Copy link

A year later and this single issue was the only thing to save me after 6+ hours of troubleshooting. Is the need for libfontconfig1 documented anywhere?

@AlexNosk
Copy link

@joshfria I believe this is described in SkiaSharp documentation, but I cannot find this right now. Also, this is described in Aspose.Words documentation here:
https://docs.aspose.com/words/net/how-to-run-aspose-words-in-docker/#configuring-a-dockerfile
Implicitly this is described in SkiaSharp.NativeAssets.Linux.NoDependencies package description:
https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux.NoDependencies#readme-body-tab

@sebestyn168
Copy link

Migrating web app froim windows stack to linux stack also requires SkiaSharp.NativeAssets.Linux.NoDependencies
next step: embed used fonts in the document

@AlexNosk
Copy link

AlexNosk commented Apr 5, 2024

@sebestyn168 Yes, you are right. Aspose.Words for .NET Standard and .NET Core use SkiaSharp to deal with graphics, to make it work on Linux you have to add reference either to SkiaSharp.NativeAssets.Linux or to SkiaSharp.NativeAssets.Linux.NoDependencies

If you add reference to SkiaSharp.NativeAssets.Linux, you should also install libfontconfig1 in your system. SkiaSharp.NativeAssets.Linux depends on this library. You can use the following command to install it:

apt-get update && apt-get install -y libfontconfig1

If you do not have rights to install packages, or other reasons not to install libfontconfig1, you can simply use SkiaSharp.NativeAssets.Linux.NoDependencies, which does not require installation of libfontconfig1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants