DefaultAppearance constructor of PDF Form Fields doesn't work

Hello

We are using Aspose.PDF for .NET (23.1.0). Upgrading to the newest version (23.8.0) makes the DefaultAppearance constructor that takes a Font unusable. This issue can be traced back to version 23.2.0 and still exists in the newest version.

The following code doesn’t work. The Font property of the DefaultAppearance is null, FontName and FontResourceName is C0_0 after running this code.

Using the constructor that takes the name of the font works, however. This can be verified by changing the constructor line to ... new DefaultAppearance(fontName, ...).

[TestMethod]
public void TestFieldsOverrideFont()
{
    // arrange
    new License().SetLicense("Aspose.Total.lic");
    var fontSource = new FolderFontSource("fonts");
    FontRepository.Sources.Add(fontSource);

    var doc = new Document();
    doc.Pages.Add();
    var field = new TextBoxField(doc.Pages.First(), new Rectangle(100, 200, 300, 300));
    field.PartialName = "samplefield";
    doc.Form.Add(field);

    doc.EmbedStandardFonts = true;
    foreach (var fontConfig in doc.FontUtilities.GetAllFonts())
    {
        fontConfig.IsEmbedded = true;
        logger.LogInformation($"Contains font: {fontConfig.FontName}");
    }

    doc.Save();


    var fontName = "DengXianLight";

    // act
    Pdf.Text.Font font = null;
    try
    {
        font = FontRepository.FindFont(fontName, true);
        font.IsEmbedded = false;
    }
    catch
    {
        logger.LogWarning($"Font '{fontName}' was not found.");
    }

    foreach (var formField in doc.Form)
    {
        if (font != null)
        {
            formField.DefaultAppearance = new DefaultAppearance(font, formField.DefaultAppearance.FontSize, formField.DefaultAppearance.TextColor);
        }
    }

    // assert
    Assert.IsTrue(doc.Form.Fields.All(x => x.DefaultAppearance.FontName == "DengXianLight"));
}

@markus.estermann

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-55462

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.