Bold style not appearing in pdf output

3
In my version of Jasper reports (from 2/28/06), the bold style is not appearing in pdf output. If I have stylized text (for example, "<b>This</b> should be <b>bold</b>"), the bold parts appear bold in the jasper 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>.
Does Jasper support stylized bold markup in pdf output? Am I just missing something here?
adepue's picture
20
Joined: Jul 20 2006 - 2:21am
Last seen: 12 years 10 months ago

12 Answers:

1
Hi,

Yes, you are missing the font mappings that need to be passed to the exporter using the FONT_MAP exporter parameter.
You can see this being used inside our /demo/samples/styledtext sample provided with the project.

I hope this helps.
Teodor
teodord's picture
4201
Joined: Jun 30 2006 - 9:00am
Last seen: 1 week 4 days ago
0
Ah ha, that's really good to know. Thanks!
adepue's picture
20
Joined: Jul 20 2006 - 2:21am
Last seen: 12 years 10 months ago
0

Hi Teodor,

Does JasperReport 1.1.0 support this feature?

I have added FONT_MAP parameter to PDF exporter - did not help.

I think this is because PdfFont class does not have 2 new extra attributes:

  •                boolean isPdfSimulatedBold
  •                boolean isPdfSimulatedItalic

Is there any other way in this version to tell to PDF exporter about stylized text markup ?

 

Thank you

Code:
JRPdfExporter exporter = new JRPdfExporter();
 
FontKey keyArial = new FontKey("Arial", false, false);  
PdfFont fontArial = new PdfFont("Helvetica","Cp1252",false); 
 
FontKey keyArialBold = new FontKey("Arial", true, false);  
PdfFont fontArialBold = new PdfFont("Helvetica-Bold","Cp1252",false); 
 
Map fontMap = new HashMap();
fontMap.put(keyArial,fontArial);
fontMap.put(keyArialBold,fontArialBold);
 
exporter.setParameter(JRExporterParameter.FONT_MAP,fontMap);
</td></tr></tbody></table>
gfeldman's picture
Joined: Apr 24 2009 - 2:15pm
Last seen: 10 years 3 weeks ago
0

Hi,

 

JR 1.1.0 is now too old. Please consider upgrading.

 

Thank you,

Teodor

 

teodord's picture
4201
Joined: Jun 30 2006 - 9:00am
Last seen: 1 week 4 days ago
0

 Ok, this thread is old, but i still have the issue:

I upgraded from jasper-reports 2.0.5 to 3.7.1, and started updating the jrxmls. before i uses to use pdfFontName="Helvetica-Bold" to get the bold effect, but now i am using only isBold="True".

in iReport the preview is ok, but printing from the web application i get no bold at all.

what should i do to enable the isBold on the default Helvetica font? FONT_MAP is old as many writes in this forum.... is there a ready font-extgension for helvetica fonts?

hopesolutions's picture
Joined: Mar 17 2008 - 9:01pm
Last seen: 11 years 2 months ago
0

Pdf Embedded mode was turned on?

<font fontName="Arial" pdfFontName="arialbd.ttf" isPdfEmbedded="true"/>

In my sample, html report file will be in Arial font and normal style. But in pdf file, it displayed in bold style.

Remember copy arialbd.tff font to your application class path.

Đức, Trần Minh ductm@fpt.com.vn

minhduc's picture
13
Joined: Mar 31 2010 - 11:57pm
Last seen: 9 years 1 month ago
0
I want to stay away from the arial font and embedding.
the question is how does iReport 3.7.1 work with just:
<font isBold="true" />

while when in application it doesn't? does ireport pass extra params/maps? use extra libraries?
hopesolutions's picture
Joined: Mar 17 2008 - 9:01pm
Last seen: 11 years 2 months ago
0

@hopesolutions:

Nothing extra library need here.

In font tag, fontName, isBold, isItalic or isUnderline property are not useful for pdf report exporter.

In pdf report , the text style depend on the font filename.

Example: If you want the text in pdf report file in Arial and :

- Bold: pdfFontName="arialbd.ttf"

- Italic: pdfFontName="ariali.ttf"

...

make sure isPdfEmbedded="true" and embeded fonts were on your classpath application

<font pdfFontName="arialbd.ttf" isPdfEmbedded="true"/>

 

Đức, Trần Minh ductm@fpt.com.vn



Post Edited by minhduc at 04/01/2010 11:17
minhduc's picture
13
Joined: Mar 31 2010 - 11:57pm
Last seen: 9 years 1 month ago
0

I might have fixed the issue by making a font extension to map standard SansSerif font to Arial, with nothing to change in current reports, just put the jar in the application folder and printing shows bold with only isBold....

Code:
<bean id="fontSansSerifFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
  <property name="name" value="SansSerif"/>
  <property name="normal" value="fonts/arial.ttf"/>
  <property name="bold" value="fonts/arialbd.ttf"/>
  <property name="italic" value="fonts/ariali.ttf"/>
  <property name="boldItalic" value="fonts/arialbi.ttf"/>
  <property name="pdfEmbedded" value="false"/>
</bean></td></tr></tbody></table><br><br>Post Edited by hopesolutions at 04/01/2010 13:39
hopesolutions's picture
Joined: Mar 17 2008 - 9:01pm
Last seen: 11 years 2 months ago
0

The solution provided by "hopesolutions" works fine!

I added to the java classpath ( /WEB-INF/classes ):

1) jasperreports_extension.properties:
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts.xml

2) fonts.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
 <bean id="fontSansSerifFamily" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
  <property name="name" value="SansSerif"/>
  <property name="normal" value="fonts/arial.ttf"/>
  <property name="bold" value="fonts/arialbd.ttf"/>
  <property name="italic" value="fonts/ariali.ttf"/>
  <property name="boldItalic" value="fonts/arialbi.ttf"/>
  <property name="pdfEmbedded" value="false"/>
 </bean>
</beans>

3) "fonts" folder containing these fonts:
arial.ttf
arialbd.ttf
arialbi.ttf
ariali.ttf

Hope this helps!
Marco

marco159's picture
Joined: Oct 20 2009 - 3:32am
Last seen: 9 years 7 months ago
0

Hi,

Do i need to change the jrxml or the exporter?

I tried making a jar out of the components you suggested and got the jar in my classpath, yet isBold is not working for me.

inimish's picture
Joined: Aug 27 2010 - 1:41am
Last seen: 8 years 8 months ago
4
I had similar problem, in iReport preview was ok, but generated pdf had no any bold styles either font extension nor iReport/JasperReports library settings didn't help.
 
In my case it was enough to add one extra dependency and it helped.
 
There is a short description in below post:
 
maxio89's picture
52
Joined: Jul 16 2012 - 2:36am
Last seen: 5 years 5 months ago

Thank you so much! This really helped me.

sanfinns - 4 years 4 months ago

Thank you!

reeeval - 3 years 10 months ago
Feedback
randomness