Skip to content

Instantly share code, notes, and snippets.

@daanturo
Created October 20, 2022 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daanturo/010601e4910fbf0287df104b567a206d to your computer and use it in GitHub Desktop.
Save daanturo/010601e4910fbf0287df104b567a206d to your computer and use it in GitHub Desktop.
pdf-toc-gen.el
(named-let recur ((files input-files)
(cur-page-num-counter 1)
(acc-bookmarks ""))
(cond
((seq-empty-p files)
acc-bookmarks)
(t
(-let* ((file (car files))
(title (--> (file-name-base file)
(string-replace "_" " " it)))
(cur-file-bookmarks (format "BookmarkBegin
BookmarkTitle: %s
BookmarkLevel: 1
BookmarkPageNumber: %d
" title cur-page-num-counter))
(new-page-num-counter (+ cur-page-num-counter
(page-number-in-file file))))
(message "Generating bookmarks for %s" file)
(recur (cdr files)
new_page_num_counter
(concat acc-bookmarks
cur-file-bookmarks
(shell-command-to-string
(format "pdf-my-demote-bookmarks %s %s"
file
(- cur-page-num-counter 1)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment