skip to Main Content

I am using Aspose Pdf library for converting HTML code to PDF Document in Dotnet. In Windows this is working perfectly but in docker image it is showing an error in the second line –
var options = new HtmlLoadOptions();

var pdfDocument = new Document(stream, options);
Here Document is using from Aspose and the steam is –
var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(HtmlData)
do I need any configuration for Aspose in the docker file?

2

Answers


  1. Chosen as BEST ANSWER

    We need to use "Aspose.pdf.drawing" for docker. Forum
    You see the examples from here and here


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

    For your reference here is simple working Dokerfile and .csproj:

    FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
    WORKDIR /app
    RUN apt-get update && apt-get install -y libfontconfig1
    
    FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
    WORKDIR /src
    COPY ["TestNet7.csproj", "."]
    RUN dotnet restore "./TestNet7.csproj"
    COPY . .
    WORKDIR "/src/."
    RUN dotnet build "TestNet5.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "TestNet7.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", "TestNet7.dll"]
    
    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
        <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
      </PropertyGroup>
      
       <PropertyGroup>
         <InvariantGlobalization>false</InvariantGlobalization>
       </PropertyGroup>
    
      <ItemGroup>
          <PackageReference Include="Aspose.Words" Version="24.5.0" />
          <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
      </ItemGroup>
    
    </Project>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search