4

I'm looking for a PDF viewer that provides a way to visualize named destinations. Named destinations are the formal name for what you might call anchors. Major browsers jump to the named destination foo when you follow a link to http://example.com/some.pdf#foo. Acrobat Reader, Xpdf, Evince and Okular can be instructed to jump to a named destination when opening the file.

How would you know the name to use (assuming there is one — many PDF-producing software don't include such names)?

I'm looking for a PDF viewer that provides a way to visualize named destinations in such a way that given a document with named destinations, you can browse to a place in the document and then reasonably easily find the closest preceding destination, so that you can link to http://example.com/some.pdf#foo rather than say “go to http://example.com/some.pdf and look at the bottom of page 4”. (I think major browsers understand http://example.com/some.pdf#page=4; this question is about using names — typically reminiscent of question names — rather than a page number.)

While I personally use Linux, I'd like reproducible advice, so an ideal solution would work all the major platforms that people typically have access to (Windows, Mac OS X and Linux). For widespread use, this would have to be cost-free.

• According to this thread, Acrobat Pro ($$$) has this feature but Acrobat Reader (free) can't do it.
• If you want a file to test with, try the hyperref manual which has named destinations like subsection.3.2 linking to §3.2.
• See also List named destinations in a PDF on Unix & Linux for a command line solution.

1 Answer 1

-1

I had the same question, and eventually found a great answer via How can I visually inspect the structure of a PDF to reverse engineer it?

The answer is to use the Python package pdfminer.six. It's even one of their examples in the documentation! Cut-and-paste this code into a terminal:

pip install pdfminer.six
cat >extract.py <<EOF
import sys
import pdfminer.pdfparser, pdfminer.pdfdocument
with open(sys.argv[1], "rb") as f:
  parser = pdfminer.pdfparser.PDFParser(f)
  document = pdfminer.pdfdocument.PDFDocument(parser)
  for (level, title, dest, a, se) in document.get_outlines():
    print('  ' * level, title, dest or a, se)
EOF
python extract.py myInputFile.pdf

On my particular PDF, the output looks like this:

$ python extract.py ~/Desktop/p2786r3.pdf | head
   Abstract {'S': /'GoTo', 'D': b'section.1'} None
   Revision History {'S': /'GoTo', 'D': b'section.2'} None
     R3: October 2023 (midterm mailing)r3-october-2023-midterm-mailing {'S': /'GoTo', 'D': b'section*.2'} None
     R2: June 2023 (Varna meeting)r2-june-2023-varna-meeting {'S': /'GoTo', 'D': b'section*.3'} None
     R1: May 2023 (pre-Varna mailing)r1-may-2023-pre-varna-mailing {'S': /'GoTo', 'D': b'section*.4'} None
     R0: Issaquah 2023r0-issaquah-2023 {'S': /'GoTo', 'D': b'section*.5'} None
   Introduction {'S': /'GoTo', 'D': b'section.3'} None
   Motivating Use Cases {'S': /'GoTo', 'D': b'section.4'} None
     Efficient vector growth {'S': /'GoTo', 'D': b'subsection.4.1'} None
     Moving types without empty states {'S': /'GoTo', 'D': b'subsection.4.2'} None

and indeed navigating to p2786r3.pdf#subsection.4.2 in my browser opens the PDF at that particular section. So it works great!

2
  • 1
    Thanks, this would be a good answer to unix.stackexchange.com/questions/246622/… which asks for a command-line solution, but it doesn't answer the question here which is about looking up anchors visually with the rendered PDF, i.e. a asking for GUI solution. Feb 10 at 17:03
  • @Gilles'SO-stopbeingevil' — Ah, I had glazed over the "viewer" part. Although, in my defense, this question does ask "How would you know the name to use", and this command-line solution does give you an easily browsable list of names. That's almost certainly Good Enough, because the anchor names are likely to be human-readable (as in my example). Even if it's not, you could bolt on an extra step, like "open the document at each anchor in turn, for human perusal"; "binary-search in the anchors with human help"; "ask pdfminer to tell you the page# of each anchor"; etc. Better than nothing. Feb 11 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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