Different format of text within a single paragraph

0
I am working on a single page report, which looks like a letter when it is generated. I have a number of paragraphs of text. Inside one of the paragraphs I have a sentance which I need to bold. Is this possible?

e.g.

This is one paragraph

This is a sentence. This is a sentance. This is a sentance. This is a bold sentance. This is the last sentance.

This is another paragraph.
rclarke88's picture
Joined: Apr 17 2007 - 6:11pm
Last seen: 12 years 9 months ago

10 Answers:

0
In the properties of your text field or static text element, set isStyledText = true.
Edit your text as follows (note sentence with style tags):

This is paragraph_1. This is sentence_2 of paragraph_1. This is sentence_3 of paragraph_1.

This is paragraph_2. This is sentence_2 of paragraph_2. <style isBold="true">This is a boldface sentence in paragraph_2.</style> This is sentence_3 of paragraph_2.

You could also use the html <b> and </b> tags in place of the style tags but it is not recommended.
redwine's picture
185
Joined: Mar 7 2007 - 1:25am
Last seen: 12 years 11 months ago
0
Thanks edwin for pointing me in the right direction. But, it does not seem to be working for me :(

I found the isStyledText tick box for this static text field, and ticked it. I tried using a <style> and <b> tags, but neither came out bold when compiling in iReports.

I tried this for a text field (non-static) and found no difference.

Here is the staticText element which iReport creates for this particular paragraph:

Code:
<staticText><br />
	<reportElement<br />
		x="0"<br />
		y="158"<br />
		width="535"<br />
		height="86"<br />
		key="staticText-4"/><br />
	<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/><br />
	<textElement isStyledText="true"><br />
		<font/><br />
	</textElement><br />
<text><![CDATA[This is one sentance. <style isBold="true">This is a bold sentance.</style> This is another normal sentance.]]></text><br />
</staticText></td></tr></tbody></table><br />
<br />
Does the XML look correct to you?
rclarke88's picture
Joined: Apr 17 2007 - 6:11pm
Last seen: 12 years 9 months ago
0
rclarke88,

For some reason, isBold and isItalic don't work in the textField or the staticText elements. The funny thing is that isUnderline works in both of them.
One workaround is to use the pdfFontName attribute instead of the isBold attribute. Since you are currently using Helvetica use this inside your style tag:
pdfFontName="Helvetica-Bold"

I tested this and use this on a regular basis so I know it would work on either textField or staticText elements.

Below are some of the attribute values that you can use:
pdfFontName
Indicates the name of the font to use if the report is exported to PDF.
Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique,
Helvetica, Helvetica Bold, Helvetica BoldOblique, Helvetica Oblique,
Times-Roman, Times-Bold, Times-BoldItalic, Times-Italic,
Symbol, ZapfDingbats
Source:
JasperReports for Java Developers
2006 Packt Publishing
page 121

Just note that the formatting will only be seen in a pdf document.


If you plan to display your report on the web (I have not done this yet), I'm thinking you should use a different attribute.

I will need to post this bug that you found so the developers could fix it.
I didn't realize that this attribute didn't work.
I'll give you a thumbs up to add to your karma for your discovery.
Cool?
Do tell me how it goes, ok?


Edwin
Post edited by: edwin, at: 2007/05/08 17:25
redwine's picture
185
Joined: Mar 7 2007 - 1:25am
Last seen: 12 years 11 months ago
0
Using the pdfFontName attribute worked! This work around should be sufficient for us (I am just using the default font anyway) as we are not generating web reports.

Thank you edwin for looking into this for a beginner!
rclarke88's picture
Joined: Apr 17 2007 - 6:11pm
Last seen: 12 years 9 months ago
0
Using the pdfFontName attribute worked! This work around should be sufficient for us (I am just using the default font anyway) as we are not generating web reports.

Thank you edwin for looking into this for a beginner!
rclarke88's picture
Joined: Apr 17 2007 - 6:11pm
Last seen: 12 years 9 months ago
0
In iReport if we checked the isstyle means that will apply for all text in paragraph na? then how can i use for particular sentence...i am using ireport-1.2.7..can i know how can i use <font>..</font? tag in report
burasami's picture
Joined: Oct 15 2006 - 8:53pm
Last seen: 13 years 3 months ago
0
burasami,

For the sake of discussion, let's say you have a text element called Text1. That element can either be a TextField or StaticText that contains some amount of.... text. :)
If the Is styled text property for Text1 is checked, it will make all the text in that element ready for styling. This means that you can style different parts of the text inside Text1 or you can just leave everything as they are without any styling... no harm done here. Just remember to enclose all the text that you want to style within <style> </style> tags that have the needed attributes defined in the opening tag. You can enclose as much text as you want or none at all (for whatever purpose that may serve). As I have said, you also can style different parts of text, enclosing each part/segment of text in the style tags.

Just like checking the Is styled text property , checking the other text formatting options for Text1 will also apply to all the text within it. But unlike the Is styled text property , they are "less flexible"... if you check the Bold property it will make ALL the text bold... this is useful if you intend to make everything in Text1 boldfaced. You could also do this by enclosing everything in Text1 in style tags but checking the property would save you some typing time.

Also remember that style tags will override any formatting property checked.
Also, nested style tags will override outer style tags.

To give you a good idea of this, taka a look at the attached .jrxml file and modify it as you wish.
Also check out this previous post about text formatting in this thread.

Have fun!
redwine's picture
185
Joined: Mar 7 2007 - 1:25am
Last seen: 12 years 11 months ago
0

This did not work for me

<textElement textAlignment="Center" verticalAlignment="Middle" isStyledText="true">
      <font fontName="Times New Roman" pdfFontName="Times-Bold" size="12" isBold="true" isItalic="false"/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[(<style pdfFontName="Times-Bold"> "From " </style> + new SimpleDateFormat("MM/dd/yyyy").format($F{start_date})+ " - " + new SimpleDateFormat("MM/dd/yyyy").format($F{last_date_included}))]]></textFieldExpression>
    </textField>

 

Nor did this

 

<textElement textAlignment="Center" verticalAlignment="Middle" isStyledText="true">
      <font fontName="Times New Roman" pdfFontName="Times-Bold" size="12" isBold="true" isItalic="false"/>
     </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[<style isItalic ="true"> "From " </style> + new SimpleDateFormat("MM/dd/yyyy").format($F{start_date})+ " - " + new SimpleDateFormat("MM/dd/yyyy").format($F{last_date_included})]]></textFieldExpression>
    </textField>

How can i italized my text



Post Edited by andell78 at 05/19/2009 20:29
andell78's picture
Joined: Apr 26 2007 - 12:54am
Last seen: 4 years 11 months ago
0

I was able to use isItalic with the pdfFontName="Times-Italic" to have my report display in a pdf format. Now that I need to have it publish to the web in pdf using the jasper file the entire script is being displayed <style isItalic="true"
pdfFontName="Times-Italic">Some text here</style>. Do you know what attribute needs to be used to have the text displayed in  italic for the web?

andell78's picture
Joined: Apr 26 2007 - 12:54am
Last seen: 4 years 11 months ago
0

Hi guys I have tried with jasper report 2.0.0 and I had sucess,

but I was trying to do the same with jasper 3.7.4, but I can't find the property isStyledText in ireport 3.7.4.

 

Can some one help me with this.

 

pepevasc's picture
Joined: Feb 7 2011 - 8:10am
Last seen: 7 months 2 weeks ago
Feedback
randomness