Free Support Forum - aspose.com

Alternative Text

With Aspose.Slides, you can get/set the alternative text for shapes. Is it possible to do the same thing in Aspose.Words? Also, what type of node is a Drawing Canvas? Is it a shape or inline shape or something else?

Geting/setting alternative text for shapes is not supported in our current API.

Drawing canvas is actually a field { SHAPE \* MERGEFORMAT }, which contains all other shapes that are drawn on it. You can see it by pressing ALT-F9 in MS Word or using our DocumentExplorer source code demo, which can be located in C:\Program Files\Aspose\Aspose.Words\Demos\DocumentExplorer after Aspose.Words installation.

Can you suggest a way to "tag" a picture? I don't need to set the tag in code, but I just need to retrieve it. For example, if a document has 4 pictures, I need to find a specific picture by some sort of tag/name/id that a client can set when creating the document.

I have logged 'setting alternative text for shapes' to our defect base as a feature request (issue #1081). We will try to add this ability in one of our future versions.

Meanwhile, you can use bookmarks to 'tag' the pictures. Here is a samle code on how to get a hold of a shape marked with a bookmark:

// set document path

string filename = Application.StartupPath + "\\doc1.doc";

// load document

Document doc = new Document(filename);

// create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder(doc);

// use builder to move to bookmark with predefined name, e.g. "pic1"

builder.MoveToBookmark("pic1");

// Get all shapes in the bookmark area

NodeCollection shapes = builder.CurrentParagraph.GetChildNodes(NodeType.Shape, true);

// get all inline shapes in a bookmark area

NodeCollection inlineShapes = builder.CurrentParagraph.GetChildNodes(NodeType.InlineShape, true);

// manipulate shapes, using Image property or other properties of Shape class.

// ...

We have added ShapeBase.AlternativeText property in the recently published Aspose.Words 4.0 which lets you to set alternative text for shapes.