Jump to content
We've recently updated our Privacy Statement, available here ×

Different format of text within a single paragraph


rclarke88

Recommended Posts

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.

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

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.

Link to comment
Share on other sites

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>
<reportElement
x="0"
y="158"
width="535"
height="86"
key="staticText-4"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement isStyledText="true">
<font/>
</textElement>
<text><![CDATA[This is one sentance. <style isBold="true">This is a bold sentance.</style> This is another normal sentance.]]></text>
</staticText>

 

Does the XML look correct to you?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 2 weeks later...

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!

Link to comment
Share on other sites

  • 2 years later...

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
Link to comment
Share on other sites

  • 5 months later...

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?

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...