How to Get and Set Hyperlink Alt Text Programmatically in InDesign SDK
Hello everyone,
I'm working on a project using the InDesign SDK, and I need to programmatically get and set the alt text for hyperlinks. I found some interfaces like IHyperlinkCmdData and IHyperlinkTable, but I'm having trouble figuring out how to retrieve or modify the alt text for a specific hyperlink.
Does anyone have an example snippet or guidance on how to achieve this?
Here's what I've tried so far
int32 hyperlinkCountint = hyperlinkTable->GetHyperlinkCount();
UID hyperlinkUID = hyperlinkTable->GetNthHyperlinkSource(n); // n = 1
TI_CHECKED_NEW_CMD(myNewCmd, kNewHyperlinkCmdBoss);
// custom macro defintion below
#define TI_CHECKED_NEW_CMD(theVar, theCmdBoss) \
InterfacePtr<ICommand> theVar(CmdUtils::CreateCommand(theCmdBoss));\
if (theVar == nil) {\
break;\
}
TI_CHECKED_INTERFACE(IHyperlinkCmdData, myNewCmdData, myNewCmd, IID_IHYPERLINKCMDDATA);
// custom macro defintion below
#define TI_CHECKED_INTERFACE(theTypeSymbol, theVar, theBase, theInterface) \
InterfacePtr<theTypeSymbol> theVar(theBase, theInterface);\
if (theVar == nil) {\
break;\
}
InterfacePtr<IHyperlinkDestination> myDestination(db, hyperlinkUID,UseDefaultIID());
UIDRef myResult;
myResult = UIDRef(db, hyperlinkUID);
myNewCmdData->SetHyperlinkDestination(myResult);
PMString hyperlinkaltText = myNewCmdData->GetHyperlinkAltText();
My questions:
- How can I retrieve the alt text for a specific existing hyperlink?
- How can I set or update the alt text for that hyperlink?
If there's a better approach or additional steps I need to take, please let me know. A code snippet or reference would be greatly appreciated!
Thanks in advance for your help! 😊
