Skip to main content

PDF の目次づくり

  1. 目次用の txt
    • このような形式で用意
      • 1列目 : 章の名前
        • 子項目の場合はタブでインデント
      • 2列目: ページ番号
      • 3列目: PDFファイル内でのページ番号
        • 1行目は必須
        • それ以降はズレる場合だけ入れる(空白ページが消えたりしてるとそうなる)
txt
1. App Development							1		15
2. Introduction to Swift 5
3. Swift Paradigm 31
...
9. Concurrency 403
9.1 Asynchronous and Concurrent Tasks 403
10. Storage 423
10.1 User Preference 423
10.2 Files 427
10.3 Archiving 460
10.4 Core Data 473
  1. JSON に変換
bash
~/tools/pdf-util/pdf-toc-txt-to-json.py 'SwiftUI for Masterminds iOS 16.index.txt'
  1. 目次用のJSON ( 出力されたもの )
json
[
[1, "1. App Development", 15],
[1, "2. Introduction to Swift", 19],
[1, "3. Swift Paradigm", 45],
...
[1, "9. Concurrency", 417],
[2, "9.1 Asynchronous and Concurrent Tasks", 417],
[1, "10. Storage", 437],
[2, "10.1 User Preference", 437],
[2, "10.2 Files", 441],
[2, "10.3 Archiving", 474],
[2, "10.4 Core Data", 487],
  1. PDF に埋め込む
bash
~/tools/pdf-util/pdf-toc-import.py \
'SwiftUI for Masterminds iOS 16.pdf' \
'SwiftUI for Masterminds iOS 16.index.json'