1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 16:07:57 +03:00

Fix #101: Write PDF bookmarks/outline correctly.

The PDF spec says that the target of a bookmark/outline entry contains
the *object ID* of the target page. We previously wrote the *page number*,
which for some reason still worked in some PDF viewers.
This commit is contained in:
Pierre-Alain Mignot 2013-06-28 18:31:01 +01:00 committed by Simon Sapin
parent 3313c061ae
commit 76b87c82f4

View File

@ -384,10 +384,11 @@ def write_pdf_metadata(document, fileobj, scale):
bookmark_root['Last']))
for bookmark in bookmarks:
content = [pdf_format('<< /Title {0!P}\n', bookmark['label'])]
page_num, pos_x, pos_y = bookmark['target']
content.append(pdf_format(
'/A << /Type /Action /S /GoTo '
'/D [{0} /XYZ {1:f} {2:f} 0] >>\n',
*bookmark['target']))
'/D [{0} 0 R /XYZ {1:f} {2:f} 0] >>\n',
pdf.pages[page_num].object_number, pos_x, pos_y))
if bookmark['Count']:
content.append(pdf_format('/Count {0}\n', bookmark['Count']))
for key in ['Parent', 'Prev', 'Next', 'First', 'Last']: