rupee symbol is not coming in pdf

36 views
Skip to first unread message

prashant kumar

unread,
Aug 12, 2024, 11:29:12 AM8/12/24
to Flying Saucer Users
using:
flying-saucer-pdf: 9.9.0
I am converting html to pdf using thymeleaf and flying-saucer.
Flying-saucer is not able render rupee(₹) symbol in the pdf.
html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>PDF Report</title>
<style>
@font-face {
font-family: 'DejaVu Sans';
src: url('src/main/resources/templates/DejaVuSans.ttf') format('truetype');
}
body {
font-family: 'DejaVu Sans', sans-serif;
}
</style>
</head>
<body>
<h1 th:text="${title}">Title</h1>
<p th:text="'' + ${content}">Content</p>
</body>
</html>

pdfService:
Context context = new Context();
context.setVariable("invoice", invoice);

String htmlContent = templateEngine.process("invoice", context);
// log.info("html content {}", htmlContent);
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("src/main/resources/templates/coolvetica.rg-regular.otf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(outputStream);
return outputStream.toByteArray();


I have tried with verdana, Montserrat, coolvetica and dejaVu. but none of the fonts worked.
Please help.

Neil Morrison

unread,
Aug 12, 2024, 3:32:45 PM8/12/24
to flying-sa...@googlegroups.com
A few things (others can correct me if wrong) but PDFs by default only support certain fonts and can will use fonts from a device when viewed if available, otherwise it will fall back onto it's standard ones.

So, maybe try the following:
- check the generated PDF actually has the font embedded (document properties in Adobe)
- check the font hasn't been corrupted by maven (looks like maven based on your resources). Maven projects often have a resources section defined where the files are filtered. Make sure to have filtering turned off or the font will become corrupt.

Regards,

Neil



--
You received this message because you are subscribed to the Google Groups "Flying Saucer Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flying-saucer-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flying-saucer-users/8fba36e6-4ed4-4cb4-a424-5f4b031143dfn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages