Need help on INodeChangingCallback

Hi I’m trying to apply some custom formatting on InsertHtml. I want to indent the text inserted using InsertHtml by half an inch to the left. The text will contain paragraphs, tables etc. I’m trying to use INodeChangingCallback for this but its not working for me. The intent that I apply has no effect. Here’s the code for my callback

public class HandleNodeChangingTextAlignment: INodeChangingCallback
{
    void INodeChangingCallback.NodeInserted(NodeChangingArgs args)
    {
        if (args.Node.NodeType == NodeType.Paragraph)
        {
            ((Paragraph)args.Node).ParagraphFormat.LeftIndent =200;

        }
    }

    void INodeChangingCallback.NodeInserting(NodeChangingArgs args)
    {
        // Do Nothing
    }

    void INodeChangingCallback.NodeRemoved(NodeChangingArgs args)
    {
        // Do Nothing
    }

    void INodeChangingCallback.NodeRemoving(NodeChangingArgs args)
    {
        // Do Nothing
    }
}

Here’s the code where I’m using this callback

string asposeWordsLic = @"D:\Aspose.Words.lic";
License lic = new License();
lic.SetLicense(asposeWordsLic);
Document doc = new Document(@"D:\test.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
doc.NodeChangingCallback = new HandleNodeChanging_FontChanger();
builder.InsertHtml("<p style='text-align: left;'>fsddfdsf</p><p>dsffsds</p><ol><li>fdsfdfd</li><li>fdsfdsdf</li><li>dfsdfffdsfdsf</li></ol><ul><li>fdsf</li></ul><p style='text-align: center;'>    sfdfdsffdsdfsfd</p><ul><li>whatever<ul><li>nested</li></ul></li><li>non nested</li></ul><p>devendra</p>");
doc.Save("c://temp1//myfile.doc");

The generated myfile.doc has the html inserted but the left indent is not applied. It seems that the NodeInserted method is called when the paragraph is inserted but its content is inserted afterwards and somehow the left indentation gets ignored.

If there is a better way to customize the formatting done by InsertHtml method then let me know. I need to change the indentation of paragraphs and bullets.

Any help on this would be appreciated.

Hi
Thank you for reporting this problem to us. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Best regards,

i found the solution for above problem(for this i found this solution given below

if (args.Node.NodeType == NodeType.Run)
{
    Aspose.Words.Font font = ((Run) args.Node).Font;
    Aspose.Words.Paragraph pp = ((Run) args.Node).ParentParagraph;
    pp.ParagraphFormat.LeftIndent = 36;
}

but now i want to change left indentation of a table with this call back(I am inserting a table with InsertHtml and I want it to have a gap of half inch on the left i.e. between the left border of the table and the page margin).i am using aspose 10.5 and i cant use the new version of aspose library.

thanks

Hi
Thanks for your request. I think, you can try using code like the following:

if (args.Node.NodeType == NodeType.Run)
{
    Table table = (Table) args.Node.GetAncestor(NodeType.Table);
    if (table != null)
        table.LeftIndent += ConvertUtil.InchToPoint(0.5);
}

Hope this helps.
Best regards,

Thanks for your reply but
i am sorry i am using aspose(10.1 version) and in this library LeftIndent property is not available in Table.And i also cant change the version of Aspose.Can you provide me some other solution for this.

Thanks
Devendra Soni

Hi
Thanks for your request. You can try using the following code:

if (args.Node.NodeType == NodeType.Run)
{
    Table table = (Table) args.Node.GetAncestor(NodeType.Table);
    if (table != null)
    {
        foreach(Row row in table.Rows)
        {
            row.RowFormat.LeftIndent = ConvertUtil.InchToPoint(0.5);
        }
    }
}

Hope this helps.
Best regards,

The issues you have found earlier (filed as WORDSNET-1792) have been fixed in this Aspose.Words for .NET 23.2 update also available on NuGet.