Quote:
Originally Posted by 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:
Originally Posted by 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:
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:
- Blue grabs the chronological numbering of all the headings.
- Red grabs how deep the levels are.
- Note that Sigil's toc.ncx formats using 8 spaces for the first level (in PDF, the first level is considered "0").
- Green grabs the actual chapter titles.
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.