We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Pdf not getting generated on cloud with Aspose.Pdf.Drawing

Our image is running with libgdiplus but still it is not working in Linux container.

The easiest variant in your case is to use Aspose.Pdf.Drawing.
Aspose.Pdf package can also be used in many cases, but you need to upload libgdiplus there and very likely the fonts.

Thank you for your response !!

We have used RUN apt-get update && apt-get install -y libgdiplus in our docker file but it still throw error
“The type initializer for ‘Gdip’ threw an exception.”

When i install aspose pdf from nuget it reference system.common.drawing

is there anything special we need to use for Linux Container.

You can use Aspose.Pdf.Drawing 23.3 from nuget.org.
Then you don’t even need to run libgdiplus.

thank you sergei.

I have removed aspose.pdf.
I added Aspose.pdf.drawing.
Now simple pdf generation code is throwing “value can not be null while save”

        Document document = new Document();
        Page page = document.Pages.Add();
        page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World!"));
        MemoryStream memoryStream = new MemoryStream();
        document.Save(memoryStream, SaveFormat.Pdf);//getting value can not be null error in docker(linux)
        return File(memoryStream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "output.pdf");


Yes, it really does not work - as you wrote, an exception occurs (with both versions of the library).
Thanks for writing - I’ll create a task for the development team.

I additionally looked together with the developers - the problem occurs due to the absent font. You need to load the fonts into the container. If you can’t do it, write here.

Thank you @sergei.shibanov you are life savior !

I have written something like below in docker file for font right now

RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

I am struggling to install MSMINCHO font in Linux container doing some research for the same though.

Thanks you very much.

Is this font standard? Perhaps you should keep this font in a separate folder in the container and load it. Like that:
COPY /Fonts /usr/share/fonts/truetype
and maybe you don’t even need to explicitly tell linux to update the fonts.

Thank you @sergei.shibanov !!

In docker file i have written something like(i have this font MSMINCHO.TTF in fonts folder)

RUN mkdir -p /usr/share/fonts/truetype/
COPY /fonts /usr/share/fonts/truetype
RUN install -m644 MSMINCHO.TTF /usr/share/fonts/truetype/

but when i try to hit endpoint same error “value can not be null" error.

image.png (2.4 KB)
image.png (37.9 KB)

Same code is working with IIS but not in docker.
Now my docker file looks like this (too many experiment)
image.png (7.7 KB)

I added the command to the dockerfile
COPY /Fonts /usr/share/fonts/truetype/msttcorefonts
after writing in the Fonts folder all the ttf fonts that I have in the Windows system.
by using:

var fonts = new InstalledFontCollection();
Console.WriteLine("installed fonts:");
foreach(FontFamily family in fonts.Families)

make sure they are installed on the system.
But the exception still occurred.

I solved the problem by adding the line
<DockerfileRunArguments>-v C:\Windows\Fonts:/usr/share/fonts/truetype/msttcorefonts</DockerfileRunArguments>
in the csproj of the project. (And I need adding a folder c:\windows to shared in Docker Desctop)
I am attaching a project that works in my environment without exception.

completely csproj looks so:

    <DockerfileRunArguments>-v C:\Windows\Fonts:/usr/share/fonts/truetype/msttcorefonts</DockerfileRunArguments>

    <PackageReference Include="Aspose.PDF.Drawing" Version="23.3.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />


Thank you @sergei.shibanov for your time.

This code worked wonderful in my local docker environment, just perfect on my docker desktop with Linux container.

But it isn’t working on my cloud environment, maybe our cloud support team can help with this. thank you !

I am wondering is there any other way around to install custom font in docker. except what we have tried above.

image.png (2.6 KB)

Is it possible to write fonts to some directory and work by loading fonts from there?
I used C:\Windows\Fonts just to make it obvious that I’m using the fonts folder.