Exception"Object reference not set to an instance" when changing fonts in linux

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)

@Draxtor,

I have worked with source code shared by you using Aspose.PDF 20.1 and unable to observe the issue. Can you please try to use latest version on your end and share feedback with us.

Tested with 20.1 and it is behaving the same.
Furthermore I noticed few more things:

  • that my font is not embedded even in Windows (but it is replaced by Times new roman) after I uninstalled it from Windows/Fonts
  • after I set default appearance for text field it’s font is null and font name is not the one I sent to the constructor
    C01.png (29.7 KB)
    C02.png (26.2 KB)

Thanks

@Draxtor,

Can you please share complete environment details with us so that we may further investigate to help you out.

Hello Adnan,
Here are my details:

  • Windows - 10 Enterprise Version 1803 64 bit
  • PC - Intel Core i7-7820HQ 2.9 with 32GB of memory
  • Visual Studio Professional 2017 15.9.9
  • Net Core 2.2 - 2.2.100

I’m also attaching sample project together with PDF, font and dockerfile I’m using.
So, current situation is that in windows my font is not embedded but no errors and in linux I’m getting exceptions.
AsposeTestConsole.zip (5.6 MB)

If you need more info I’ll be glad to provide it.

Thanks

@Draxtor,

We have tested the scenario in our environment. We have logged it as PDFNET-47546 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

@Adnan.Ahmad , how do I find the status of this issue. Having similar problems.

@michael.dennis

You can check the status of the issue showing at the bottom of the page under Issue Status heading. Furthermore, we will inform in this forum thread as soon as the ticket is investigated and resolved. At the moment, the ticket is pending for a fix due to other issues in the queue logged prior to it. In free support model, the issues are resolved on a first come first serve basis. We will let you know in this forum thread as soon as the ticket is resolved. Please spare us some time.

We apologize for the inconvenience.