Aspose.pdf is not working in docker container with linux

Hello Support,

We are exploring aspose.pdf for .Net library to achieve our requirement. While are containerize the same application with linux it is not working properly. it seems to be an fonts issues. the main concern here is that we have to containerize the .net application in linux environment. ones we could be able to resolve the issue then we can go ahead and purchase license of the product. Can you please guide how we can resolve the issue. I am attaching .net core solution here with the ticket for your reference.

you can also find dockerfile within the same solution as well.

Thanks in advance.AsposePdf.zip (299.9 KB)

@vbhattsynoptek
Thank you for preparing and attaching the project.
It started up in my environment (attached a screenshot, launched Docker Compose)
Docker Compose.png (57.6 KB)
screen.png (47.7 KB)
If we assume that the docker should work uniformly, we can assume that the matter is in the environment.
Is it firewall blocking possible?

We have checked from our end as well by reinstalling docker and wsl.exe as well but we are facing same issue. We have also consulted with IT Team and they have confirmed that there are no any blocker from firewall end. We would like to ask below question which may help us to make progress on this ticket.

  1. Which docker version you are using? W are using docker desktop 4.19.0.
    2.Which operating system you are running the solution. - we are using windows 11 pro.
    3.Which aspose version you have used from your end.We are using 23.4.0.

Please let us know your inputs.

Thanks in advance.

@vbhattsynoptek
I have Windows 10 Pro (22H2) installed.
I’m using Docker Desktop version 4.17.0 (running it as administrator). When opening the attached project, I only added the directory to File sharing. And accordingly, the version of the package is the same as in the attached project 23.4
Docker Desktop.png (52.2 KB)

Hello,

Thanks for quick response. We have check the version which you have shared but it is not working in out machine.

We did some R&D and go through couple of solutions, based on it we have added few lines in docker file and it working now.
Addres below lines:
RUN apt-get update && apt-get install -y libgdiplus
RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

RUN ln -s /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so
RUN apt update
RUN apt install -y libgdiplus
RUN ln -s /usr/lib/libgdiplus.so /lib/x86_64-linux-gnu/libgdiplus.so

We are just querious that how it is working in your machine. It would be really helpfull for us to troubleshoot the same.

Please suggest.

how did it show up?

@vbhattsynoptek
By the way, for Linux it’s probably best to use a library Aspose.Pdf.Drawing.
It does not require libgdiplus.

It can be assumed that this is due to the difference in the environments.
I have Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.5.5.
Perhaps influenced by what is installed in Visual Studio.

Thanks for quick response.

Related to aspose.pdf.drawing so we have included in our application but it was still throwing gidplib related runtime exception. to resolve the same we have added gidlib related code into the dockerfile.

We have confirm that we have also VS 2022 and 17.5.5 addition to that we have not install any additional package into that.

Just shared updated demo example prepared from our end. just want to know is it correct way to resolve the issue and is it possible to run application successfully in docker with linux environment without adding addional fonts and gidp library? - asking as you have mentioned earlier, the demo is working in your machine without additional code in docker file which is strange behevior for us :slight_smile:.

the difference is just a docker version as we are using latest version of docker for windows and running application in linux container. please suggest.

Thanks,
Vishal

AsposePdf.zip (488.2 KB)

@vbhattsynoptek

I added packages (to the standard VS installation) and maybe that’s why we have a difference.

Aspose.Pdf.Drawing is an alternative to the Aspose.Pdf package.
And you should use one of these packages (in the attached project, they are both connected).
Aspose.Pdf uses the Gdi library, while Aspose.Pdf.Drawing uses the Aspose.Drawing library.
Accordingly, there are fewer problems when in Linux using Aspose.Pdf.Drawing, especially if you install standard Microsoft fonts.
The main limitation at the moment is the lack of a Printing API.

The project attached in the last post running in my environment without any changes on my part.
Than I removed the Aspose.Pdf library from the project and removed the lines (#4,8) related to gdiplus in the dockerfile.
DockerFileScreen.png (37.6 KB)
And so the project running
.

  • Can you please share package detail with us so that we can also add the same and try from our end?

Thanks,
Vishal Bhatt

@vbhattsynoptek

there are quite a lot of options, besides, my environment is in the national language - I suppose this will not help.

I am attaching screenshots with Docker Desktop settings on my computer.
DockerOptions_1.png (64.2 KB)
DockerOptions_2.png (40.5 KB)
DockerOptions_3.png (53.5 KB)
DockerOptions_4.png (42.5 KB)
DockerOptions_5.png (44.9 KB)
DockerOptions_6.png (66.5 KB)
DockerOptions_7.png (55.2 KB)
DockerOptions_8.png (44.2 KB)
I draw your attention to the fact that I have installed without WSL. It is interesting that although the automatic update was set, the version was like in screenshot 4. I manually set the update, with the updated version (screen 8), the project also started without problems.

Do the following on the Linux container before you start your .net application (sh script which is run from Docker on run):

  apt-get update
  wget http://ftp.us.debian.org/debian/pool/contrib/m/msttcorefonts/ttf-mscorefonts-installer_3.6_all.deb
  apt-get install gdebi-core -y
  gdebi -n ttf-mscorefonts-installer_3.6_all.deb 
  apt-get update && apt-get install -y libgdiplus
  apt-get install -y libgdiplus

Your .net solution should have a runtimeconfig.template.json in there with the following:

{
  "configProperties": {
    "System.Drawing.EnableUnixSupport": true
  }
}

Your csproj under should have the following:

<PropertyGroup>
	<TargetFramework>net6.0</TargetFramework>
	<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

On any HTML assets, images, files that are needed by the PDF copy them to output directory and make sure they are referenced properly by anything that needs them through absolute path or relative if it makes sense.

Our .net application starts up from within the shell file using

./ApplicationName --ENVIRONMENT=Test

Our Dockerfile Example:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env

WORKDIR /app

RUN apt update
RUN apt install -y unixodbc-dev

# Copy everything
COPY . ./

RUN dotnet publish ApplicationTest.sln -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
EXPOSE 80
COPY --from=build-env /app/out .

ENTRYPOINT ["bash","startupshellscript.sh"]
WORKDIR /app

@usmanpop
For now, my work week ends - on Monday I will study that you wrote in last post and write to you.

@usmanpop

I replaced the contents of the dockerfile in the previously attached project with this and the project started.

@usmanpop
However, when I did it again, I got an error
Err.png (3.1 KB)
Tomorrow I will devote more time to your question.

Cannot see your attachment its private.

Do you have a file called startupshellscript.sh in the same location as the Dockerfile?

That file must be copied over into the root of the .net output directory (/bin).

In this case it will be /app.

@usmanpop

Should it be in the ch file?
If I just include this part to existing dockerfile instead of
ENTRYPOINT ["bash","startupshellscript.sh"]
will be the same result?

Please learn how to use Docker and shell scripts.

Follow my example exactly and make sure you are on the same environment from Microsoft Docker images (Debian)

@usmanpop
Maybe it’s better for you to create a project with all the settings and files you want and attach it to be sure that everything is exactly the way you want it to be.
Only in the project should the reference to Aspose.Pdf.Drawing be removed (leaving only Aspose.Pdf).
And for better use in Linux Aspose.Pdf.Drawing, then you don’t need to install gdiplus.

I think first see if it works for you then do the corrections later