Free Support Forum - aspose.com

Aspose Words not displaying correct font when using HTML ordered list

I am having a problem with the font not being correct when inserting HTML into Aspose Words.

All the text inserted renders correctly except for the numbers in an ordered list
    . I am using Calibri which is fine but the font for the numbers in the ordered list are rendered in a Serif font, which is incorrect.

    This is the code that I am using to insert the html into the document.

    builder.Document.NodeChangingCallback = new HandleNodeFont(“Calibri”, 10.0);
    builder.InsertHtml(strHTML);
    builder.Document.NodeChangingCallback = null;

    Please advise as to what I am missing to correct this issue.

    Cheers,
    James

    Hi James,


    Thanks for your inquiry. Could you please attach your Html and complete code here for testing? I will investigate the issue on my side and provide you more information.

    Best regards,

    Sample html follows:


    Some Text Here

    1
    2
    3
    1. Item One
    2. Item Two
    3. Item Three

    4. The code is just the same from the original post with a document being a document builder. The following code handles the INodeChangingCallback.

      public class HandleNodeFont : INodeChangingCallback
      {
      private string Name;
      private double Size;

      public HandleNodeFont(string name, double size)
      {
      this.Name = name;
      this.Size = size;
      }

      void INodeChangingCallback.NodeInserting(NodeChangingArgs e)
      { }

      void INodeChangingCallback.NodeInserted(NodeChangingArgs e)
      {
      if (e.Node.NodeType == NodeType.Run)
      {
      ((Run)e.Node).Font.Name = Name;
      ((Run)e.Node).Font.Size = Size;
      ((Run)e.Node).ParentParagraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
      ((Run) e.Node).ParentParagraph.ParagraphFormat.LineSpacing = 15;
      }
      }

      void INodeChangingCallback.NodeRemoving(NodeChangingArgs e)
      { }

      void INodeChangingCallback.NodeRemoved(NodeChangingArgs e)
      { }
      }


      please let me know what you find or if you need anything else from me.

      Hi James,


      Thanks for the additional information. Please use the following code snippet to change the Font values of list numbering:

      public class HandleNodeFont
      : INodeChangingCallback

      {

      private string Name;

      private double Size;

      public HandleNodeFont(string name, double size)

      {

      this.Name = name;

      this.Size = size;

      }

      void INodeChangingCallback.NodeInserting(NodeChangingArgs e)

      { }

      void INodeChangingCallback.NodeInserted(NodeChangingArgs e)

      {

      if (e.Node.NodeType == NodeType.Run)

      {

      ((Run)e.Node).Font.Name = Name;

      ((Run)e.Node).Font.Size = Size;

      ((Run)e.Node).ParentParagraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;

      ((Run)e.Node).ParentParagraph.ParagraphFormat.LineSpacing = 15;

      }

      if (e.Node.NodeType == NodeType.Paragraph)

      {

      if (((Paragraph)e.Node).IsListItem)

      {

      Paragraph listItem = ((Paragraph)e.Node);

      listItem.ListLabel.Font.Name = Name;

      listItem.ListLabel.Font.Size = Size;

      }

      }

      }

      void INodeChangingCallback.NodeRemoving(NodeChangingArgs e)

      { }

      void INodeChangingCallback.NodeRemoved(NodeChangingArgs e)

      { }

      }


      I hope, this helps.

      Best regards,