Click on "Alt+Left arrow", won't take me back to hyperlinked Image

Hi,
I am trying to add hyperlink to matched text and also add image and hyperlink to that image and the hyperlinked matched text and hyperlinked image looks like as shown in below screenshot. Both hyperlinked text and image should take me to same bookmark as it is referenced to same and this is working as expected.

Below 1st point working as expected and have issue with 2nd point.

  1. When I click on matched text it will take me to referenced bookmark and click on “Alt+Left arrow”, it takes me back to matched text.
  2. When I click on image it will take me to referenced bookmark but click on “Alt+Left arrow”, it won’t take me back to image.
// Create hyperlink for matched text and add bookmark reference to it
string hyperlinkFormat = "HYPERLINK \\l \"{0}\" \\o \"{1}\"";
string hyperlinkScreenTip = "Click to jump to Bookmark. Use Alt ← to return to matched text";
// Create field code
string hyperlinkFieldCode = string.Format(hyperlinkFormat, _bookmarkName, hyperlinkScreenTip);
builder.Font.Color = Color.Blue;
// Insert hyperlink
builder.InsertField(hyperlinkFieldCode, matchedText);

//Create jumplink image next to matched text and add bookmark reference to it
//jumplink image path
string imagePath = "Images/HeadnoteDown.png";
Shape shape = builder.InsertImage(imagePath);
shape.ScreenTip = hyperlinkScreenTip;
shape.HRef = string.Format("#{0}", _bookmarkName);

Please let me know what the issue and fix could be. Also let me know if we have any other approach to achieve this requirement.

Regards,
Chetan

@KCSR Unfortunately, I cannot reproduce the problem on my side. I have used the following simple code for testing:

string _bookmarkName = "test";

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create hyperlink for matched text and add bookmark reference to it
string hyperlinkFormat = "HYPERLINK \\l \"{0}\" \\o \"{1}\"";
string hyperlinkScreenTip = "Click to jump to Bookmark. Use Alt ← to return to matched text";
// Create field code
string hyperlinkFieldCode = string.Format(hyperlinkFormat, _bookmarkName, hyperlinkScreenTip);
builder.Font.Color = Color.Blue;
// Insert hyperlink
builder.InsertField(hyperlinkFieldCode, "This is hyperlink");

//Create jumplink image next to matched text and add bookmark reference to it
//jumplink image path
string imagePath = @"C:\Temp\test.png";
Shape shape = builder.InsertImage(imagePath);
shape.ScreenTip = hyperlinkScreenTip;
shape.HRef = string.Format("#{0}", _bookmarkName);

// Insert few page breaks and the bookmakrk.
builder.Writeln();
builder.InsertBreak(BreakType.PageBreak);
builder.InsertBreak(BreakType.PageBreak);
builder.InsertBreak(BreakType.PageBreak);
builder.StartBookmark(_bookmarkName);
builder.Write("This is bookmakr target");
builder.EndBookmark(_bookmarkName);

doc.Save(@"C:\Temp\out.docx");

Here is the generated document: out.docx (12.6 KB)
On my side both Ctrl+Click and Alt+Left Arrow works fine with both hyperlink and hyperlinked shape.

Hi Alexey,

Please take a look at the below steps to replicate this issue.

Regards,
Chetan

@KCSR Thank you for additional information. It is not Aspose.Words defect, this is MS Word peculiarity. I see exactly the same behavior when create test document in MS Word. It looks like in MS Word Alt+Left Arrow returns the cursor to the last location, but cursor is not moved when you Ctrl+Click on the image hyperlink. So the cursor is returned to it’s last position.

Hi Alexey, you are right. Is there any other options we can achieve this requirement? In Word Interop Dll we use to have different methods to achieve this Shapes, Range, etc.

Is possible to achieve my requirement using Shapes available in Aspose, I am fine to use any default shapes which matches near to the image that I have posted in my description.

Regards,
Chetan

@KCSR Unfortunately, Aspose.Words does not control the behavior of MS Word. Aspose.Words allows you to work with document object model, not with MS Word UI.
I am afraid, I do not see a way to achieve your requirements neither using Aspose.Words nor using MS Word.

Thanks Alexey, i had tried this and came to know it is possible though of checking in forum if we have any workaround. Thanks for trying this from your end.

Regards,
Chetan

1 Like

Alexey, i was just checking in Word document if we can have any workaround and I do see there is option to insert Symbols which will work link text and jumping to bookmark and from bookmark works perfectly fine with this. I have found some symbols near to the image that i have and will be suggesting to use any of these.

Symbol options is available here –

Could you please let me know if we can insert symbols, underline, bold it and also add bookmark reference to it using Aspose?

Regards,
Chetan

@KCSR You can insert a symbol the same way as a simple tex. For example:

builder.Font.Name = "Calibri";
builder.Font.Bold= true;
builder.Font.Underline = Underline.Thick;
builder.Write("\x2193");

Here is a full code example with hyperlink:

string _bookmarkName = "test";

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Create hyperlink for matched text and add bookmark reference to it
string hyperlinkFormat = "HYPERLINK \\l \"{0}\" \\o \"{1}\"";
string hyperlinkScreenTip = "Click to jump to Bookmark. Use Alt ← to return to matched text";
// Create field code
string hyperlinkFieldCode = string.Format(hyperlinkFormat, _bookmarkName, hyperlinkScreenTip);
builder.Font.Color = Color.Blue;
// Insert hyperlink
Field hyperlink = builder.InsertField(hyperlinkFieldCode, "This is hyperlink");

// Move builder inside the field value.
builder.MoveTo(hyperlink.End);
builder.Font.Name = "Calibri";
builder.Font.Bold= true;
builder.Font.Underline = Underline.Thick;
builder.Write("\x2193");

// Move builder outside the field value.
builder.MoveToDocumentEnd();

// Insert few page breaks and the bookmakrk.
builder.Writeln();
builder.InsertBreak(BreakType.PageBreak);
builder.InsertBreak(BreakType.PageBreak);
builder.InsertBreak(BreakType.PageBreak);
builder.StartBookmark(_bookmarkName);
builder.Write("This is bookmakr target");
builder.EndBookmark(_bookmarkName);

doc.Save(@"C:\Temp\out.docx");

out.docx (7.2 KB)

1 Like

Thanks dear, this should be very near to my image!

1 Like