Skip to content

Commit

Permalink
Add support of PDF/A-?u
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Apr 25, 2024
1 parent c75cc9f commit 245e4f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions weasyprint/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ def write_pdf(self, target=None, zoom=1, finisher=None, **options):
_, properties = VARIANTS[variant]
if 'version' in properties:
version = properties['version']
if 'identifier' in properties and not identifier:
identifier = properties['identifier']

if finisher:
finisher(self, pdf)
Expand Down
28 changes: 24 additions & 4 deletions weasyprint/pdf/pdfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def read_binary(package, resource):


def pdfa(pdf, metadata, document, page_streams, attachments, compress,
version):
version, variant):
"""Set metadata for PDF/A documents."""
# Add ICC profile.
profile = pydyf.Stream(
Expand Down Expand Up @@ -86,9 +86,29 @@ def pdfa(pdf, metadata, document, page_streams, attachments, compress,
pdf_object['F'] = 2 ** (3 - 1)

# Common PDF metadata stream.
add_metadata(pdf, metadata, 'a', version, 'B', compress)
add_metadata(pdf, metadata, 'a', version, variant, compress)


VARIANTS = {
f'pdf/a-{i}b': (partial(pdfa, version=i), {'version': pdf_version})
for i, pdf_version in enumerate(('1.4', '1.7', '1.7', '2.0'), start=1)}
'pdf/a-1b': (
partial(pdfa, version=1, variant='B'),
{'version': '1.4', 'identifier': True}),
'pdf/a-2b': (
partial(pdfa, version=2, variant='B'),
{'version': '1.7', 'identifier': True}),
'pdf/a-3b': (
partial(pdfa, version=3, variant='B'),
{'version': '1.7', 'identifier': True}),
'pdf/a-4b': (
partial(pdfa, version=4, variant='B'),
{'version': '2.0', 'identifier': True}),
'pdf/a-2u': (
partial(pdfa, version=2, variant='U'),
{'version': '1.7', 'identifier': True}),
'pdf/a-3u': (
partial(pdfa, version=3, variant='U'),
{'version': '1.7', 'identifier': True}),
'pdf/a-4u': (
partial(pdfa, version=4, variant='U'),
{'version': '2.0', 'identifier': True}),
}

0 comments on commit 245e4f5

Please sign in to comment.