We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Open hyperlink in generated PDF document in a new window (when opened in an iframe)

I am using the Java Aspose-library to convert Word-documents to PDF-documents. In the Word-document the hyperlinks are configured to open in a new window (ALT-F9 shows the fieldcode), which gives something like:

HYPERLINK "http://www.domain.tld" \t "_blank"

The official Microsoft documentation tells me that this is the way to make a hyperlink open in a new window.

By default the Aspose-library doesn’t seem to keep the state of the hyperlinks (open in a new window) when generating a PDF-document.

I used code found in the Aspose documentation to modify hyperlinks: https://docs.aspose.com/words/net/working-with-fields/ to be sure that the fieldcode is like stated by the official Microsoft documentation.

However, when I open the PDF inside an iframe of my browser and I click on the hyperlink, it opens in the same frame, instead of opening in a new window.

Question: is it possible to generate hyperlinks in a PDF - the PDF will be opened in an iframe - to always open in a new window? Or is this a security issue of the Adobe PDF Reader plugin for browsers?

Hi Amar,

Thanks for your inquiry. I have attached a sample document here for your reference that simulates the exact structure of the HYPERLINK field as you described. I then rendered this document to PDF format using Aspose.Words v11.7.0 on my side (please see out.pdf). When you click on the link in PDF, it opens up a new browser window as expected. Could you please download the latest version of Aspose.Words from the following link and let us know how it goes?


Secondly, Adobe PDF readers do warn about such Security Warnings when you try to open a link from inside PDF documents. In case you trust the website specified by the HYPERLINK, simply choose the ‘Allow’ option available in the warning message.

Moreover, you can check in the DocumentExplorer that the field code in HYPERLINK field is preserved:

Best Regards,

Thank you for your comment.

I downloaded your attached out.pdf file and tried to embed the PDF file in an iframe and opened it in my browser, Firefox with Adobe Acrobat Reader as PDF-viewer plugin. The PDF-file is shown inside the iframe and I can click on the hyperlink shown in the PDF, but the hyperlink still opens in the current window. While I’d like it to open in a “_blank” target (new window/tab).

My HTML test file contains the following code and your attached out.pdf file:

Concerning the code I use to change the hyperlinks, I used the code example from this page and I modified the Hyperlink class method updateFieldCode():

fieldCode.setText(java.text.MessageFormat.format("HYPERLINK "{0}" \t "_blank"", mTarget));

This will generate a hyperlink with the following layout:

HYPERLINK "http://www.mydomain.tld" \t "_blank"

But I am not sure if this is picked up by Aspose when converting to PDF or that the target attribute is thrown away in the final PDF file. The main problem is still that I cannot open a hyperlink in a PDF from within an iframe and hope that it will open the hyperlink in a new window.

Hi Amar,

Thanks for the additional information.

Yes, Aspose.Words preserves all bits of HYPERLINK field during converting to PDF. You can confirm this by converting your Word document to PDF format by using Microsoft Word itself and then you’ll see that the behaviour of iframe is the same even with the output PDF produced by Ms Word. I am not sure how it is related to Aspose.Words; could you please follow up this guy here and see if he managed to achieve the same thing?

If we can help you with anything else, please feel free to ask.

Best Regards,

Hello Awais,

I created a hyperlink in an empty Word-document which should open in a new window when clicked on. Then I saved the document from within Word as a PDF-file. I then opened the saved PDF-file from within an iframe and tried clicking on the hyperlink in the hope it would open up in a new window. Still this doesn’t work, it keeps opening the hyperlink in the same iframe. I also took a look at the guy/forum link you refered to, it looks as the same issue I want to solve, but there are no solutions given in his thread.

Do you have any other suggestions? Or do you know if it is possible to put some sort of JavaScript behind every link, so that it opens up in a new window? It seems that is is possible to create hyperlinks which always open in a new window. I tried a tool from this guy and when I put the generated PDF file in an iframe and click on a hyperlink in the PDF document, it opens up in a new window.

Summary: could Aspose provide code to change hyperlinks in a document to a JavaScript-link? Something to do with app.launchUrl(www.domain.tld,true)?


Thanks for your inquiry. I am afraid, Aspose.Words does not deal with Javascript and no Javascript is read or written during open and save. Please let me know if I can be of any further assistance.

Best Regards,

Hi Amar,

Just to let you know, while working on a similar request we have found a way to export hyperlinks to PDF so they retain the behavior of opening in a new window. I have linked this thread to the appropriate issue so you will receive notification when this feature is implemented and released (this will be near the end of the month).

Please let me know if I can help with anything else.


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

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

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan