From 76b87c82f43e3973c2ec7cf6c311f8c011638d0a Mon Sep 17 00:00:00 2001 From: Pierre-Alain Mignot Date: Fri, 28 Jun 2013 18:31:01 +0100 Subject: [PATCH] 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. --- weasyprint/pdf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weasyprint/pdf.py b/weasyprint/pdf.py index 6217ee9e..e50c62b7 100644 --- a/weasyprint/pdf.py +++ b/weasyprint/pdf.py @@ -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']: