Aspose.Words Image Rendering Issue in AWS Lambda

When converting a Word document (.docx) to PDF using Aspose.Words in AWS Lambda, images/logos in the document are missing in the generated PDF. The identical code works perfectly on a local Windows environment, preserving all images.

Are there specific settings required for image preservation in aws lambda?

@tomas2457

Could you please provide more details about the environment setup in AWS Lambda and any specific configurations you are using for Aspose.Words?

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

i added reference to the SkiaSharp.NativeAssets.Linux.NoDependencies and no images in the converted pdf file

thi is my csprog file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <AWSProjectType>Lambda</AWSProjectType>
    <!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <!-- Generate ready to run images during publishing to improve cold start time. -->
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="DTO\**" />
    <EmbeddedResource Remove="DTO\**" />
    <None Remove="DTO\**" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="Aspose.Words.NET.lic" />
    <None Remove="Fonts\arial.ttf" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="Aspose.Words.NET.lic">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="Fonts\arial.ttf">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.ApplicationLoadBalancerEvents" Version="2.2.0" />
    <PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
    <PackageReference Include="Aspose.Words" Version="25.1.0" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.413" />
    <PackageReference Include="EPPlusFree" Version="4.5.3.8" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="3.116.1" />
  </ItemGroup>
</Project>

@tomas2457 As I can see you are using Aspose.Words 25.1. This version used SkiaSharp 2.88.8 version. SkiaSharp 3.116.1 is not compatible with 2.88.8 version, since there were breaking changes in API. So either downgrade SkiaSharp.NativeAssets.Linux.NoDependencies to 2.88.8 version or update Aspose.Words to 25.2 version.

1 Like

It is working now

Thank you!!

1 Like