Hello,
I’m using Aspose.PDF version 19.4.0 for .NET inside .net core application.
Application is containerized using docker from base image microsoft/dotnet:latest
I have a problem when I run application inside linux containers:
- Text fields with Non embedded fonts are throwing “Object reference not set to an instance of an object” exception, which is probably OK because container does not have those fonts at all
So I tried to change font for those fields by following this thread.
It works on windows. On Linux I’m getting:
residentialAddress1: [Object reference not set to an instance of an object.] ::: at Aspose.Pdf.Annotations.WidgetAnnotation.#=zIGjjKM6i5t_x(Font #=zNID2VIw=)
at Aspose.Pdf.Annotations.WidgetAnnotation.set_DefaultAppearance(DefaultAppearance value)
at AsposeTestConsole.Program.Main(String[] args) in /app/Program.cs:line 80
Font is OpenSans-Regular.ttf. I have also tried with Montserrat-Regular.otf and Helvetica.ttf
Here is my code excerption:
Document doc = new Document(title);
var fields = doc.Form.Fields;
Font font = Aspose.Pdf.Text.FontRepository.OpenFont("fonts/OpenSans-Regular.ttf");
font.IsSubset = false;
font.IsEmbedded = true;
foreach (var field in fields)
{
if (field is TextBoxField)
{
var textField = ((TextBoxField)field);
if (textField.DefaultAppearance.FontName != "MicrosoftSansSerif")
{
DefaultAppearance defaultAppearance = textField.DefaultAppearance;
// Set the font information for form field by using Font object
textField.DefaultAppearance = new DefaultAppearance(font, defaultAppearance.FontSize, defaultAppearance.TextColor);
}
}
}
Can you help?
Thanks.
Fonts used:
fonts.zip (366.0 KB)