r"""
>>> from pprint import pprint
>>> data = '\n'.join([
+ ... 'InfoBegin',
... 'InfoKey: CreationDate',
... 'InfoValue: D:20080502020302Z',
... 'NumberOfPages: 123',
+ ... 'BookmarkBegin',
... 'BookmarkTitle: Chapter 1',
... 'BookmarkLevel: 1',
... 'BookmarkPageNumber: 1',
... 'BookmarkTitle: Section 1.2',
... 'BookmarkLevel: 2',
... 'BookmarkPageNumber: 5',
+ ... 'PageLabelBegin',
... 'PageLabelNewIndex: 1',
... 'PageLabelStart: 316',
+ ... 'PageLabelPrefix:',
... 'PageLabelNumStyle: DecimalArabicNumerals',
... 'PageLabelNewIndex: 2',
... 'PageLabelStart: 317',
+ ... 'PageLabelPrefix:',
... 'PageLabelNumStyle: DecimalArabicNumerals',
... 'PageLabelNewIndex: 3',
... 'PageLabelStart: 318',
+ ... 'PageLabelPrefix:',
... 'PageLabelNumStyle: DecimalArabicNumerals',
... 'PageLabelNewIndex: 4',
... ])
bookmark_info = {}
bookmark_info_fields = ['title', 'level', 'page']
for line in data.splitlines():
- key,value = line.split(': ', 1)
+ try:
+ key,value = line.split(': ', 1)
+ except ValueError: # e.g. line == 'InfoBegin'
+ continue
if key == 'NumberOfPages':
pages = int(value)
elif key.startswith('Bookmark'):