Hyperlinks Have Inconsistent Formatting

When applying hyperlinks to text in a word document, portions are not colored blue and underlined like the rest of the text.

It seems to be based on some hidden formatting of the underlying document. I've attached an example initial document and resulting document with hyperlinks inserted. The line marked fresh text results in a correctly styled hyperlink. The second example which was pasted from the user document has a malformed hyperlink style applied with part of the text still black with no underline.

The style issue is only present with the specific text pasted from a user document. I used design mode and the style viewer to attempt to view any hidden data applied to the text but I could not see any difference.

I was wondering if you could tell what about the problem text is causing aspose to fail to apply the hyperlink style consistently. I've pasted the code which is applying the hyperlink styles to the document and the example documents are attached.


Node start = match.get(0);
// Create an empty text hyperlink directly before the match
docBuilder.moveTo(start);
docBuilder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
Field hyperlink = docBuilder.insertField(String.format(LOCAL_HYPERLINK_CODE_FORMAT, linkDef.getBookmarkName(), "Appended Authority"), "");
// Field hyperlink = docBuilder.insertHyperlink("", linkDef.getBookmarkName(), true);
for (Node nd : match)
{
if (nd.getNodeType() == NodeType.RUN)
{
// ((Run) nd).getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
//More consistent to set each than use the StyleIdentifier
((Run) nd).getFont().setUnderline(Underline.SINGLE);
((Run) nd).getFont().setColor(Color.BLUE);
if (_highlightingUsed)
{
((Run) nd).getFont().setHighlightColor(Color.YELLOW);
}
}
start = nd;
}

// Move the link's end-marker to directly follow the end of the match
// so that the hyperlink contains the full matching text.
FieldEnd hyperlinkEnd = hyperlink.getEnd();
hyperlinkEnd.remove();
start.getParentNode().insertAfter(hyperlinkEnd, start);

Hi,

Thanks for your inquiry. The problem occurs because the Run of text “Residence Requirements” is contained inside a SmartTag node. Please try run the following code to learn how you can correct this behavior.

Document doc = new Document("C:\\Temp\\Bad+Hyperlink+Formatting+Output.doc");

SmartTag tag = (SmartTag) doc.getChildNodes(NodeType.SMART_TAG, true).get(0);
Run run = (Run) tag.getChildNodes(NodeType.RUN, true).get(0);
run.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);

doc.save("C:\\Temp\\out.doc");

Please let me know if I can be of any further assistance.

Best regards,