Aspose PDF.Net in Linux Docker Container. Errors about Symbol font

Hi,

I’m using AsposePDF for .Net to replace text in a pdf. While building the system on my local PC (Windows 11), I only had to install one extra font (ShadowsIntoLightTwo-Regular) to get it working. The text I’m replacing makes use of this font.

We plan to deploy using a Linux container in Docker, so I’ve been testing that locally. As far as I can see, I’m adding the font to the container, though I’m not entirely sure how best to check that.

This is the Dockerfile:

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

COPY ["PDFTest/ShadowsIntoLightTwo-Regular.ttf", "/tmp"]

RUN apt-get update && apt-get install -y fontconfig && mkdir -p /usr/share/fonts/truetype/custom/ && mv /tmp/ShadowsIntoLightTwo-Regular.ttf /usr/share/fonts/truetype/custom/ && fc-cache -fv


FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["PDFTest.csproj", "PDFTest/"]
RUN dotnet restore "PDFTest/PDFTest.csproj"
COPY . .
WORKDIR "/src/PDFTest"
RUN dotnet build "PDFTest.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "PDFTest.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PDFTest.dll"]

When I run the project in docker, it builds, loads the PDF, and attempts to find and replace. At this point, it throws an exception with the error: “Format of font “Symbol” is not supported for new composite fonts”.

I’ve added the lines to list all fonts in use by the pdf:

var fonts = pdfDocument.FontUtilities.GetAllFonts().ToList();
fonts.ForEach(f => Console.WriteLine(f.FontName));

From that I can see that the only fonts used by the pdf are:

VAGRounded-Thin
VAGRounded-Light
VAGRounded-Thin
VAGRounded-Bold
VAGRounded-Bold
AvenirNext-UltraLight
ShadowsIntoLightTwo-Regular
Inspiration-Regular

Any advice to help me get this working?

Thanks,

Mike

@mike.johnson

If the font is not installed in the Windows system, the same or a different error is issued?
Knowing this, it would be possible to determine that the font was not found or that it is not supported in Linux.
Offhand, I can suggest trying to use the Aspose.Pdf.Drawing library (instead of Aspose.Pdf, and then you don’t need to load the libgdiplus package) and use the call

Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("<user's path to ms fonts>"));

It would be nice if you also provided the code you are using (and font), so that I can reproduce it myself and study the issue.

1 Like

Hello. Thanks for the reply. I hadn’t spotted adding font sources that way, though I had looked in the hope that feature existed. I must have been looking in the wrong place.

I dumped every font on my Windows system into a fonts folder and added that as a source, and it worked. Then I went through a process of elimination. It wasn’t the “Symbol” font it was complaining about. It was the regular “Times New Roman” font it wanted. If I leave only “TIMES.TTF” in the source folder it works. Remove it and it stops working.

Perhaps that exception message needs rewording? Maybe it refers to symbols as something other than the “Symbol” font itself, but if so, that makes it confusing. :slight_smile:

Thanks for your help!

Mike

@mike.johnson
Thank you very much for posting the results.
Glad your issue got resolved.
I will point out to the development team that it is desirable to issue font error messages for such cases.