Any way to set a DocumentBuilder.InsertHyperlink to have a target (ie - open in new window)

In our code, we have a couple of uses of InsertHTML and InsertHyperlink.
I would like to make links open themselves in a new window. This is easy to do in InsertHTML, I can just add the target=_blank in the HTML. But with hyperlink, it doesn’t look like target is an option.
I wanted to check to see if I was missing anything before converting these InsertHyperlinks into InsertHTML to make a new target.

Hi John,
Thanks for your inquiry.
You’re correct, there is there no way to insert switches using the InsertHyperlink method right now. I have logged this request and it should be included with the new version of the Field API.
In the mean time I suggest you use the InsertHTML method for all links like that.
Thanks,

I was going through my code and reaslized why many of these had been moved to InsertHyperlink vs InsertHtml.
When using InsertHTML, even if I change the DocumentBuilder’s color and/or include a in the InsertHTML, when it generates a word document, it doesn’t color the text. I need to color this to classify a few things. I think when it saves as HTML though, it does save correctly.
This changed a while back, somewhere between versions 6 and 8.
Is there any way around this?

Hi Jon,
Thanks for your request. Starting from 9.5.0 version, behavior of InsertHtml was changed. Now formatting that you set before inserting HTML has no effect on the content inserted using InsertHtml. So you must specify all formatting in the HTML string you insert. For instance font color and size should be specified on SPAN level.
Please feel free to ask in case of any issues we will be glad to assist you.
Best regards,

We are using 9.1. We didn’t want to go further than that right now, because we rely hevily on Mail Merge (thats most of what we do with Aspose.Words) - and that changed in 9.2.
I am trying using font or span - both which still don’t display correctly in the word document. I can test again - but pretty sure it does display correctly in HTML.
In 9.1 - how can I format the link font (mainly color) in word?

Hi Jonathan,
Thanks for your inquiry.
You can try using the technique provided in this thread here to use DocumentBuilder formatting on inserted HTML content.
Thanks,

Reusing the NodeChangingCallback? How do I use this to only affect one peice of text?

Hi Jonathan,
Thanks for this additional information. Could you please clarify what you mean? It seems originally you wanted to use switches in your hyperlink to have them open in a new window so inserted them using DocumentBuilder InsertHtml instead of InsertHyperlink.
Then it appeared the change in functionality of the InsertHtml not using any formatting from the DocumentBuilder anymore was causing you trouble so I suggested to use the call to InsertHtmlWithBuilderFormatting in the code in the other thread instead. You only need to call this method when inserting content using DocumentBuilder.
Thanks,

Correct, my current issue is allowing formatting when using InsertHTML. The anchor link confused me not knowing which part of the thread I was actually supposed to use code from :).
Will try out this InsertHTMLWithBuilderFormatting code.

When I add this in and then try to call it I get an error " The type or namespace name ‘INodeChangingCallback’ could not be found (are you missing a using directive or an assembly reference?) ".
I am using 9.1 - and as I mentioned before, can’t move to 9.2 just yet. I already have a ‘using Aspose.Words’ in this class.

Hi Jon,

Thanks for your request. In 9.1.0 version you should use Document.NodeInserting event handler instead of INodeChangingCallback. This event handler do exactly the same as callback.
Best regards,

I have found the NodeInserting handler, but unsure on how to replace the class in there as well.
For example, in the InsertHTMLWithBuilderFormating method, around lines 14-20, I am assuming I change doc.NodeChangingCallback to doc.NodeInserting += new NodeChangedEventHandler(doc_NodeInserting).
On line 57 is the start of another class, but unsure what HandleNodeChanging should be extending. Currently it is public class HandleNodeChanging : INodeChangingCallback.
Also, with the nodes ArrayList, how does this get used in not using the callbacks?

Hi Jonathan,
Thanks for your inquiry.
Please try replacing the NodeChangingCallback code with this code below which will work in the older versions.

// Stores nodes inserted during the InsertHtml call.
doc.NodeInserted += new NodeChangedEventHandler(HandleNodeInserted);

// Insert HTML.
mBuilder.InsertHtml(html);
// Remove handler
doc.NodeInserted -= new NodeChangedEventHandler(HandleNodeInserted);
public static void HandleNodeInserted(object sender, NodeChangedEventArgs e)
{
    if (e.Node.NodeType == NodeType.Run)
        mRuns.Add(e.Node);
}

Thanks,

Thank you for the code example.
This colored the text and created the links.
The only problem, is that instead of inserting them at the Merge Field they were supposed to be at, they were all inserted at the top of the document. Does this make sense?

Hi Jon,
Thanks for your request. This can occur if you do not move DocumentBuilder cursor to the mergefield before inserting HTML. Please make sure you move cursor before inserting HTML. If the problem still occurs, please share your code and template here for testing.
Best regards,

Hi Jonathan,
Thanks for your inquiry.
Alexey is correct, this was just a small bug which I have fixed now.
Thanks,

This worked great. Thank you.

The issues you have found earlier (filed as WORDSNET-4321) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(10)