linwaytin · 2022-10-29 15:31
First, I am not the author of this tool, but have used [toc-mode](https://github.com/dalanicolai/toc-mode) to make tables of contents for pdf and djvu files for many times. There are only a few other tools have the same functionality, but `toc-mode` is supposed to be the most convenient one.
Most other tools are command line, which is not adequate for this task. Even though a pdf contains the information of its table of contents, it is almost impossible to get a perfect table of contents automatically. You always need to do some editing to the extracted table, and this is why having this tool in Emacs is reasonable. Most editors focus on programming code, but things involving editing are more than that. I think `toc-mode` is a good example.
By the way, the same author has more ambitious goals to create better a better doc viewer with some editing functionalities in Emacs. This is again a great example how Emacs do can more than code editing.
nonreligious · 2022-10-29 17:47
Thanks for the post!
I use `pdf-tools` to view PDF files, and this is able to extract the TOC for a file which has one that is software generated - I can browse this using the toolbar, or hit `o` and get a side-window where the TOC is displayed using org-mode headings. Of course, this fails when there is no software generated TOC - I guess `toc-mode` can do this, using OCR?
linwaytin · 2022-10-29 22:12
Yes. If the pdf has an OCR layer, `toc-mode` can extract the TOC from that, with given page numbers for the TOC. Try `toc-extract-pages`. If there is no OCR, I would suggest generating the OCR first.
dalanicolai · 2022-10-30 14:32
Thanks a lot for posting this! Just want to mention that, as mentioned in the toc-mode README, the package has been renamed to the less fancy name \`doc-toc\` (to make 'doc' tools packages have a uniform namespace), and under that new name, it now is [available on ELPA](https://elpa.gnu.org/packages/doc-toc.html).