/AF array lists every attachment twice in PDF/A-3 output
Hello,
This issue has been written with the help of Claude Code. I made my best to write a useful issue report and avoid any slope as much as I can. I have run myself all the bash command on my terminal (GNU/Linux - TuxedoOS up to date) and study the output. I am not an expert on the PDF format but the output returned by the bash and Claude code points looks logical to me that there's a duplication in what weasyprint is generating in the PDF.
So now the issue :-)
With the parameter --pdf-variant=pdf/a-3b, the catalog's /AF array holds each attachment twice, although a single /Filespec object exists for it:
~/_poc/bug-weasyprint
$ python3 -m venv venv
~/_poc/bug-weasyprint
$ ./venv/bin/pip install --upgrade pip
Requirement already satisfied: pip in ./venv/lib/python3.12/site-packages (24.0)
Collecting pip
Downloading pip-26.2.1-py3-none-any.whl.metadata (4.6 kB)
Downloading pip-26.2.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 38.6 MB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 24.0
Uninstalling pip-24.0:
Successfully uninstalled pip-24.0
Successfully installed pip-26.2.1
~/_poc/bug-weasyprint
$ ./venv/bin/pip install weasyprint==70.0
Collecting weasyprint==70.0
Using cached weasyprint-70.0-py3-none-any.whl.metadata (3.8 kB)
...
...
Installing collected packages: brotli, zopfli, webencodings, Pyphen, pydyf, pycparser, Pillow, fonttools, tinyhtml5, tinycss2, cffi, cssselect2, weasyprint
Successfully installed Pillow-12.3.0 Pyphen-0.18.1 brotli-1.2.0 cffi-2.1.1 cssselect2-0.10.1 fonttools-4.64.0 pycparser-3.0 pydyf-0.12.1 tinycss2-1.5.1 tinyhtml5-2.1.0 weasyprint-70.0 webencodings-0.6.1 zopfli-0.4.3
~/_poc/bug-weasyprint
$ ./venv/bin/weasyprint --version
WeasyPrint version 70.0
~/_poc/bug-weasyprint
$ ./venv/bin/python -c "import sys, weasyprint, pydyf; print(sys.version.split()[0], weasyprint.__version__, pydyf.__version__)"
3.12.3 70.0 0.12.1
~/_poc/bug-weasyprint
$ printf '<!DOCTYPE html>\n<html><body><h1>Invoice 42</h1></body></html>\n' > invoice.html
~/_poc/bug-weasyprint
$ echo '<x/>' > factur-x.xml
~/_poc/bug-weasyprint
$ ./venv/bin/weasyprint invoice.html out.pdf \
--attachment=factur-x.xml --attachment-relationship=Alternative --pdf-variant=pdf/a-3b
~/_poc/bug-weasyprint
$ ls
factur-x.xml invoice.html out.pdf venv
~/_poc/bug-weasyprint
$ mutool clean -d -a out.pdf decomp.pdf
~/_poc/bug-weasyprint
$ ls
decomp.pdf factur-x.xml invoice.html out.pdf venv
~/_poc/bug-weasyprint
$ grep -ao '/AF *\[[^]]*\]' decomp.pdf
/AF [ 11 0 R 11 0 R ]
~/_poc/bug-weasyprint
$ grep -c '/Type /Filespec' decomp.pdf
1
~/_poc/bug-weasyprint
$ grep -ao '/Producer *([^)]*)' decomp.pdf
/Producer (WeasyPrint 70.0)
~/_poc/bug-weasyprint
$
If you look at the bash above, you'll see that I attached only one file but the PDF says they're two: /AF [ 11 0 R 11 0 R ].
This is not a validation failure: veraPDF passes such a file:
~/_poc/bug-weasyprint
$ docker run --rm -v "$PWD":/data verapdf/cli:v1.30.2 --flavour 3b --format text out.pdf
Unable to find image 'verapdf/cli:v1.30.2' locally
v1.30.2: Pulling from verapdf/cli
db5b5e075fa3: Pull complete
780851c4d3fa: Pull complete
988a3cb80ef0: Pull complete
6a0ac1617861: Pull complete
803a70357bd1: Pull complete
abaf802d09f9: Pull complete
Digest: sha256:d5ee329657cf9bc4b2400392dd54c7d0a0ce9980ff6fa2da5590eebeec007cdb
Status: Downloaded newer image for verapdf/cli:v1.30.2
PASS /data/out.pdf 3bAnd duplicates aren't forbidden anywhere Claude Code could find, so the two reasons I am posting here anyway:
- A reader that lists associated files from
/AFcan show the same attachment twice - The exemple Factur-X invoices Claude Code downloaded from FNFE-MPE all carry exactly one reference per attachment.
Source: Kozea/WeasyPrint