This sample demonstrates how to extract all links from a PDF file using link extraction settings.
Java
// Open the PDF using the Parser class
try (Parser parser = new Parser("input.docx"))
{
// Verify that hyperlink support is enabled for this document
if (!parser.getFeatures().isHyperlinks()) {
return;
}
// Apply options to filter links
PageAreaOptions options = new PageAreaOptions(new Rectangle(new Point(380, 90), new Size(150, 50)));
// Use the parser to get hyperlink data
Iterable<PageHyperlinkArea> hyperlinks = parser.getHyperlinks(options);
// Iterate through the links and handle them accordingly
for (PageHyperlinkArea h : hyperlinks) {
System.out.println(h.getText());
System.out.println(h.getUrl());
}
}