HTML Hyperlink Anchor in Hidden Content is not Clickable when Inserting in Word Document using Aspose.Words for Java

While passing Content Data into the Word file using Java, post Aspose generation of the word file, the content that is hidden does not have Hyperlinks applied to them.

Code Snippet :

else if(TYPE_RATIONALE.equalsIgnoreCase(strExpandObjType))
{
	if("internal".equals(strPurpose))
		{	
				mapParagraph = mapData;
				strContentData = (String)mapParagraph.get(SELECT_ATTRIBUTE_CONTENT_DATA);
						
			if(UIUtil.isNotNullAndNotEmpty(strContentData) && !strContentData.isEmpty() && !"<p>&nbsp;</p>".equalsIgnoreCase(strContentData))	
						{
							strContentData = strContentData.replace("<br><br>","<pre style='margin-bottom:-5pt;'>&nbsp;</pre>");
							strContentData = strContentData.replace("<br>","<pre></pre>");
							strContentData = "<style>div> :first-child {display: inline}</style><div hidden style='border-style: solid;border-width: 1px;font-family:Times New Roman;font-size:11.0pt;font-weight:bold;' class='EM Rationale'>RATIONALE: "+strContentData+"</div>";
							
							
							if(!stdUsgNotesObjIds.contains(strExpandObjId))
							{
								builder.insertHtml(strContentData);
							}
							
							if(EMBodyTextStyle!=null)
							builder.getParagraphFormat().setStyle(EMBodyTextStyle);
						}
						}

So the “hidden” attribute in the div causes the rational to be hidden in the word file, the content data is getting added with no issues, but the hyperlinks are not clickable (Refer screenshot below)
asposeword.PNG (183.3 KB)

Is there a styling error? or is there some way we can get the hyperlink to get updating correctly?

@bekal94,

Please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • A simplified HTML string that you are inserting in Word document (copy it in .txt or .html file and share the file)
  • Aspose.Words for Java 20.12 generated output DOCX file showing the undesired behavior.
  • Please also create a standalone simple Java application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start further investigation into your particular scenario/issue and provide you more information.

Hi Awais,

The information you have requested has been attached,
• Your simplified input Word document - There is no input word document, we are generating it from the tool. So I have attached a video for your understanding.

  • Please also create a standalone simple Java application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words JAR files in it to reduce the file size. – Since the source code is confidential information, I will have to try to get a customized Jar for your testing, I am still working on that.

Meanwhile please check the above and let me know if anything else is required.Information.zip (8.2 MB)

@bekal94,

I have managed to locate and observe the issues in the output DOCX files that you shared. You are right, the hidden blue text contents in these output documents are not rendering as Hyperlink fields. But, after an initial test with the licensed latest (20.12) version of Aspose.Words for Java, I was unable to reproduce this issue on my end. I used the following simple Java code to convert your HTML to DOCX format on my end:

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

String data = new String(Files.readAllBytes(Paths.get("C:\\Temp\\Information (1)\\Test.html")));
builder.insertHtml(data);

doc.save("C:\\temp\\Information (1)\\awjava-20.12.docx");

Can you please provide simplified but complete Java source code without compilation errors that helps us to reproduce this problem on our end?

Awais,
Information_Repo.zip (6.3 KB)
Sorry my bad, the HTML did not have the hidden attribute, that is why it worked.
Sharing the code and the Reproduced Document for reference.

The link is hidden so you will have to click on Show/Hide option in Word.
Thanks

@bekal94,

We have logged this problem in our issue tracking system with ID WORDSNET-21612. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Thank you for your quick reply…

Hi Awais,
Any update on the issue ID WORDSNET-21612?

@bekal94,

WORDSNET-21612 is currently pending for analysis and is in the queue. We will inform you via this forum thread as soon as this issue will get resolved in future. We apologize for any inconvenience.

Hi Awais, the WORDSNET-21612 status says that the Analysis is complete. Is there any update on the same?

@bekal94,

Unfortunately, your issue is not resolved yet; but yes, we have completed the analysis of this issue and the root cause has been identified. Currently, Aspose.Words handles anchors if element is visible and discards when it is not. We will change this behavior and write Hyperlink for hidden references (and mimic MS Word’s logic). We will inform you via this forum thread as soon as this issue will get resolved in future and apologize for any inconvenience.

2 posts were split to a new topic: HTML to Word DOCX | Visibility of Hidden Numbered and Bullet Lists | Java

Hi Awais,

I see the status of the WORDSNET-21612 is closed… Can I know what is the fix that is applied so that I can update here as well?

@bekal94,

Your issue WORDSNET-21612 has now been resolved and the fix of this issue will be included in 21.5 version of Aspose.Words for Java. We will notify you here as soon as 21.5 version will be released at the start of May 2021.

Hi Awais,
Any update on the release of this completed issue? Please do let me know when it becomes available.

Thanks

@bekal94,

I am afraid, the 21.5 release of Aspose.Words for Java is not published yet. We will notify you here as soon as we publish the next Aspose.Words for Java 21.5 release in next few days.

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

HI Awais,
Thank you for resolving the issue, we were able to use the jar for testing and it has fixed the hyperlink issue,
However when deploying in our QA environment we have encountered an issue where the jar is incompatible, possibly because we are using Oracle JAVA 8-181u in the QA and PROD servers.
Is it possible to provide the same jar by compiling using JAVA 8?
We also have a plan to upgrade to Adopt OpenJDK 281u later this year, So is it compatible with that as well?
Thanks in advance.

@bekal94,

You can use the regular JAR from the latest (21.5) version of Aspose.Words for Java package. It should work in your current (and future OpenJDK 281u) environments. However, we currently do not provide a JAR which is specially compiled for OpenJDK 281u.

At the moment, we only ship two types of packages:

  1. A regular Aspose.Words for Java 21.5 package that supports the following Java versions:
  • J2SE 7.0 (1.7)
  • J2SE 8.0 (1.8)
  • or above (for example Java 10)
  1. Aspose.Words for Java 21.5 (JDK1.6 only) package that is specially compiled for JDK1.6. You can choose this if you are using Aspose.Words for Java on an old Java 6 environment.

For any more details, please refer to following section of documentation:

Hi Awais,

  1. A regular Aspose.Words for Java 21.5 package that supports the following Java versions:
  • J2SE 7.0 (1.7)
  • J2SE 8.0 (1.8) - we are currently using this version (Adopt Open JDK 8 282u)
  • or above (for example Java 10)

But on the Acceptance environment we see that this jar is not compatible. Please let me know if you have a jar that is complied in Java 8 (Adopt OpenJDK - 8 282u)