diff --git a/tests/test_pdf.py b/tests/test_pdf.py index 6e93040c6d..e3067b6fe9 100644 --- a/tests/test_pdf.py +++ b/tests/test_pdf.py @@ -620,6 +620,21 @@ def test_attachments_data(): ''').write_pdf() md5 = '<{}>'.format(hashlib.md5(b'some data').hexdigest()).encode() assert md5 in pdf + assert b'EmbeddedFiles' in pdf + + +@assert_no_logs +def test_attachments_data_with_anchor(): + pdf = FakeHTML(string=''' + Test document 2 + + +

Title

+ example + ''').write_pdf() + md5 = '<{}>'.format(hashlib.md5(b'some data').hexdigest()).encode() + assert md5 in pdf + assert b'EmbeddedFiles' in pdf @assert_no_logs diff --git a/weasyprint/pdf/__init__.py b/weasyprint/pdf/__init__.py index 4c396dcbe2..34ae7e8aa7 100644 --- a/weasyprint/pdf/__init__.py +++ b/weasyprint/pdf/__init__.py @@ -468,7 +468,10 @@ def generate_pdf(document, target, zoom, attachments, optimize_size, name_array.append(pydyf.String(anchor[0])) name_array.append(anchor[1]) dests = pydyf.Dictionary({'Names': name_array}) - pdf.catalog['Names'] = pydyf.Dictionary({'Dests': dests}) + if 'Names' in pdf.catalog: + pdf.catalog['Names']['Dests'] = dests + else: + pdf.catalog['Names'] = pydyf.Dictionary({'Dests': dests}) # Apply PDF variants functions if variant: