Skip to content

Commit

Permalink
Store attachment name in list of attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jan 19, 2025
1 parent e21a848 commit e4f9b7d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@ def test_command_line_render(tmp_path):
os.environ.pop('SOURCE_DATE_EPOCH')

stdout = _run('combined.html --uncompressed-pdf -')
assert stdout.count(b'attachment') == 0
assert stdout.count(b'Filespec') == 0
stdout = _run('combined.html --uncompressed-pdf -')
assert stdout.count(b'attachment') == 0
assert stdout.count(b'Filespec') == 0
stdout = _run('-a pattern.png --uncompressed-pdf combined.html -')
assert stdout.count(b'attachment') == 1
assert stdout.count(b'Filespec') == 1
stdout = _run(
'-a style.css -a pattern.png --uncompressed-pdf combined.html -')
assert stdout.count(b'attachment') == 2
assert stdout.count(b'Filespec') == 2

_run('combined.html out23.pdf --timeout 30')
assert (tmp_path / 'out23.pdf').read_bytes() == pdf_bytes
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def test_embedded_files_attachments(tmp_path):
]
)
assert f'<{hashlib.md5(b"hi there").hexdigest()}>'.encode() in pdf
assert b'/F ()' in pdf
assert b'/F (attachment.bin)' in pdf
assert b'/UF (attachment.bin)' in pdf
name = BOM_UTF16_BE + 'some file attachment äöü'.encode('utf-16-be')
assert b'/Desc <' + name.hex().encode() + b'>' in pdf
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def generate_pdf(document, target, zoom, **options):
if pdf_attachments:
content = pydyf.Dictionary({'Names': pydyf.Array()})
for i, pdf_attachment in enumerate(pdf_attachments):
content['Names'].append(pydyf.String(f'attachment{i}'))
content['Names'].append(pdf_attachment['F'])
content['Names'].append(pdf_attachment.reference)
pdf.add_object(content)
if 'Names' not in pdf.catalog:
Expand Down
2 changes: 1 addition & 1 deletion weasyprint/pdf/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def write_pdf_attachment(pdf, attachment, compress):

pdf_attachment = pydyf.Dictionary({
'Type': '/Filespec',
'F': pydyf.String(),
'F': pydyf.String(filename.encode(errors='ignore')),
'UF': pydyf.String(filename),
'EF': pydyf.Dictionary({'F': file_stream.reference}),
'Desc': pydyf.String(attachment.description or ''),
Expand Down

0 comments on commit e4f9b7d

Please sign in to comment.