Reputation: 279
I am using code to generate PDF file from Thymeleaf HTML template from this website [Convert Thymeleaf to PDF][1].
I am getting very nice PDF but facing one minor issue. I am showing price of products in PDF for multiple currency and using this reference website [currency symbols with Unicode(Hex)][1] to get Unicode (Hex) value for different currency.
Following is my .java file code
context.setVariable("currencySymbol","₹"); // this is Unicode for Indian rupee sysmbol
following is my thymeleaf template code
<td th:utext="${currencySymbol} + ' ' + ${#numbers.formatDecimal(product.price, 0, 'COMMA', 2, 'POINT')}"> </td>
it is working fine and showing currency symbols for all, except Indian Rupee and United Arab Emirates Dirham.
Please suggest me how can I display Indian Rupee and United Arab Emirates Dirham currency Symbols in my Generated PDF.
Thanks in Advance.
**Note :- If is there any new way to generate PDF from HTML Thymeleaf template, please inform me **
Upvotes: 1
Views: 1684
Reputation: 9356
The issue is that the font used by default doesn't support the characters you want to print. To make it work, you can embed another font which can display this character, for example DejaVu.
You must first download the DejaVu font file, then declare this font in your java class:
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("font/dejavu-sans/DEJAVUSANS.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
And use this font in your HTML document, for example with:
td {font-family: DejaVu Sans;}
Upvotes: 1