Replace character by bullet

Hi,
Our client wants to change the character “Alt + 1049” (small point) by a bullets. This character is used when we enter the text in a simple textbox so that we can’t insert bullet. But when we generate our templates, the client wants the bullets. Does there exist a means of making the change with Aspose??? I’m using C# with Aspose.Words 9.8.
Thanks
Steeve

Hi

Thanks for your request. Could you please attach your input document here for testing? I will check it on my side and provide you more information.
Best regards,

Hi Andrey,
I have attached a example.
Thanks
Steeve

Hi Steeve,

Thank you for additional information. Please try using the following code to achieve what you are looking for:

Document doc = new Document("C:\\Temp\\Test+For+Aspose.docx");
Regex regex = new Regex("\x2022", RegexOptions.IgnoreCase);
doc.Range.Replace(regex, new MyReplacingCallback(), false);
doc.Save("C:\\Temp\\out.docx");
private class MyReplacingCallback: IReplacingCallback
{
    public ReplaceAction Replacing(ReplacingArgs args)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = args.MatchNode;
        // We should get paragraph to apply bullet
        Paragraph paragraph = (Paragraph) currentNode.ParentNode;
        // Apply bullet for this paragraph
        paragraph.ListFormat.ApplyBulletDefault();
        return ReplaceAction.Replace;
    }
}

Best regards,

Hi Andrey,
It works well. Thanks for your quick answers, it’s very appreciated!!
2 more things that I have some difficulties:

- I need the insert a custom bullet, a colored small square (client choice in the application). I don’t know how to use a bullet that I have defined (bullet menu);
- How can I set the paragraph to fit like my example in attachment?? Can I remove the tab??
Thanks
Steeve

Hi
Thanks for your request. Unfortunately, there is no way to insert pictured bullets. We will consider adding such feature in one of future versions. But as a workaround you can try using th following code:

private class MyReplacingCallback: IReplacingCallback
{
    public ReplaceAction Replacing(ReplacingArgs args)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = args.MatchNode;
        // We should get paragraph to apply bullet
        Paragraph paragraph = (Paragraph) currentNode.ParentNode;
        // Apply bullet for this paragraph
        paragraph.ListFormat.ApplyBulletDefault();
        paragraph.ListFormat.ListLevel.NumberPosition = 0;
        paragraph.ListFormat.ListLevel.TextPosition = 15;
        paragraph.ListFormat.ListLevel.TabPosition = 10;
        paragraph.ListFormat.ListLevel.Font.Color = Color.Blue;
        paragraph.ListFormat.ListLevel.Font.Size = 12;
        paragraph.ListFormat.ListLevel.Font.Name = "Wingdings 2";
        // If paragraph is an item of bulleted list, we should specify bullet style square.
        paragraph.ListFormat.ListLevel.NumberFormat = "\x00A1";
        return ReplaceAction.Replace;
    }
}

Best regards,

Hi Andrey,
I think that our client will be happy about your workaround!! It seems to work well
Thanks a lot!!!
Steeve

Hi Andrey,
I have problem with bullets. For performance, we decided to save on disk a part of the document, the document settings (margin / format / orientation / etc.) and the text. But, with the suggested solution, when I open then document, I’m not able to change the color.
So, how can I change the color of the bullet in an existing document?? The bullets are create with the above suggestion…
Thanks a lot
Steeve

Hello Steeve,
Thanks for your request. I think, in this case, you should use the code like the following:

Document doc = new Document("C:\\Temp\\in.docx");
// Loop through all paragraph
foreach(Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))
{
    // Check if paragrapf is item of a list
    if (paragraph.IsListItem)
    {
        paragraph.ListFormat.ListLevel.Font.Color = Color.Red;
    }
}
doc.Save("C:\\Temp\\out.docx");

Best regards,

Hi Andrey,
It works well !! Thanks again and have a good day!!!
Steeve