Images missing when saving Word document as PDF in LINUX docker container

Hi Aspose Support Team,

We have a use case to save Word documents containing images as PDF documents using Aspose.Words for .NET.

The prod environment is a docker based linux system. We are developing on Windows machines.

On Windows, it works as expected. Running the code on linux, the images in the generated PDF documents are missing.

We prepared a simple solution to reproduce the issue: GitHub - e-experts-gmbh/aspose-words-to-pdf-missing-images

Is this a bug in Aspose.Words or is something wrong with our code?

Kind regards,
Adrian

@adrian732

It seems that you are experiencing an issue where images are missing when saving Word documents as PDF in a Linux Docker container using Aspose.Words for .NET. This issue does not occur in your Windows environment, which suggests that it may be related to the environment configuration or dependencies in the Linux setup.

Here are a few steps you can take to troubleshoot and potentially resolve the issue:

  1. Check Image Paths: Ensure that the images in your Word document are accessible in the Linux environment. If the images are linked rather than embedded, the paths must be valid in the Docker container.

  2. Docker Configuration: Verify that your Docker container has all the necessary libraries and dependencies installed. Sometimes, missing libraries can lead to issues with rendering images.

  3. Use PdfSaveOptions: When saving the document, you can specify various options using PdfSaveOptions. For instance, you might want to ensure that the images are being processed correctly. Here’s a basic example of how to use PdfSaveOptions:

    Document doc = new Document("path/to/your/document.docx");
    PdfSaveOptions saveOptions = new PdfSaveOptions
    {
        // You can set various options here
    };
    doc.Save("path/to/output/document.pdf", saveOptions);
    
  4. Check for Warnings: Implement a warning callback to capture any warnings that occur during the saving process. This can help identify if there are issues with specific images or other elements in the document:

    HandleDocumentWarnings callback = new HandleDocumentWarnings();
    doc.WarningCallback = callback;
    doc.Save("path/to/output/document.pdf", saveOptions);
    foreach (WarningInfo warning in callback.mWarnings)
    {
        Console.WriteLine(warning.Description);
    }
    
  5. Test with Different Images: If possible, test with different images or a simpler document to see if the issue persists. This can help isolate whether the problem is with specific images or the overall document.

If after trying these steps the issue still persists, it may be beneficial to check the Aspose documentation or reach out to Aspose support for further assistance, as there could be specific configurations or known issues related to the Linux environment.

For more detailed examples and options, you can refer to the Aspose documentation on working with PDF save options here.

If you have any further questions or need additional assistance, feel free to ask!

1 Like

@adrian732 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.

1 Like

Thanks for your help.

Using a WarningCallback, the message DrawingML picture rendering failed with exception:'The type initializer for 'iY' threw an exception.' shows up.

The project references SkiaSharp.NativeAssets.Linux and libfontconfig1 gets installed.

Downgrading SkiaSharp.NativeAssets.Linux from 3.119.0 to 3.116.1 solved the issue with the missing images in PDF documents.

How can the matching version of SkiaSharp.NativeAssets.Linux be found?
Would it be worth to extend the docs and a comment, that the version of SkiaSharp.NativeAssets.Linux has to match the version of SkiaSharp that Aspose.Words requires?

@adrian732 Yes, you are right it is recommended that SkiaSharp.NativeAssets version matches the SkiaSharp version specified in dependencies tab on NuGet:
https://www.nuget.org/packages/Aspose.Words#dependencies-body-tab

But this is not a rule, usually SkiaSharp versions are backward compatible, but it is better to use the matched versions to make sure functionality works as expected.

1 Like