Jump to content
Changes to the Jaspersoft community edition download ×

Displaying Html code


2006 IR Open Dicussion

Recommended Posts

By: Manfred Cerny - zephyrfredi

Displaying Html code

2006-06-22 01:34

Hi all,

 

I have a Problem using iReport and JR. I need to display html code in a text field object.

The html content will be received through a Field. I've tried it already with the "Is styled text" attribute but this doesn't work.

 

I would be very happy if anyone knows a solution.

 

Thanks

Fredi

Link to comment
Share on other sites

  • 4 weeks later...
  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

I don't think the <input type=....> tags are supported for data fields. Atleast the samples don't show it.

 

jasperreports-1.2.7demosamplesstyledtext

 

Instead, you could use shapes around the data(a transperant rectangle maybe) and make it look like it is a textfield.

Link to comment
Share on other sites

  • 3 weeks later...

yes, somewhere it is stated that Jasper reports allows you to report 'virtually any data format', well how about html?

nope, it would seem that you cannot use Jasper to output your html text stored in your db - i've been tearing my hair out with this one and all I got with 1.2.4 was the text complete with all it's tags (isStyledText setting made no difference), now with version 1.2.7 it's worse, all I get is: 'net.sourceforge.jtds.jdbc.ClobImpl@faa03e' appearing instead of the text field.

If anyone has any idea how to solve this I'd be delighted.

Link to comment
Share on other sites

  • 2 weeks later...

I'm not sure whether this is still open... Or whether you guys have found an acceptable work-around.

But this is a feature I would very much appreciate... So if anyone has any insight I would appreciate some assistance.

 

 

Here's what I've discovered so far:

 

 

1. "Is Styled Text" does work for a [very] limited set of HTML tags [see:http://jasperreports.sourceforge.net/samples/StyledTextReport.html

]

 

 

2. If the text contains ANY HTML tags that aren't supported then the whole HTML file [text] is displayed with the HTML tags visible [i.e. not rendered]

 

 

3. Even when you use only the supported HTML tags, tags such as <LI>Point #1</LI> have three addition <BR/> after them resulting in excessive white space.

 

 

4. For the fun of it all the HTML tags must be Upper-Case else they are not recognized [see point #2]

 

 

5. I have simple HTML [generated by MS Word] hence plugging this little snippet of code into the expression field removes all the unrecognized HTML tags. [Modify as needed.. but there REALLY should be a better way… this is just painful :sick:]

 

Code:

/*This removes all the html tags not supported by iReports 1.2.7*/
$F{document}.substring( $F{document}.indexOf( "<body lang=EN-US>" )+17, $F{document}.length() )
.replaceAll( "</html>", ""«»).replaceAll("</body>",""«»)
.replaceAll($F{document}.substring( $F{document}.indexOf( "class=" )-1,
$F{document}.indexOf( ">", $F{document}.indexOf( "class=" ) ) ),""«»)
.replaceAll("<p class=MsoNormal>",""«»).replaceAll("</p>",""«»)
.replaceAll("<div>",""«»).replaceAll("</div>",""«»)
.replaceAll("<b>","<B>"«»).replaceAll("</b>","</B>"«»)
.replaceAll("<u>","<U>"«»).replaceAll("</u>","</U>"«»)
.replaceAll("<i>","<I>"«»).replaceAll("</i>","</I>"«»)
.replaceAll("<li>","<LI>"«»).replaceAll("</li>","</LI>"«»)
.replaceAll("<OL>",""«»).replaceAll("</OL>",""«»)
.replaceAll("<span style='color:","<style forecolor='"«»).replaceAll("</span>","</style>"«»)
.replaceAll(" ",""«»).replaceAll("'","""«»)

 

Let me know what you have come up with so far!

Happy coding

NiPo..

Link to comment
Share on other sites

  • 2 months later...

I have the same need - render HTML stored within a database field. This topic comes up quite a bit in the forums but I've not seen a definitive answer.

 

Styled text seems too limited for general use.

 

Anyone find a work around, solution or other options?

 

I'm assuming the various output formats are what makes this challenging.

Post edited by: eric_jama, at: 2007/01/31 04:20

Link to comment
Share on other sites

  • 2 months later...

I’d like to resurrect this issue…

 

 

I have a db field that contains HTML that needs to be included in a report.

 

 

The ‘Is Styled Text’ only handles a very small sub-set of HTML tags and as soon as an unhandled tag is encountered rendering of the HTML fails resulting in the HTML tags being printed in the report.

 

 

Does anyone have a work around?

Does anyone know of any plans to incorporate full HTML support into iReport?

 

 

Many thanks

Nigel.

Link to comment
Share on other sites

  • 1 month later...

Hi!

 

I'm with the same problem. Considering that source code HTML can contain differents tags and that it is impracticable to foresee all they, it can be easier to select in the original code tags that they are interpreted by the Jasper. What you think?

 

 

Thanks!!

Joseane

Link to comment
Share on other sites

  • 1 month later...

Right now the only workaround is to write a scriptlet to handle the formatting of HTML tags... For example:

 

public String checkForAmps(String field){

String replacement = "";

 

if (field.contains("&")){

replacement += field.replaceAll("&", "& amp;" );

}

else if (field.contains("<")){

replacement += field.replaceAll("<", "& lt;" );

}

else if (field.contains("<&")){

replacement += field.replaceAll("<&", "& lt;& amp;" );

}

else if (field.contains(">")){

replacement += field.replaceAll(">", "& gt;" );

}

else if ((field.contains("&") == false) ||

(field.contains("<&") == false)||

(field.contains("<") == false) ||

(field.contains(">") == false)){

replacement += field;

}

 

return replacement;

 

}

 

I have this written inside of my scriptlet editor to handle returned data(from my db) that contains html. Also, there are only the options that are displayed on the /samples/styledtext demo that can be used to format html. Tags like <p> and </br> aren't supported.

 

Note: The above bolded text is not the correct html syntax, I had to add space for it to display correctly inside of THIS forum. remove the spaces after the & and it should work fine.

Link to comment
Share on other sites

  • 7 months later...

Hi,

 

A new text element attribute called "markup" was added to support embedding text snippets that contain style information in RTF of HTML format.

 

The former isStyledText boolean attribute was deprecated and is now equivalent to markup="styled".

 

All the modification are committed to SVN and will be part of the next release. A new sample /demo/samples/markup was added to show this new feature.

 

Thank you,

Teodor

Link to comment
Share on other sites

  • 2 years later...

hI

On version 4 of ireport has HTML support for very basic tags but TAGS like <table> are not supported. Is there a plan to support the render of html tables on IReports?. Or there's a pluggin or programatically i can do this on this version.

 

Thanks for your help.

 

Grettings form Ecuador....Encoding in the middle of the world ;)

Link to comment
Share on other sites

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...