PDF Output: Ignore invalid links instead of erroring out on them. Fixes #1179314 (conversion from CHM to PDF fails)

This commit is contained in:
Kovid Goyal 2013-05-13 08:56:31 +05:30
parent 1c225cac66
commit cc223574d0

View File

@ -45,11 +45,15 @@ class Links(object):
href, page, rect = link
p, frag = href.partition('#')[0::2]
try:
link = ((path, p, frag or None), self.pdf.get_pageref(page).obj, Array(rect))
pref = self.pdf.get_pageref(page).obj
except IndexError:
self.log.warn('Unable to find page for link: %r, ignoring it' % link)
continue
self.links.append(link)
try:
pref = self.pdf.get_pageref(page-1).obj
except IndexError:
self.pdf.debug('Unable to find page for link: %r, ignoring it' % link)
continue
self.pdf.debug('The link %s points to non-existent page, moving it one page back' % href)
self.links.append(((path, p, frag or None), pref, Array(rect)))
def add_links(self):
for link in self.links: