This occurs with Aspose.PDF for .Net 22.6.0 running in a Linux container (Alpine) with .net Core 3.1. Just creating a new WatermarkArtifact value throws an error if Arial font is not installed.
Just using the following statement throws an error before any properties are even set.
The workaround is to install the font with the docker deployment but throwing an error when a WatermarkArtifact object is declared is still an issue.
This is the same as Issue setting watermark for pdf on Unix machine. Works on windows but is still an issue despite a workaround being found. This is one of a number of issues which occur when Aspose.PDF for .Net is used with a Linux container and not in a Windows environment.
var artifact = new WatermarkArtifact();
Font Arial was not found
at Aspose.Pdf.Text.FontRepository.FindFont(String fontName, Boolean ignoreCase)
at Aspose.Pdf.WatermarkArtifact.#=z9VmHVgA=()
at Aspose.Pdf.WatermarkArtifact..ctor()
at CREngland.CareerPdf.MainService.ApplyWatermark(WatermarkRequest request) in /app/MainService.cs:line 916
@williamfa
An investigation ticket as PDFNET-52048 has been logged in our issue tracking system to further analyze this issue. We will look into its details and let you know once it is resolved. Please be patient and spare us some time.
We apologize for the inconvenience.
PS: Meanwhile, could you please share your sample docker file with us as well?
Here is the docker file I’m using
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
COPY CareerPdf/*.csproj ./
COPY CareerPdf/Nuget.Config ./
RUN dotnet restore --configfile ./Nuget.Config
# copy everything else and build app
COPY CareerPdf/. ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
#####################
#PUPPETEER RECIPE
#####################
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& echo "http://dl-cdn.alpinelinux.org/alpine/v3.12/main" >> /etc/apk/repositories \
&& apk upgrade -U -a \
&& apk add \
libstdc++ \
libgdiplus \
chromium \
harfbuzz \
nss \
freetype \
ttf-freefont \
font-noto-emoji \
wqy-zenhei \
&& rm -rf /var/cache/* \
&& mkdir /var/cache/apk
# copy fonts ** NEW **
COPY CareerPdf/InstallFonts/. /usr/share/fonts/truetype/msttcorefonts/
RUN fc-cache -f -v
# Set an environment variable to use that Chrome.
ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/chromium-browser"
#####################
#END PUPPETEER RECIPE
#####################
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:5000
RUN mkdir /certs
EXPOSE 5000
# Required for Time Zone database lookups
RUN apk add --no-cache tzdata
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "CareerPdf.dll"]
Also, thanks for the responses. I initially tried to implement msttcorefonts but due to Microsoft’s licensing it has to remain as it was originally released 20 years or so ago with individual .exe files. Although, the Linux package would unpack the archives without execution this has created policy conflicts on our side which prevent implementation and will need to be addressed before this can be done.
Also, I was able to get some success with a workaround of using the older TextStamp objects and loading the fonts from embedded resources if they are not found with FindFont. I then add the fonts to each pages’ resources as embedded. It seems like a bit of a kludge though. Adding fonts with MemoryFontSource doesn’t seem to have any effect even in Windows.
I edited my dockerfile above to show the new lines copying the fonts from my project folder. I ended up just populating the ttf files myself and checking those in.
For some reason when I run in Linux the values for FontRepository.Sources had only the system source in it. I had to explicitly add the FolderFontSource. After I did this the font seemed to work. I had to reload before the change would be recognized too. In windows the folder source would be there already.
FontRepository.LoadFonts();
if(FontRepository.Sources.Count == 1)
{
var newSource = new FolderFontSource( "/usr/share/fonts/truetype/msttcorefonts" );
FontRepository.Sources.Add( newSource );
}
FontRepository.ReloadFonts();
@williamfa
Thanks for providing more information and the feedback. We have updated the ticket information accordingly so that it can be investigated from these perspectives as well. We will let you know once investigation is complete and ticket is closed. Please spare us some time.
We apologize for the inconvenience caused.