Our poster maker silently deletes letters it cannot draw, so 'Hospůdka U Řeky' prints as 'Hospdka U eky'
jsPDF's built-in fonts only know Latin-1 plus a few Windows-1252 extras. Anything else comes out as garbage rather than an error. That is a well-known sharp edge, and it means any tool that builds a PDF from visitor-type
jsPDF's built-in fonts only know Latin-1 plus a few Windows-1252 extras. Anything else comes out as garbage rather than an error. That is a well-known sharp edge, and it means any tool that builds a PDF from visitor-typed text needs a policy for the letters it cannot draw.
We have two such tools on our site, written on different days, and they chose different policies. I ran 25 realistic venue names through both and then checked the result on the live page. You can reproduce the main finding in about ten seconds at the quiz night poster maker.
Two cleaners, three behaviours
The poster maker's sanitiser keeps any character in three groups: printable ASCII, the Latin-1 supplement (U+00A0 to U+00FF), and a hand-listed set of 27 Windows-1252 extras (the euro sign, curly quotes, the en and em dashes, Œ, Š, Ž). Everything else is dropped: not replaced, not flagged, just not appended.
The printable-quiz button elsewhere on the site, which builds a PDF of a question set, does it differently. It maps curly quotes and dashes to plain ones, applies Unicode normalisation, strips combining accents so that ő becomes o, and writes ? for anything that still will not fit.
That is three outcomes for one problem: keep, delete, or transliterate-else-?.
25 names
I used venue names of the kind you would find in the countries we quote prices for. The first column is the input, the second is the poster maker's output, the third is the printable button's output.
| Input | Poster maker | Printable button |
|---|---|---|
| Złota Kaczka | Zota Kaczka | Z?ota Kaczka |
| Pod Żółwiem | Pod ówiem | Pod Zó?wiem |
| Őrmester Kocsma | rmester Kocsma | Ormester Kocsma |
| Fűszeres Étterem | Fszeres Étterem | Fuszeres Étterem |
| Hospůdka U Řeky | Hospdka U eky | Hospudka U Reky |
| Şişli Meyhanesi | ili Meyhanesi | Sisli Meyhanesi |
| Crâșma Veche | Crâma Veche | Crâsma Veche |
| La Țuică | La uic | La Tuica |
| Y Ddraig Wŷr | Y Ddraig Wr | Y Ddraig Wyr |
| Pivnica Ľudová | Pivnica udová | Pivnica Ludová |
| Konoba Šime & Đuro | Konoba Šime & uro | Konoba Sime & ?uro |
| Ο Κήπος | (empty) | ? ????? |
| The Pig 🐷 & Whistle | The Pig & Whistle | The Pig ?? & Whistle |
| Café de l’Œuf | Café de l’Œuf | Café de l'?uf |
Eleven more names are not in the table because the poster maker leaves them alone: Þórshamar, Ølhuset, Källaren, Zum goldenen Löwen, An Caisleán, El Rincón del Ñu, O Pátio Açoriano, Pub Åland, Çiçek Pub, U Zlatého tygra and "Joe's Place - Trivia" with a curly apostrophe and an en dash (the printable button straightens both). Counting the Café name, 12 of the 25 come through the poster maker unchanged and 13 do not.
What the deleting version does to a name
Delete is the worse policy for a proper noun, and the table shows why. Three effects:
- The name still looks like a name. "Hospdka U eky" is not obviously broken to someone who does not speak Czech. It is wrong the way a typo is wrong, and the person who typed it will see the correct version in their own input box, because the input keeps what they typed.
-
It can change what a word means. Dropping the letters of "Pod Żółwiem" leaves "Pod ówiem", which is nothing. Dropping
Łfrom a name leaves a shorter word that might be another word. - It can empty a field. An all-Greek venue name sanitises to a single space, which the clamp then trims to an empty string.
Transliterating is kinder, and the printable button's Őrmester to Ormester is how a human would hand-write it on an English-keyboard poster. But it only works for letters that decompose. ł, đ and ș do not decompose in Unicode, so they fall through to ?, which is arguably the more honest of the two failures.
Check it on the live page
The input box keeps what you type, and the preview does the dropping. Reproduce it:
- Open the poster maker.
- Click into "Venue name" and type
Hospůdka U Řeky. - Look at the big poster preview. I read the text nodes out of the SVG and got
Hospdka U eky, while the input still containedHospůdka U Řeky.
Nothing on the page says a character was removed. I searched the component and the page source for any message about accents, Latin or unsupported characters and found none.
The preview and the download are drawn from the same layout, so what you see is what the PDF prints. The preview is honest about the PDF. It is not honest about your input.
The test that pins the behaviour
The poster maker's test suite does cover it:
expect(sanitiseText('£2 or €3 🍺 entry')).toBe('£2 or €3 entry')
The expected string has two spaces where the beer was. So the suite pins the dropping and also pins the leftover double space as correct. It checks that pounds and euros survive and that emoji do not. It has no case with a diacritic, which is the case a visitor in Prague or Istanbul types first.
Why two cleaners exist
Not carelessness. The poster tool sanitises fields at clamp time so that the layout engine never measures a glyph it cannot draw. The printable button sanitises at draw time because its text comes from our own question library, which is written in English and almost never needs it. Different inputs, different assumptions. The mistake is that neither assumption is stated where a third tool would find it.
What I would do
- One cleaner, one policy. Move the sanitiser into one module with a documented rule: transliterate where Unicode can, otherwise replace with a visible mark, never delete.
- Tell the person. When the cleaner changes a field, show a line under it: "Some characters can't be printed and were changed." Ten lines of UI.
- Embed a font that has the letters. jsPDF can embed a TTF. A Latin Extended font would remove the problem rather than manage it, at the cost of 30 to 100 KB loaded only when the visitor presses Download.
-
Add the Prague case to the test.
sanitiseText('Hospůdka')should be on the list.
Until then, if your venue's name has a diacritic outside Latin-1, check the preview before you print. The tool is free, runs in the browser and does not need an account. If you are planning a night rather than a poster, pub-trivia.app has a free tier with no card.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.