Last active
March 28, 2016 02:53
-
-
Save yiwenlu66/7dabe217546901c57d61 to your computer and use it in GitHub Desktop.
Convert DJVU outline to PDF metadata
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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