How to list all hyperlink in Word document

If I have Docx file including a lot of hyperlink.
How to code to get all hyperlink, and change its url.
Thanks.

Hi Wuttipol,

Thanks for your inquiry. Please read following article about modifying hyperlink.
https://docs.aspose.com/words/java/update-field/

Please use Range.Fields property to get the Fields collection that represents all fields in the range. You can check hyperlink field by comparing field type with FieldType.FIELD_HYPERLINK.

Hope this helps you. Please let us know if you have any more queries.

Dear Tahir

Thank you so much for great advice.
Some is work, some is not.
I attached the file which is not be able to convert, Please kindly advise .

Hi Wuttipol,

Thanks for your inquiry. The hyperlink in the shared document is set to Shape node. You can check this by using Shape.HRef property. Please use the 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 + "Input.docx");
for (Shape shape : (Iterable)doc.getChildNodes(NodeType.SHAPE, true))
{
    if (shape.hasImage() && !shape.getHRef().equals(""))
    {
        System.out.println(shape.getHRef());
        shape.setHRef("http://google.com/");
    }
}
doc.save(MyDir + " Out.docx");

Dear Tahir

Thank you, let me try first, I will update you accordingly.

Hi, Tahir

I tested to our full document, it works.
It seems that there is the definition of element in Aspose paradigm. Could you please share us such document ? Thank you.

Hi Wuttipol,

Thanks for your inquiry. When Aspose.Words reads a Word document into memory, objects of different types are created to represent various document elements. Every run of text, paragraph, table, section is a node, and even the document itself is a node. Aspose.Words defines a class for every type of document node.

Please visit the following articles to learn about DOM structure of a document.
https://docs.aspose.com/words/java/aspose-words-document-object-model/
https://reference.aspose.com/words/java/com.aspose.words/Node
https://docs.aspose.com/words/java/navigation-with-cursor/

Hope this helps you. Please let us know if you have any more queries.

Dear Tahir

Thanks, It is great document. Let me digest all of them. Thank you.
Just the quick question, if I have images embedded inside docx file,
with Aspose.Words. Can I extract it and save to be another files as either jpeg,gif, bmp ?

Hi Wuttipol,

Thanks for your inquiry. Yes, you can export the shape (images) into Jpeg, Png, Bmp, tiff, emf. 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 + "Image.SampleImages.docx");
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.JPEG);
int imageIndex = 0;
for (Shape shape : (Iterable)shapes)
{
    if (shape.hasImage())
    {
        String imageFileName = MyDir + java.text.MessageFormat.format(
        "Image.ExportImages.{0} Out.jpg", imageIndex);
        shape.getShapeRenderer().save(imageFileName, imageOptions);
        imageIndex++;
    }
}

Dear Tahir

Thank you, so this mean we can save to any file extension as we want and the image quality/solution would be good as the saving format accordingly, Am I right ?

Hi Wuttipol,

Thanks for your inquiry. Please read about Aspose.Words save formats from here:
https://reference.aspose.com/words/java/com.aspose.words/SaveFormat

You can convert shape into Tiff, Png, Bmp, Emf or Jpeg file format. I suggest you please read about ImageSaveOptions class from here:
https://reference.aspose.com/words/java/com.aspose.words/ImageSaveOptions

Dear Tahir

Thank you so much for your promptly support.
Out team is under performing the evaluation and can see that almost feature is matching.
Let see how to user feedback to us.

Hi Wuttipol,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Dear Tahir

Thank you for always support.
Today, I got 1 challenge from the team. If we have the html file which have image link in tag , not sure how Aspose.Word convert it to be docx. They need to have the image embedded inside the file’s content not just create the link to remote server. Please kindly advise.

Hi Wuttipol,

Thanks for your inquiry. When html document is loaded into Aspose.Words DOM, the image from img tag is loaded into Shape node. When html is saved to Docx, this image is embedded in output document.

Please let us know if you have any more queries.

Hi Tahir

Thanks, I tried it, it is work.
Just the quick question, Do I need to add any special saveOption to keep the image quality/resolution ?
or Is there any saveOption which make such image’s quality/resolution better ?

Please kindly advise, thanks.

Hi Wuttipol,

Thanks for your inquiry.
No, there is no special save options. You simply load your html
document into Aspose.Words DOM and save it to Doc/Docx.

Please
note that Aspose.Words mimics the same behaviour as MS Word does. Its
mean that if you convert your input document to Doc/Docx using MS Word,
you will get the same output.