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

How to rotate a text field by 45 degrees?


bhavya_s

Recommended Posts

Hi All,

 

I need to rotate a text field by 45 degrees. Using iReport, I could rotate the text to left, right or upside down i.e., i could rotate the text by 90 degrees or by 360 degrees but could not rotate the text by 45 degrees.

 

Is it possible to have a text at an angle of 45 degrees in Jasper Reports? If so, please let me know how to do it.

 

Thanks in advance,

Bhavya

 

 

Link to comment
Share on other sites

  • 1 year later...
  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Not an ideal solution, but you could write a helper class in java that creates a image with the text rotated. You could do it as a scriptlet I guess, I prefer a standalone java utility as I could get more mileage from it.
Link to comment
Share on other sites

  • 7 months later...

I have a requirement for rotating text and images by 15 degrees, so that certain elements are slanted.

I've done a search on the forums and seen plenty of discussions on the ability to rotate text by 90, 180 and 270, but I've not seen any example or solution to being able to print text/images at an arbitary angle.  Any ideas would be welcome.

As I'm not an expert in Java, I've not seen any example of how to pass a field into a java image rendering function to create a java.awt.Image object, and I'm not sure how to fit this into iReport.

Thanks

 

Link to comment
Share on other sites

  • 1 year later...

Hi guys. After reading that thread I wrote a scriptlet for rotation of text. It works quite nice, even if the scriptlet seems to find no Open Type Fonts and some character parts appear a little pixilated (although I used antialiasing). But its good enough that our customer will use it for 10.000 prints per month. The code is long only because of a text wrapping algorithm. Tell me if you need a version without wrapping.

After registering the class in classpath (e.g. via the jar archive I have attached: In iReport Extras/Options/iReport/Classpath/Add JAR) all you have to do in layout is the following:

1. Add attribute:

<jasperReport ...  scriptletClass="RotateTextScriptlet" ... >

2. use it in image element. Example:

            <image scaleImage="RealSize" hAlign="Center" vAlign="Middle">
                <reportElement x="26" y="16" width="162" height="162"/>
                <imageExpression class="java.awt.Image"><![CDATA[$P{REPORT_SCRIPTLET}.rotateText(
    $V{SpecialDescription},new java.awt.Font("Sans Serif",1,100), 365, 365, 350, java.awt.Color.white)]]></imageExpression>
            </image>

Note: The image must lead to the java interface type "java.awt.Image" and not "java.lang.String", which is used when referring to an image file. The scriptlet returns an image implementing that interface.

I hope this will help you out!

PS: For any RGB Colors of the text use "new java.awt.Color(R,G,B)" instead of "java.awt.Color.white" which is a constant. Any value can be 0 to 255, so "java.awt.Color.white" is the same like "new java.awt.Color(255,255,255)"

RotateTextScriptlet.java:



Post Edited by artduc at 07/18/2012 10:03



Post Edited by artduc at 07/18/2012 10:04



Post Edited by artduc at 07/18/2012 10:14



Post Edited by artduc at 07/18/2012 10:18
Link to comment
Share on other sites

  • 2 years later...

I don't know if this post is still active but if it is, Could you help me with this .jar file? I have problems understanding completely the way this is implemented in iReport. I'm using iReport 5.5.0, I tried to attach it and then try it out on an image element but I get this error:

"com.jaspersoft.ireport.designer.errorhandler.ProblemItem@12ff416 The method rotateText(String, Font, int, int, int, Color) is undefined for the type String"

 

Thanks.

Link to comment
Share on other sites

  • 2 years later...
  • 4 months later...

Another way to do this is with an Image and an ImageExpression with SVG.

net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText("<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="765" height="990"><text x="60" y="40" transform="matrix(.6,.8,-.8,.6,0,0)" style="font-size:140px;font-weight:bold;fill:#d8d8d8">$F{my_text_field}</text></svg>")[/code]

 

Link to comment
Share on other sites

  • 1 month later...

Thanks to Circuitsoft, I add this to my jrxml:

<background>

<band height="842" splitType="Stretch">

<image>

<reportElement x="20" y="0" width="511" height="830" uuid="d5d7a19d-060a-4875-954b-e176ab96898a"/>

<imageExpression><![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText("<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="765" height="990"><text x="60" y="40" transform="matrix(.6,.8,-.8,.6,0,0)" style="font-size:140px;font-weight:bold;fill:#d8d8d8">DRAFT</text></svg>")]]></imageExpression>

</image>

</band>

</background>

 

 

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