Q: We have not been able to get PDFViewCtrl.getLinkAt(x,y) to work in our attempts. The code is as follows:
before setDoc(…):
/*
- Enables URL extraction
*/
mPDFView.setUrlExtraction(true);
within the event handler:
int x = (int)(event.getX() + 0.5);
int y = (int)(event.getY() + 0.5);
// Handle link click if one occured.
LinkInfo linkInfo = mPDFView.getLinkAt(x, y);
if ( linkInfo != null) {
String url = linkInfo.getURL();
…
linkInfo is always null, yet the viewer follows the link as expected. The text link is something like “pdftron.com”.
A: The getLinkAt() method does not recognize a pattern such as foo.com (i.e., it expects “www” or “http://” in front). In your case this is why the linkInfo object is null.
It is always a good practice to check for both link info and a link annotation in this use case. For example, in your handler you can check for link info (as above) and something in these lines:
`
// Handle link click if one occured.
Annot annotation = mPDFView.getAnnotationAt(x, y);
if (annotation != null) {
try {
if (annotation.getType() == Annot.e_Link) {
pdftron.PDF.Annots.Link link = new pdftron.PDF.Annots.Link(annotation);
Action action = link.getAction();
if (action.isValid()) {
if (action.getType() == Action.e_URI) {
String uri = action.getSDFObj().get(“URI”).value().getAsPDFText();
System.out.println(" Links to: " + uri);
}
}
}
} catch (PDFNetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
`