Mobileread
Create a simple TOC, how?
#1  nlundberg 04-30-2020, 02:25 PM
Hi,

I would like to create a toc on a PDF (converted from DJVU). Just a simple one to jump to chapters in a 1000+ pages book.
Reply 

#2  Hitch 05-01-2020, 06:51 PM
Quote nlundberg
Hi,

I would like to create a toc on a PDF (converted from DJVU). Just a simple one to jump to chapters in a 1000+ pages book.
No automated way. Open the PDF in Acrobat and insert links manually.

Sorry. I'm sure that somebody, somewhere, has a faster/easier option, but the manual way is how I do it, when needed. I mean, realistically, there aren't a lot of PDFs, today, that come to life AS PDFs. As PDF is the end result of a process, most folks have the source docs, which facilitate making the links in a more-automated fashion. You, unfortunately, are stuck with the good old fashioned hand method.

(I would note that searching for the word Chapter, if it's used, makes it slightly less excruciating. For the project you've previously mentioned, the pdfs from websites, well...it's all manual. Sorry.)

Hitch
Reply 

#3  Tex2002ans 05-01-2020, 10:23 PM
Many many years ago I used jpdfbookmarks:

http://flavianopetrocchi.blogspot.com/2011/11/jpdfbookmarks-252.html

Edit: I just looked up and saw that willus's fantastic tool, k2pdfopt also has an option "-toclist".

This allows you to create a simple text file:

Code
1 Introduction
10 Chapter 1
+10 Chapter 1, Part A
+25 Chapter 1, Part B
++25 Chapter 1, Part B, Subsection 1
++27 Chapter 1, Part B, Subsection 2
+30 Chapter 1, Part C
50 Chapter 2
70 Chapter 3
and insert that as PDF bookmarks.

You can read more details in his "List of Command-Line Options" (and check the above thread too, willus has tons of answers about his program there).
Reply 

#4  Hitch 05-02-2020, 12:15 AM
Quote Tex2002ans
Many many years ago I used jpdfbookmarks:

http://flavianopetrocchi.blogspot.com/2011/11/jpdfbookmarks-252.html

Edit: I just looked up and saw that willus's fantastic tool, k2pdfopt also has an option "-toclist".

This allows you to create a simple text file:

Code
1 Introduction
10 Chapter 1
+10 Chapter 1, Part A
+25 Chapter 1, Part B
++25 Chapter 1, Part B, Subsection 1
++27 Chapter 1, Part B, Subsection 2
+30 Chapter 1, Part C
50 Chapter 2
70 Chapter 3
and insert that as PDF bookmarks.

You can read more details in his "List of Command-Line Options" (and check the above thread too, willus has tons of answers about his program there).
Yeah, but AFAIK, this poster is downloading websites and converting them to PDFs for readability on his Kindle. I'm not sure how he can use k2pdfopt to create a TOC like that. But, hey, it'll be interesting to know how it goes!

Hitch
Reply 

#5  willus 05-02-2020, 07:50 AM
Quote Tex2002ans
Many many years ago I used jpdfbookmarks:

http://flavianopetrocchi.blogspot.com/2011/11/jpdfbookmarks-252.html

Edit: I just looked up and saw that willus's fantastic tool, k2pdfopt also has an option "-toclist".

This allows you to create a simple text file:

Code
1 Introduction
10 Chapter 1
+10 Chapter 1, Part A
+25 Chapter 1, Part B
++25 Chapter 1, Part B, Subsection 1
++27 Chapter 1, Part B, Subsection 2
+30 Chapter 1, Part C
50 Chapter 2
70 Chapter 3
and insert that as PDF bookmarks.

You can read more details in his "List of Command-Line Options" (and check the above thread too, willus has tons of answers about his program there).
If all you need to do is add a TOC/bookmarks, Coherent PDF (cpdf) is a better tool than k2pdfopt. It's an excellent PDF command-line tool to have in your arsenal--it can split, merge, add watermarks, etc., and it's super fast. See this link.

To list existing bookmarks:

cpdf -list-bookmarks input.pdf

0 "Part 1" 1 open
1 "Part 1A" 2
2 "Part 1B" 3
0 "Part 2" 4
1 "Part 2a" 5

I presume "open" is the bookmark you want the file to open to by default.

To add bookmarks:

cpdf -add-bookmarks bookmarks.txt input.pdf -o output.pdf
Reply 

#6  Tex2002ans 05-02-2020, 07:39 PM
Quote willus
If all you need to do is add a TOC/bookmarks, Coherent PDF (cpdf) is a better tool than k2pdfopt.


It's been at least 7 years since I had to add bookmarks to existing PDFs, so my info was probably a little out of date.

Quote Hitch
Yeah, but AFAIK, this poster is downloading websites and converting them to PDFs for readability on his Kindle. I'm not sure how he can use k2pdfopt to create a TOC like that. But, hey, it'll be interesting to know how it goes!
Hmmm... wonder if you could create a completed EPUB, generate a proper TOC, then pull the toc.ncx and get rid of all the xml cruft.

For example, Sigil formats the toc.ncx like:

Spoiler Warning below






Code
 <navMap> <navPoint id="navPoint-1" playOrder="1"> <navLabel> <text>Part 1</text> </navLabel> <content src="Text/Section0001.xhtml#sigil_toc_id_1"/> <navPoint id="navPoint-2" playOrder="2"> <navLabel> <text>Chapter 1</text> </navLabel> <content src="Text/Section0001.xhtml#sigil_toc_id_2"/> </navPoint> </navPoint> <navPoint id="navPoint-3" playOrder="3"> <navLabel> <text>Part 2</text> </navLabel> <content src="Text/Section0001.xhtml#sigil_toc_id_3"/> </navPoint> </navMap>


Everything is already nested/indented in a certain way.

So you strip everything besides <text> and playOrder:

Code
 playOrder="1" <text>Part 1</text> playOrder="2" <text>Chapter 1</text> playOrder="3" <text>Part 2</text>
Search and replace the Parts:

Search: ^\s+playOrder="(\d+)"\r\n[ ]{8}<text>(.+)</text>
Replace: 0 "\2" \1

Code
0 "Part 1" 1 playOrder="2" <text>Chapter 1</text>
0 "Part 2" 3
Key points being:

Then you adjust the red part for "10 spaces" = next level:

Search: ^\s+playOrder="(\d+)"\r\n[ ]{10}<text>(.+)</text>
Replace: 1 "\2" \1

Code
0 "Part 1" 1
1 "Chapter 1" 2
0 "Part 2" 3
then you would just have to go through and manually change the (blue) numbers to match the PDFs pages... but at least the bulk of the formatting would be completed.
Reply 

#7  Marinolino 05-05-2020, 08:26 AM
Quote nlundberg
Hi,

I would like to create a toc on a PDF (converted from DJVU). Just a simple one to jump to chapters in a 1000+ pages book.
Also, if there is no TOC page we can create one to our liking (e.g. just with chapter's titles) and then link (hyperlink) those lines instead of creating bookmarks, or we can create both (linked TOC bookmarks and hyperlinked TOC page) at the same time.

Here is an older thread with some tools for the automatic and manual creation of a linked TOC, either as bookmarks or hyperlinked TOC page:

https://www.mobileread.com/forums/sh...d.php?t=262659
Reply 

#8  Hitch 05-05-2020, 09:07 AM
Quote Marinolino
Also, if there is no TOC page we can create one to our liking (e.g. just with chapter's titles) and then link (hyperlink) those lines instead of creating bookmarks, or we can create both (linked TOC bookmarks and hyperlinked TOC page) at the same time.

Here is an older thread with some tools for the automatic and manual creation of a linked TOC, either as bookmarks or hyperlinked TOC page:

https://www.mobileread.com/forums/sh...d.php?t=262659
I remember that thread, but in almost every instance, the TOC already existed, in the scanned document and all the posts were about how to automagically link said pre-existing TOC.

Unless I've misread this poster's threads, he is making pdfs from websites. Those aren't going to have preexisting TOCs with page numbers.

@Tex2002ans:

Yes, I suspect that's about the fastest way around it; create an ePUB, use headings (if they are not already there from the website), generate a TOC, etc.

Hitch
Reply 

#9  Marinolino 05-05-2020, 09:17 AM
Quote Hitch
I remember that thread, but in almost every instance, the TOC already existed, in the scanned document and all the posts were about how to automagically link said pre-existing TOC.

Unless I've misread this poster's threads, he is making pdfs from websites. Those aren't going to have preexisting TOCs with page numbers.

...
In that case as I've suggested he can create a pdf TOC page himself (from a textual file or by using some pdf editor) consisting of chapter numbers or full chapter names, and than hyperlink those chapter names manualy using some pdf editor.

How to create an interactive (hyperlinked) table of contents with Acrobat.

https://www.youtube.com/watch?v=IR7FT3Pr4a0
Reply 

#10  Hitch 05-05-2020, 09:27 AM
Quote Marinolino
In that case as I've suggested he can create a pdf TOC page himself (from a textual file or using some pdf editor) consisting of chapter numbers or full chapter names, and than hyperlink those chapter names manualy using some pdf editor.

How to create an interactive (hyperlinked) table of contents for a PDF.

https://www.youtube.com/watch?v=IR7FT3Pr4a0
"Chapter numbers" from what? There aren't any chapters, typically, on a website. I guess he could use URLs as chapter "titles."

Hitch
Reply 

  Next »  Last »  (1/2)
Today's Posts | Search this Thread | Login | Register