Insert a radio button in a Word document

Hello Andrey,

I’ve read that with Aspose.Words for .Net it’s impossible to insert a radio button in a Word document because it’s an ActiveX control.

Has this feature now been integrated into your new version?

Is there a function that allows you to replace text with an image?

Thank you very much for your help.

Best regards,

Aziz

@AzizDIOP Unfortunatly, you still can’t insert radio buttons using Aspose.Words.

To replace text with an image you can use following code:

Document doc = new Document("input.docx");
byte[] image = File.ReadAllBytes("input.png");

ReplaceWithImageHandler handler = new ReplaceWithImageHandler(image);
FindReplaceOptions options = new FindReplaceOptions()
{
    ReplacingCallback = handler,
    Direction = FindReplaceDirection.Backward,
};

doc.Range.Replace("Hello", string.Empty, options);
doc.Save("output.docx");

public class ReplaceWithImageHandler : IReplacingCallback
{
    private readonly byte[] _image;

    public ReplaceWithImageHandler(byte[] image)
    {
        _image = image;
    }

    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args)
    {
        DocumentBuilder builder = new DocumentBuilder((Document)args.MatchNode.Document);
        builder.MoveTo((Run)args.MatchNode);
        builder.InsertImage(_image);

        return ReplaceAction.Replace;
    }
}

Also, please check Find and Replace in C#|Aspose.Words for .NET

Thank you
Aziz

1 Like