Hi,
Could any body help in changing the color of a hyperlink?
May I know whether a hyperlink attribute/property can be manipulated so that it will have a custom color after the click?
Thanks
Hi Spoorthy,
Thanks for your inquiry. To change the appearance of hyperlinks, you should change the Hyperlink style.
To change the appearance of followed hyperlinks (followed hyperlink: A hyperlink to a destination you have visited. Once you follow a hyperlink to its destination, the hyperlink changes color.), you should modify FollowedHyperlink style.
Please see StyleIdentifier.HYPERLINK and StyleIdentifier.FOLLOWED_HYPERLINK:
https://reference.aspose.com/words/java/com.aspose.words/styleidentifier/
Please let me know if you need more assistance, I will be glad to help you.
Best regards,
Setting of style identifier takes only an int argument. How custom color can be set to a hyperlink?
Dear Spoorthy,
To set custom color of hyperlink you can use the following technique:
// Get style for hyperlink and for followed hyperlink
Style followedhyperlinkStyle = doc.getStyles().getByStyleIdentifier(StyleIdentifier.FOLLOWED_HYPERLINK);
Style hypelinkStyle = doc.getStyles().getByStyleIdentifier(StyleIdentifier.HYPERLINK);
// Change color of hyperlink and followed hyperlink
hypelinkStyle.getFont().setColor(Color.ORANGE);
followedhyperlinkStyle.getFont().setColor(Color.GREEN);
// For testing purposes insert a hyperlink into the document
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertParagraph();
builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
builder.insertHyperlink("aspose.com", "https://www.aspose.com/", false);
Let s know if you have any concerns.