A PDF built in the browser shows Czech characters, but copy-paste returns garbage and the QR payment is rejected
You can write a small PDF 1.7 generator yourself (Type0 / CIDFontType2, Identity-H, FontFile2) and skip a several-hundred-kB library. Three things decide whether it works: subset the font by zeroing unused glyphs (keep glyph IDs, keep components of composite glyphs), always ship a ToUnicode CMap, and load the font as a static TTF (WOFF2 cannot be embedded). For a Czech QR payment (SPAYD), follow the Czech Banking Association spec literally and compute the amount with the same rounding as your other invoice export.
PDF jde v prohlížeči napsat vlastním malým zapisovačem (Type0 / CIDFontType2, Identity-H, FontFile2) bez knihovny o stovkách kB. Rozhodují tři věci: podmnožinu písma dělat nulováním nepoužitých glyfů (ID zůstanou, komponenty složených glyfů se berou s sebou), vždy přidat ToUnicode CMap a písmo načítat jako statické TTF (WOFF2 vložit nejde). U QR Platby (SPAYD) se držet standardu ČBA doslova a částku počítat stejným zaokrouhlením jako druhý export faktury.
Why it bites
- The PDF base fonts (WinAnsi) have no
ě ř š ž ů. You need an embedded font, and the obvious route – a PDF library plus a font engine – adds hundreds of kB to a bundle that every user downloads. - Converting RTF/DOCX to PDF on the server (SharePoint/OneDrive
?format=pdf) is great for plain documents, but the server substitutes fonts it does not have and you lose control over exact layout – not good enough for an invoice with a QR code.
What works
- Subset by zeroing, not renumbering. Keep
glyfentries only for used glyph IDs and give every other glyph a zero-lengthlocarange. Glyph IDs stay the same, socmap,hmtxandCIDToGIDMap Identityneed no rewrite. - Keep composite components. Many accented letters are composites (
ř=r+ caron). Walk the component list of every kept glyph, otherwise the accent renders as nothing. - Always add
ToUnicode. Without it the page looks right, but copy-paste, search and any document reader on the receiving side get nonsense. - Load the font lazily as static TTF from your CDN with CORS, only when the user asks for the PDF. WOFF2 is compressed and usually variable – it cannot go into
FontFile2. - Compress with
CompressionStream('deflate')(zlib format, which is whatFlateDecodeexpects); fall back to an uncompressed but valid file if it is missing.
QR Platba (SPAYD) rules that get violated
SPD*1.0*header,ACC= IBAN (optionally+BIC),AMwith a dot and two decimals, max. 9 999 999.99.CC– the spec allows only CZK. Do not put EUR invoices into a QR Platba code; say so on the document instead.- Texts (
MSGmax 60,RNmax 35) uppercase, without diacritics (keeps the QR in alphanumeric mode);*inside a value must be%2A.X-VSdigits only, max 10. - Verify by decoding the rendered PDF (render a page, read the QR with a decoder, parse the result), not by comparing strings in a unit test.
- Round like your other export. If your XML e-invoice rounds each VAT bucket's base to whole crowns and the PDF sums raw bases, the QR asks for a different amount than the XML (a line of 9 001.50 CZK is enough). Test both outputs against each other.