Hi All,
I’m trying to render a pdf that includes non-Latin / ASCII text.
I have a data grid on a blank panel form which is populated from a data table, and produces a two column pdf with latin characters in one column and non latin in the other.
The Anvil.pdf function itself works really well - looks exactly as I want it to look - but the non-ASCII text is not supported.
Is there any way to config the output further using anvil.pdf e.g reference a custom web font in CSS?
It looks like this is a fairly common issue with pdf rendering ,and I think there’s probably an ‘uplink solution’ where you render from CSV locally using a downloaded .tff font and filepath to asset in fonts.
But I really like the Anvil.pdf result and would like to replicate it as closely / simply as possible.
Anyone have any ideas or experience around this?
Thanks.
This doesn’t tell us what is happening. Without specifics, there’s no diagnosis possible. So I’m just going to suggest a few things.
Since Unicode (in UTF-8 encoding) is the Internet standard these days, I would expect Anvil’s PDF features to work just fine if the non-ASCII characters are encoded in UTF-8 format.
If they’re in some other format (e.g., an 8-bit character set), then I would expect error messages or other effects.
So, check your text’s encoding. Visual inspection isn’t reliable, but you can automate. I use chardet to identify the encoding of any text that is suspect. (CSV files are notorious for hidden encoding problems, since they don’t have a way to specify which character encoding was used to write them.)
Then I use Python’s standard library to convert it to Unicode. (For use with Python and SQLite, which also assume a Unicode encoding.)
I haven’t tried this approach for PDF generation, but it sure seems to me like a similar problem, so maybe the solution is similar, too.
2 Likes
Fixed it. In the end the solution was to experiment with different fonts in CSS/Native Libraries - a different font in the same Noto Sans family worked whereas the original didn’t. The PDF renderer will work through the list of installed fonts so if a font works just include it in the list. Logically encoding did seem like the issue, and I did look into that. An encoding checker if anyone ever needs something along those lines: Anvil | Login
Can’t see my initial reply to you in the thread. Looked into the encoding/chardet - will come in useful. Thanks.