6

I'm building a few report using iReport 5.1.0 and JasperReports 5.0.0. Now my trouble is that bold style is not appearing in pdf output. If I have stylized text (for example, "<b>My Text</b>"), the bold parts appear bold in the report's output, but not in the pdf. The only way I can get bold in pdf is to force the pdf font for that element to be a bold font (pdfFontName="Helvetica-Bold" for example), but that bolds the entire string and does not allow me to control it via the style markup <b>.

I'm exporting the pdf file in this way:

JRPdfExporter exp = new JRPdfExporter();
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, namefileToExport);
exp.exportReport();

How can I do?

Daniela
  • 471
  • 7
  • 25
Skizzo
  • 2,883
  • 8
  • 52
  • 99

3 Answers3

7

https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports-fonts/6.0.0

<!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports-fonts -->
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>6.0.0</version>
</dependency>

adding this dependency to the pom.xml should be enough to fix the problem

Daniela
  • 471
  • 7
  • 25
2

I have just had the same problem only I used styled markup, not html and this solution helped me.

I only added these 4 lines before generating the report to embed fonts into pdf:

DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.default.font.name", "DejaVu Sans");
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.default.pdf.embedded", "true");
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.default.pdf.font.name", "DejaVu Sans");

And then added a new dependency to the maven configuration:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports-fonts</artifactId>
    <version>4.0.0</version>
</dependency>
Miklos
  • 102
  • 2
  • 8
-1

In your text field select markup as html and write your text like this.

"<b>" + "My" + "</b>" + "Text"

For install new font you can follow this link. install new font

Community
  • 1
  • 1
user1791574
  • 1,729
  • 2
  • 16
  • 30