When you are viewing a PDF file, you may well notice that (like a web page) there are blue clickable links. These are defined in 2 ways:-
Viewer generated links
Several PDF Viewers will spot that the text on the page is a link. For example is starts http:// or www. and add a link. This is something each Viewer does on an adhoc basis and this data is not in the PDF file. It can be a bit hit and miss, especially with multiline values.
The PDF File can contain actual links. These are not stored in the text but are Annotations. They are stored as separate objects in a PDF file and drawn by the PDF viewer.
Every PDF page has a possible list of annotation objects on that page (if there are no annotations are present there will be no value). Annotations objects allow PDF files to contain animations and interactions. There are stored separately from the page text and drawn on by the PDF renderer.
There are several types of Annotation object. The one we are interested in is the Annot values with /Subtype of link. Here is what the raw data might look like.
23 0 obj<<
/Rect[60.72 684 86.88 696]
The values we are interested in are:-
/Subtype value which tells us it is a link (it could be a video, a sound, a form, a popup note or lots of other cool features)
/Rect value (which is the PDF coordinates of a rectangle which is the link). If you click on this area, the link will activate
/A value (this is the action value which tells us what to do. In this case we have a URL which we open in a browser
These are easy to extract from the Annot object. This is a feature offered by our JPedal PDF software.
As mentioned earlier, the text is stored separately so we need to decode the page and extract the text from the area of the page. Because of the way PDF works, you cannot be sure what is at any page location unless you parse the whole page.
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Find out more about our software for Developers
|Convert PDF to HTML5 or SVG|
|Convert AcroForms and XFA to HTML5|
|Java PDF SDK for working with PDF files|