Skip to Content

[FIX] tools: convert PDFs using simple fonts to PDF/A

Failed 14m merged
PR
#1347
PR Author
David Tran
Committer
David Tran
Commit
b84a010cea45
Branch
20.0
Age
Up-time
Commit message
[FIX] tools: convert PDFs using simple fonts to PDF/A

Steps to reproduce:
- Install the optional `fonttools` package (it is also pulled by other
  packages, e.g. `pyHanko[opentype]`)
- Run `odoo-bin -i test_base --test-tags /test_base:TestPdf`

Issue:
`test_convert_to_pdfa_without_outlines` fails with
`KeyError: '/DescendantFonts'`.

Cause:
When `fonttools` is installed, `convert_to_pdfa` rewrites the glyph
widths of the fonts used in the PDF and reads `/DescendantFonts` of
every font, assuming they are all composite (Type0) fonts like the ones
embedded by wkhtmltopdf. Simple fonts (Type1, TrueType, ...), such as
the Arial font of `base/tests/files/file.pdf`, have no descendant fonts,
so the conversion crashes. Without `fonttools` the whole block is
skipped, which hides the issue.

The callers (Factur-X/ZUGFeRD and ZATCA invoice PDFs) catch the
exception and only log it, so such a PDF is sent without being
converted to PDF/A.

Fix:
Only collect the descendant fonts of composite fonts. Simple fonts keep
their widths in `/Widths` (or use the standard 14 font metrics) and are
left untouched.

Signed-off-by: David Tran <david.tran@tvtmarine.com>