Skip to content

Instantly share code, notes, and snippets.

@yiwenlu66
Last active March 28, 2016 02:53
Show Gist options
  • Save yiwenlu66/7dabe217546901c57d61 to your computer and use it in GitHub Desktop.
Save yiwenlu66/7dabe217546901c57d61 to your computer and use it in GitHub Desktop.
Convert DJVU outline to PDF metadata
#!/usr/bin/env python3
import sys
import sexpdata
def walk_bmarks(bmarks, level):
output = ''
wroteTitle = False
for j in bmarks:
if isinstance(j, list):
output = output + walk_bmarks(j, level + 1)
elif isinstance(j, str):
if not wroteTitle:
output = output + \
"BookmarkBegin\nBookmarkTitle: %s\nBookmarkLevel: %d\n" % (j, level)
wroteTitle = True
else:
output = output + "BookmarkPageNumber: %s\n" % j.split('#')[1]
wroteTitle = False
else:
pass
return output
if __name__ == "__main__":
if len(sys.argv) == 1:
print("No input file.")
exit()
filename = sys.argv[1]
print(walk_bmarks(sexpdata.load(open(filename)), 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment