We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating cross-references that are embedded in pictures


I’m trying to insert cross-references in a Word document by using the Java API. In order to do that I created a field with the DocumentBuilder: builder.insertField(“REF myAnchor \h”, “my reference”);
This works fine when the field value is a text (here “my reference”). However, I would like to know if it is also possible to create a cross-reference that is embedded in a picture (i.e. the picture has to refer to the anchor “myAnchor”)? In Word 2007 this is easy to do but how can I accomplish this programmatically with the Aspose Word API?

Thank you very much in advance for your help.

With best regards,


Thanks for your request. You can easily achieve this using Aspose.Words by setting HRef property of the shape:
Here is simple code example:

// Create document and DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert image, which will be a hyperlink.
Shape shape = builder.InsertImage(@"Common\test.jpg");
// We should set HRef property of shape to make it a hyperlink.
// HRef will be a bookmark in the document, which wil be inserted later.
string bookmarkName = "myBookmark";
shape.HRef = string.Format("#{0}", bookmarkName);
// Insert few page breaks and bookmark.
// Insert bookmark.
builder.Write("This is some text");
// Save output document.

Hope this helps.
Best regards.