I opened my Spotify data export the other day, partly out of curiosity, partly because that’s what you do when you build a tool for opening data exports. Somewhere among the JSON files sat a PDF, the kind of introduction document that explains what all the other files are. It had a contents page. Titles, dotted leaders, page numbers, all very orderly.

The sidebar in Unwrap was empty.

My first reaction was the obvious one: that’s a bug. There’s a table of contents right there. I can see it. Surely the viewer can see it too.

It couldn’t, and for a fairly good reason. A contents page and an outline look like the same thing, but they live in completely different places.

Illustration of a rabbit feeding a book into a machine while a small robot watches a screen rebuild a nested contents outline.

Two things that look the same

The outline you see in a PDF viewer’s sidebar comes from bookmarks. That’s a separate structure inside the file, a little tree of entries, each pointing at a destination. It isn’t part of any page. You can’t see it in print, and it doesn’t care what the document looks like.

The contents page is just a page. To the file, it’s text placed at certain coordinates, the same kind of thing as a paragraph or a page footer. That it lists chapters is something you understand by reading it. The PDF doesn’t know.

Lots of documents have both, because the software that made them wrote both. Lots of documents have only the printed one, because nobody exported bookmarks, or the tool didn’t support them, or the PDF was assembled from something that never had them. From the outside, these two kinds of PDF look identical. From the inside, one has a map and the other has a picture of a map.

Diagram comparing a printed contents page on the left with a PDF outline sidebar on the right, both listing the same chapter titles.

There’s a middle ground, and that’s where it gets interesting. Many contents pages are clickable. You click a chapter title and land on the right page. So surely that’s enough to build an outline from?

Sort of. A link in a PDF is a rectangle with a destination. That’s it. It doesn’t come with a label. The words you see are just whatever text happens to sit underneath that rectangle. To turn a link into an outline entry, you have to look at what’s under the clickable area and decide what the entry is called.

That’s where dotted leaders and page numbers come in. “A snapshot, not a backup … 4” is what you see, but the entry you want is “A snapshot, not a backup”. The printed page number is irrelevant here. The link already knows where it goes, and sometimes the printed number doesn’t even match the actual page position, because the title page wasn’t counted or the preface has its own numbering.

Diagram showing a contents-page link split into a kept title label and stripped dotted leaders with a printed page number, while the jump still goes to the linked destination.

Reconstructing carefully

So I taught Unwrap to try. If a PDF has usable bookmarks, it shows them as they are and stops there. If it doesn’t, it looks at the first few pages for a group of internal links that behaves like a table of contents: enough of them, moving forward through the document, pointing at more than one page. A stray entry or two is fine. Jumping back and forth isn’t. If most entries carry numbers like 1, 1.2 and 1.2.3, the outline gets nested. Otherwise it stays flat.

What it doesn’t do, at least not yet, is build an outline from plain text. That’s not because it can’t be done. A lot of contents pages are easy enough to spot: a heading that says Contents, a column of titles, dotted leaders, numbers running down the right edge. You could match those titles against headings further in and get it right most of the time.

Most of the time is the hard part. With links, the file tells you where each entry goes. With plain text, you’re inferring it, and an unnumbered title page or a separate numbering scheme for the front matter is enough to send every entry off by a page or two, quietly and confidently. That’s solvable, but it needs more work than matching a few lines of text.

And even with real links, there’s a limit. Unwrap knows where a link points. It doesn’t know whether the author linked the right chapter.

Where it stands

The Spotify PDF has an outline now. Its contents page turned out to be clickable, and the links behave the way a table of contents should, so Unwrap can rebuild one from them.

Plenty of PDFs still end up with an empty sidebar. Some have no contents page at all. Some have one that’s plain text, and Unwrap doesn’t read those yet. A lot of them would probably be readable well enough, so that’s simply the next problem, not a principle. The part I’d keep either way is the order: use what the file actually says first, and only guess when the guess is good enough to trust.

A contents page is something written for people. An outline is something written for software. Many PDFs only contain the first one, and that’s why your viewer looks at a perfectly good table of contents and sees nothing.

If you want to see the difference for yourself, there’s an interactive deep dive with three versions of the same document.