extract bookmarks:
$ gio info -a "metadata::evince::bookmarks" coq-art.pdf \
| sed -n '/metadata::/ s/^.*: //p' > coq-art.bookmarks
and restore its by:
gio set coq-art.pdf 'metadata::evince::bookmarks' "$(cat coq-art.bookmarks)"
Convert bookmarks to outline. See https://www.pdflabs.com/blog/export-and-import-pdf-bookmarks/
$ pdftk coq-art.pdf dump_data output coq-art.data
$ <coq-art.bookmarks sed 's/^\[//; s/\]$//' \
| sed "s/(\([0-9]*\), '[0-9IVX]*\s*- \([^']*\)')\(, \)\?/\1\t\2\n/g" | sed '/^\s*$/d' | sort -n > coq-art.bookmarks.tsv
$ <coq-art.bookmarks.tsv awk -F'\t' '$2 != "" {print "BookmarkBegin";
print "BookmarkTitle:", $2; print "BookmarkLevel:", ($2 ~ /^[0-9]+\.[0-9]/) ? 2 : 1;
print "BookmarkPageNumber:", $1 + 1}' > coq-art.bookmarks.data
$ cat coq-art.data coq-art.bookmarks.data > coq-art2.data
$ pdftk coq-art.pdf update_info coq-art2.data output coq-art2.pdf
Head of
gio info -a "metadata::evince::bookmarks" coq-art.pdf
: