You are not logged in.

#1 2022-01-24 23:45:32

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

[solved] Generate a table of contents of a PDF

I recently printed The Rust Programming Language Book (https://doc.rust-lang.org/stable/book/ - see the top-right icon for printing). I then found out it has no index/ToC. What's worse is that the chapters are not even enumerated, so good luck finding anything...

I was wondering, then, if there was any tool to generate a table of contents of a PDF. The file has correctly marked sections and subsections, and it has, fortunately, page numbers. So far, I've found close to nothing online: Windows proprietary programs, paid web services, etc. I was wondering if this is something doable with one of those fancy little CLI utilities that I haven't discovered yet. Or, maybe, there is a relatively easy way to create a script that gets the job done.

I am asking for any help or guidance in this nice community :-)

Last edited by icar (2022-01-25 20:26:20)

Offline

#2 2022-01-25 09:21:51

seth
Member
Registered: 2012-09-03
Posts: 50,008

Re: [solved] Generate a table of contents of a PDF

Tried libreoffice?

Offline

#3 2022-01-25 14:16:44

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: [solved] Generate a table of contents of a PDF

seth wrote:

Tried libreoffice?

I did, yes. After 5min loading, it presented an editable document with parts of the text wrongly formatted.

Example: https://i.imgur.com/z6Cd8Po.png

Offline

#4 2022-01-25 14:49:06

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: [solved] Generate a table of contents of a PDF

In the case of the rust book you can use pdf.tocgen (Example:

python -m pdfxmeta -p 8 -a 1 ../The\ Rust\ Programming\ Language.pdf "Getting Started" > data.toml
python -m pdfxmeta -p 3 -a 2 ../The\ Rust\ Programming\ Language.pdf "Who Rust Is For" >> data.toml
python -m pdfxmeta -p 4 -a 3 ../The\ Rust\ Programming\ Language.pdf "Students" >> data.toml
python -m pdftocgen ../The\ Rust\ Programming\ Language.pdf <data.toml >data.toc
python -m pdftocio ../The\ Rust\ Programming\ Language.pdf <data.toc

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2022-01-25 20:26:01

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: [solved] Generate a table of contents of a PDF

Thanks progandy, that is exactly what I was looking for.

Offline

Board footer

Powered by FluxBB