[Tex/LaTex] How to enforce generation of PDF table of contents

hyperreftable of contents

When I'm adding \tableofcontents to my document the PDF generated contains a nice list of sections/subsections on the left side, when viewed in Adobe Acrobat (I also use hyperref package). Everything is fine.

But now I don't need this TOC to be visible in the document, but I want to keep it visible in the PDF. When I'm deleting \tableofcontents from the document it disappears in the PDF as well. How to solve it?

ps. Maybe this is the problem (my log)?:

Package hyperref Warning: Option `bookmarks' has already been used,
(hyperref)                setting the option has no effect on input line 33.

Best Answer

Here's a hack:

\newsavebox{\discard}
\sbox{\discard}{\vbox{\tableofcontents}}

The tableofcontents is generated and saved but never inserted into the document.

But I just read @lockstep's comment; you may not need any of this.