Update existing LinkAnnotation by Rectangle/ TextFragment Object

Dear Team,

We have purchased Aspose.Pdf for Java Site OEM license with Enterprise Support.
We have following issue with current version of API. Could you please help us to resolve these issues?

ISSUE:

How to verify there is already hyperlink existed in the current rectangle position / found TextFragment’s rect dimensions?
Is there any way to find the hyperlink present or not using the found TextFragment / Rectangle object? At present we are able to create a new LinkAnnotion, however our requirement is to update the existing LinkAnnotation. Could you please help us the right solution or with code snippet examples.

CODE SNIPPET:

// Get rectangular dimensions of TextFragment object
Rectangle rect = new Rectangle((float) textFragment.getPosition().getXIndent(), (float) textFragment.getPosition().getYIndent(), (float) textFragment.getPosition().getXIndent() + (float) textFragment.getRectangle().getWidth(), (float) textFragment.getPosition().getYIndent() + (float) textFragment.getRectangle().getHeight());

// Create LinkAnnotation object and specify rectangular region
LinkAnnotation link = new LinkAnnotation(textFragment.getPage(), rect);

// Set target file
link.setAction(new GoToRemoteAction(remotePDF, remotePageNumber));

// Add annotation to annotations collection of TextFragment
textFragment.getPage().getAnnotations().add(link);

Could you please let us know the right solution with example code snippets.
Highly appreciate for your support and resolution.

Thanks & Regards,
Radha Krishna Garnepudi

@grk_aspose

Thank you for contacting support.

You may verify existence of Hyperlink by checking AnnotationTypeof any annotation, because a hyperlink is different than simple TextFragment. Moreover, you may check for any hyperlink with gotoAction.getURI method and then update the link using gotoAction.setURI method. Below is a code snippet for your kind reference:

Document document = new Document(dataDir + "Annotation.pdf");
for (Page page : document.getPages()) 
{
    for (Object object : page.getAnnotations()) 
    {
        Annotation annotation = (Annotation) object;
        if(annotation.getAnnotationType() == AnnotationType.Link) 
        {
	LinkAnnotation linkAnnotation = (LinkAnnotation) annotation;                
	if(linkAnnotation.getAction() instanceof GoToURIAction) 
            {
                GoToURIAction gotoAction = (GoToURIAction) linkAnnotation.getAction();
                gotoAction.setURI("www.aspose.com");
	}				
        }
}
}
document.save(dataDir + "Test_18.11.pdf");

We hope this will be helpful. In case your requirements are different than suggested solution, please share source and expected PDF files so that we may investigate further to help you out.