Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find all links in a PDF file, along with the page they're on and their X/Y position. Is there any tool or combination of tools I can use to do that?

share|improve this question
Perl with PDF::API2, maybe, but it doesn't look so easy. – Gilles Oct 10 '11 at 22:32

I haven't heard of a single tool that could tell you the coordinates of some text or link in a pdf file. It is even a bit hard to imagine, how this might be done reliably - I guess the tool would have to either calculate the geometry of all the text in the document (probably a modification of some standard pdf rendering library like poppler would be necessary for that) or otherwise base its estimation on some X-automation tool working on top of a pdf viewer.

What you can do without too much effort is grep for links in a non-encrypted and uncompressed pdf file. Here are some example grep searches you can use:

grep -ao "http://[[:print:]]*" TheFile.pdf

grep -ao "http://[[:alnum:]./]*" TheFile.pdf

grep -ao "http://[^ ']*" TheFile.pdf

grep -ao "URI(http://.*[^\])" TheFile.pdf

The last one should be the closest to what links can be found while reading though the file. Still, you'd probably have to work a bit on those regexes to extract the links you really want from a certain document.

If the document is packed or encrypted, you'd have to extract a plain version from it first. Use pdftk or similar tool to do that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.