The open Window of Links in Files

We want the links in files are will open in a new window a href="" target="_blank"

Hi there,

Thanks for your inquiry. Could you please share your input document and expected output document here for our reference? We will then provide you more information about your query along with code. It seems that you want to convert Word document into Html. Please confirm this.

Yes,when we convert doc or other office files to html,the links in this file will be converted to ,it will be opened in the same window.but we want to open this link in new window,like

Hi there,

Thanks for sharing the detail. Please use following code example to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
doc.updateFields();
for (Field field : doc.getRange().getFields())
{
    if (field.getType() == FieldType.FIELD_HYPERLINK)
    {
        builder.moveTo(field.getSeparator());
        builder.write("\\t _blank");
    }
}
doc.updateFields();
doc.save(MyDir + "Out.html");

It didn’t work well!!

public static void main(String[] args) throws Exception {
    License wordLicense = new License();
    wordLicense.setLicense(MainTest.class.getClassLoader()
            .getResourceAsStream(
                    "personal/lixp/test/aspose/Aspose.Total.Java.lic"));
    Document doc = new Document(FileDir.getDeskTop() + File.separator
            + "test.docx");
    DocumentBuilder docBuilder = new DocumentBuilder(doc);
    doc.updateFields();
    for (Field field : doc.getRange().getFields()) {
        if (field.getType() == FieldType.FIELD_HYPERLINK) {
            docBuilder.moveTo(field.getSeparator());
            docBuilder.write("\t *blank");
        }
    }
    doc.updateFields();
    HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
    saveOptions.setPrettyFormat(true);
    saveOptions.setExportEmbeddedCss(true);
    saveOptions.setExportEmbeddedFonts(true);
    saveOptions.setExportEmbeddedImages(true);
    saveOptions.setExportEmbeddedSvg(true);
    saveOptions.setWarningCallback(new com.aspose.words.IWarningCallback() {
        @Override
        public void warning(com.aspose.words.WarningInfo warningInfo) {
            System.out
                    .println(warningInfo.getWarningType() == com.aspose.words.WarningType.FONT_SUBSTITUTION ? ("Font substitution: " + warningInfo
                            .getDescription()) : "");
        }
    });
    int pageCount = doc.getPageCount();
    for (int i = 0; i < pageCount; i++) {
        saveOptions.setPageIndex(i);
        saveOptions.setPageCount(1);
        doc.save(new FileOutputStream(FileDir.getDeskTop() + File.separator
                + "test*" + (i + 1) + ".html"), saveOptions);
    }
}

Hi there,

Thanks for sharing the
detail. You are saving the document to HtmlFixed file format. In this case, Document.Save removes target="_blank" from output document. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-12449. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

How is this??

Hi there,

Thanks for your inquiry. We have verified the status of this issue from our issue tracking system and like to share with you that this issue has been planned for development. Hopefully, the fix of this issue will be available in February 2016 release. Please note that this estimate is not final at the moment. We will be sure to inform you via this forum thread as soon as this issue is resolved.

We appreciate your patience.

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

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

It didn’t work well.

when I check the a label,it is still like

but no target=“_blank”.
like below:

Hi there,

Thanks for your inquiry. Could you please attach your input Word document and output Html here for testing? We will investigate the issue on our side and provide you more information.

can you create a doc file with link in it?and convert it to HTML,you will find this problem!and why you notify us you have solved this problem???

Hi there,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-1357. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi there,

Thanks for your patience. In your document the target frame of hyperlink is set to none. Please check the attached image for detail. You need to set the target of hyperlink as shown below. Please upgrade to latest version of Aspose.Words for Java 16.3.0 and use following code example. We have closed WORDSJAVA-1357 as ‘Not a Bug’.

Document doc = new Document(MyDir + "link Test.docx");
for (Field field : doc.getRange().getFields())
{
    if (field.getType() == FieldType.FIELD_HYPERLINK)
    {
        FieldHyperlink hyperlink = (FieldHyperlink)field;
        hyperlink.setTarget("_blank");
    }
}
doc.save(MyDir + "OutJava.html", SaveFormat.HTML_FIXED);