Docx: Saving hyperlinks using <w:hyperlink> instead of using complex fields?

Hello,
I use Aspose Words (Java) to support .docx format in my app by converting RTF files to .docx. For one use-case, these .docx files get sent to a third-party app that reads them and converts them for ebook and print book formats. This third-party app, however, only recognises hyperlinks that are formatted using <w:hyperlink>, as per the OOXML docs here:
http://officeopenxml.com/WPhyperlink.php
The trouble is that it seems Aspose doesn’t export hyperlinks that way, but instead uses fields - this method:
http://officeopenxml.com/WPfields.php
This means the third-party app we sometimes work with does not read the links in a .docx file generated by Aspose. While this is obviously a limitation of the third-party app, given that we don’t have any control over that, I was wondering if there is any way to tell Aspose to use the <w:hyperlink> method for links? That is, either through some save option that I’ve missed, or by formatting the RTF in such a way that Aspose will use this method.
Is there any way of achieving this, or any plans to update Aspose to use the <w:hyperlink> method (assuming that is the newer method)? I’ve tried changing the compatibility options to Word 2016 and Strict, but nothing has helped.
Many thanks,
Keith

@kayembi,

Thanks for your inquiry. Please ZIP and attach your input and expected output Word documents here for testing. We will investigate the issue on our side and provide you more information.

Hi Tahir,

Many thanks for the reply. I have attached three example files (zipped):

  • Link-Source-RTF.rtf is the source RTF document.
  • Link-Aspose-DOCX.docx is the result of using Aspose to convert Link-Source-RTF.rtf to .docx format.
  • Link-Word-DOCX is a .docx file created and saved in the latest version of Word for macOS.

All three files contain only the text “This is a hyperlink.”, with “hyperlink” linked to our website.

The Aspose-generated .docx file results in the hyperlink being generated in the /word/document.xml file like this (I’ve simplified the XML here slightly so that it’s easier to see what’s going on):

<w:p>
	<w:r>
		<w:t>This is a </w:t>
	</w:r>
	<w:r>
		<w:fldChar w:fldCharType="begin" />
	</w:r>
	<w:r>
		<w:instrText>HYPERLINK "http://www.literatureandlatte.com"</w:instrText>
	</w:r>
	<w:r>
		<w:fldChar w:fldCharType="separate" />
	</w:r>
	<w:r>
		<w:t>hyperlink</w:t>
	</w:r>
	<w:r>
		<w:fldChar w:fldCharType="end" />
	</w:r>
	<w:r>
		<w:t>.</w:t>
	</w:r>
</w:p>

The Word-generated .docx file, by contrast, uses <w:hyperlink> and in the .rels file to create the link, as follows:

In /word/document.xml:

<w:p>
	<w:r>
		<w:t>This is a </w:t>
	</w:r>
	<w:hyperlink r:id="rId4" w:history="1">
		<w:r>
			<w:t>hyperlink</w:t>
		</w:r>
	</w:hyperlink>
	<w:r>
		<w:t>.</w:t>
	</w:r>
</w:p>

Then, in /word/_rel/document.xml.rels:

<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="http://www.literatureandlatte.com/" TargetMode="External"/>

For our links to work in the third-party app that many of our users use, we need to be able to create links using the <w:hyperlink> method rather than using fields.

Obviously the original RTF file uses fields for hyperlinks, but that’s because (to the best of my knowledge) there is no other way of generating hyperlinks in RTF.

Many thanks,
Keith

Link-Examples.zip (20.4 KB)

@kayembi,

Thanks for sharing the detail. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-16965 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Thanks for the reply. In doing some more research on this, I just came across this:

https://forum.aspose.com/t/problem-converting-hyperlinks-to-docx-format/110744

Given that someone was asking about this ten years ago, I’m guessing it’s not a high priority. :slight_smile: I’ll take it up with the third-party app developers in the meantime.

All the best,
Keith

@kayembi,

Thanks for your inquiry. There was no issue logged for the shared thread. We will inform you via this forum thread once there is any update available on this issue.

any progress so far?

This is actually no longer an issue for us, because after we contacted the developers of the third-party app we support, they updated the app to support both types of links.

All the best,
Keith

@kayembi,

Thanks for your inquiry. We have a good news for you that is WORDSNET-16965 has now been resolved and its fix will be included in the next version of Aspose.Words i.e. 18.7. Hopefully, this release is available at the end of this week.

Great, thank you for adding this!

The issues you have found earlier (filed as WORDSNET-16965) have been fixed in this Aspose.Words for .NET 18.7 update and this Aspose.Words for Java 18.7 update.