Aspose Word to PDF / Docker lost images

Hi, I use the last Aspose Word .net library and when I want to save a docx file to pdf from windows all is working fine but when i deploy my application to a linux container based on aspnet microsoft docker image like below picture are lost :

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.20 AS runtime
WORKDIR /app
RUN apk update && apk upgrade && apk add fontconfig && apk add harfbuzz

Could you please help me !
Regards

@jguittonneau

When converting Word documents to PDF using the Aspose.Words library in a Linux container, it’s common to encounter issues with missing images. This can often be attributed to the environment not having the necessary font configurations or libraries that are available on Windows.

Here are some steps you can take to resolve the issue:

  1. Ensure Font Availability: Make sure that the fonts used in your Word documents are installed in your Linux container. You can add additional font packages to your Dockerfile. For example, you can install common fonts using:

    RUN apk add --no-cache ttf-dejavu
    
  2. Font Configuration: Since you are already installing fontconfig, ensure that it is properly configured to recognize the fonts. You might need to run fc-cache to update the font cache after installing new fonts.

  3. Check Image Paths: If your Word documents reference images, ensure that the paths to these images are accessible within the container. If the images are embedded, this should not be an issue, but if they are linked, you need to ensure the links are valid in the container environment.

  4. Test with a Simple Document: Create a simple Word document with a few images and test the conversion process. This can help isolate whether the issue is with specific documents or a broader configuration problem.

  5. Logging and Debugging: Implement logging in your application to capture any errors or warnings during the conversion process. This can provide insights into what might be going wrong.

By following these steps, you should be able to resolve the issue of lost images when converting documents in your Docker container. If the problem persists, consider checking the Aspose documentation or community forums for additional troubleshooting tips.

If you need further assistance, feel free to ask!

I just made a quick test with a single image and it desepeared…

@jguittonneau Aspose.Words for .NET Standard and .NET Core uses 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.

If you are using Aspose.Words version lower than 25.2, You should use 2.88.8 version of SkiaSharp, please use the appropriate nave assets package

<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />

The latest SkiaSharp 3.116.1 is not compatible with 2.88.8 version, since there were breaking changes in API.

Starting from 25.2 version Aspose.Words uses SkiaSharp 3.116.1.

Thank you for your reply. I already apply SkiaSharp lib in my packages and the libfontconfig1 whitout success. Then I changed a lot of thinks in my dockerfile to build from the aspnet sdk and added some extra font libs:

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
    update-ms-fonts && \
    fc-cache -f
RUN apk add --no-cache ttf-dejavu
RUN fc-cache -f -v

And then it works !

@jguittonneau It is perfect that you managed to resolve the problem. Please feel free to ask in case of any other issue, we are always glad to help you.