Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold style doesn't work in pdf output

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?

like image 352
Skizzo Avatar asked Oct 11 '13 09:10

Skizzo


People also ask

Why is bold not working in PDF?

When you choose the style of the word, DO NOT just make it bold, you have to change the font name from "CMU Serif" to "CMU Serif Bold" (if you can't find this "CMU Serif Bold" font in the drop down menu, you can type it). Then save the word as pdf, Your pdf should display bold font correctly now, this solved my issue.

How do I print bold in PDF?

The steps of how to make text bold in PDF In order to write bold text inside PDF, you can go to the "Text" menu, click the "Add Text" button to add new text to the PDF file, then you can click on the "Bold" button to write bold text inside PDF.

How do I set up bold print?

in the Font group on the Home tab. Type the keyboard shortcut: CTRL+B.

Why does my font change in PDF?

1. Fonts are not available on your operating system. If the fonts in a PDF file aren't available on your computer, Lighten PDF Converter is not able to preserve the original font. For example, if the PDF author purchased commercial fonts and use it in PDF, which is not available in your font book.


2 Answers

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

like image 73
Daniela Avatar answered Oct 18 '22 15:10

Daniela


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>
like image 40
Miklos Avatar answered Oct 18 '22 17:10

Miklos