Free Support Forum - aspose.com

[Java][Word] FieldHyperlink - Hyperlink reference not valid

Code:

FieldHyperlink field = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, true);
String getMyDir =  "C:\\Users\\admin\\Desktop\\";
field = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, true);
field.setAddress(getMyDir + "Screenshot_2.png");
field.setScreenTip("Open " + field.getAddress());
// field.setTarget("iframe_3");
field.setOpenInNewWindow(true);
field.isImageMap(false);
field.update();

builder.getDocument().updateFields();

And as a result, I get : (I create 2 the same links)

aspose_2.png (18.8 KB)
After when I pres F9 in MsWord I get correct text which present location to file instead reference not valid…
aspose_1.png (10.2 KB)
Aspose version 21.5

@aolo23

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

full example

    private static void hyperlinks() throws Exception {
        Document doc = new Document();
        License lic = new License();
        lic.setLicense(System.getProperty("user.dir")+"/src/main/resources/Aspose.Words.Java.lic");

        doc.removeAllChildren();
        Section section = new Section(doc);
        doc.appendChild(section);
        DocumentBuilder builder = new DocumentBuilder(doc);

        Shape box = new Shape(doc, ShapeType.TEXT_BOX);
        box.setWidth(153);
        box.setHeight(150.0);
        box.setWrapType(WrapType.NONE);
        box.setTop(200);
        box.setLeft(100);
        box.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        box.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        box.appendChild(new Paragraph(builder.getDocument()));
        builder.insertNode(box);

        FieldHyperlink field = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, true);
        String getMyDir =  "C:\\Users\\admin\\Desktop\\";
        field.setAddress(getMyDir + "Screenshot_2.png");
        field.setScreenTip("Open " + field.getAddress());
        field.setOpenInNewWindow(true);
        field.isImageMap(false);
        field.update();

        builder.getDocument().updateFields();

        builder.moveTo(box.getLastParagraph());
        FieldHyperlink field2 = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, true);
        field2.setAddress(getMyDir + "Screenshot_2.png");
        field2.setScreenTip("Open " + field.getAddress());
        field2.setOpenInNewWindow(true);
        field2.isImageMap(false);
        field2.update();

        OoxmlSaveOptions options = new OoxmlSaveOptions();
        options.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
        builder.getDocument()
                .save(System.getProperty("user.dir") + File.separator + "hiperlinks_test_"+System.currentTimeMillis()+".docx", options);
    }

Current state:
In the out doc document, as a result, we can see the text Error! Hyperlink reference not valid but it still works, which mean when we press CTRL + click on this text it will open the target image.

Fix in MsWord:
After pres F9 text Error! Hyperlink reference not valid is changing into the directory of file (as it was set in code)

Expectation
The text should show tooltip correctly without additional refreshing ms word

@aolo23

We have tested the scenario and 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 WORDSNET-22360. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.