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

How to use SVG information in Jasper Report?


marco.giudici

Recommended Posts

Hi all,

I'm new in this community and I have create a Jasper-Report with a lot of text field and for the moment all works fine.

Now I have the necessity to integrate a SVG field to rappresent a drawing, but I don't understand how to use/configure this type of thing. I use SVG field to show a drawing when I have the information to plot it

I work with Java with IDE Eclipse Juno 3.8 and Jasperstudio 5.5.2.

First question is : when I haven't this information to create SVG data, how can manage the corrisponding parameter in Jasper-Report?

Second question is : in my application the SVG data is defined as String, how can manage it in the corrisponding paramert in Jasper-Report?

This is an example of my SVG string:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg viewBox="0 0 900 250" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" version="1.1" xml:space="preserve" preserveAspectRatio="xMidYMid meet"> <line x1="10.0" y1="55.354330708" x2="195.196850391" y2="55.354330708" style="stroke:red;stroke-width:1" /><line x1="102.5984251955" y1="10.0" x2="102.5984251955" y2="100.708661416" style="stroke:red;stroke-width:1" /><circle cx="102.5984251955" cy="55.354330708" r="1" stroke="red" stroke-width="1" /><line x1="122.165354329" y1="55.354330708" x2="132.165354329" y2="55.354330708" style="stroke:green;stroke-width:1" /><line x1="127.165354329" y1="50.354330708" x2="127.165354329" y2="60.354330708" style="stroke:green;stroke-width:1" /><circle cx="192.67343983190142" cy="39.47167533989254" r="1" stroke="black" stroke-width="1" /><circle cx="193.51923562108152" cy="22.26186203772813" r="1" stroke="black" stroke-width="1" /><circle cx="175.5900466283618" cy="13.212598425150006" r="1" stroke="black" stroke-width="1" /><circle cx="154.71357471086574" cy="11.624527970907806" r="1" stroke="black" stroke-width="1" /><circle cx="140.01170087056778" cy="10.766925011520428" r="1" stroke="black" stroke-width="1" /><circle cx="128.48818897465" cy="10.511944446555773" r="1" stroke="black" stroke-width="1" /><circle cx="119.01539207489269" cy="10.249084910934187" r="1" stroke="black" stroke-width="1" /><circle cx="110.53975287955373" cy="10.316823389799282" r="1" stroke="black" stroke-width="1" /><circle cx="102.5984251955" cy="10.377952755899997" r="1" stroke="black" stroke-width="1" /><circle cx="94.65709751144627" cy="10.316823389799282" r="1" stroke="black" stroke-width="1" /><circle cx="86.18145831610732" cy="10.249084910934187" r="1" stroke="black" stroke-width="1" /><circle cx="76.70866141635001" cy="10.511944446555773" r="1" stroke="black" stroke-width="1" /><circle cx="65.42809286897163" cy="11.05645361993912" r="1" stroke="black" stroke-width="1" /><circle cx="50.772804288552976" cy="11.867471319447198" r="1" stroke="black" stroke-width="1" /><circle cx="29.934120450677966" cy="13.401574803100011" r="1" stroke="black" stroke-width="1" /><circle cx="12.743093017093301" cy="22.64966440495786" r="1" stroke="black" stroke-width="1" /><circle cx="10.662356537685326" cy="39.14352130336137" r="1" stroke="black" stroke-width="1" /><circle cx="10.377952755900012" cy="55.354330707999985" r="1" stroke="black" stroke-width="1" /><circle cx="10.662356537685326" cy="71.5651401126386" r="1" stroke="black" stroke-width="1" /><circle cx="12.387933601368374" cy="88.18826446678537" r="1" stroke="black" stroke-width="1" /><circle cx="31.570703890876672" cy="96.36220472315" r="1" stroke="black" stroke-width="1" /><circle cx="51.062332896971654" cy="98.5982467480134" r="1" stroke="black" stroke-width="1" /><circle cx="65.42809286897162" cy="99.65220779606088" r="1" stroke="black" stroke-width="1" /><circle cx="76.70866141634997" cy="100.19671696944422" r="1" stroke="black" stroke-width="1" /><circle cx="86.18145831610728" cy="100.4595765050658" r="1" stroke="black" stroke-width="1" /><circle cx="94.65709751144627" cy="100.39183802620072" r="1" stroke="black" stroke-width="1" /><circle cx="102.59842519549998" cy="100.3307086601" r="1" stroke="black" stroke-width="1" /><circle cx="110.5397528795537" cy="100.39183802620073" r="1" stroke="black" stroke-width="1" /><circle cx="118.88612461914944" cy="100.10441708934088" r="1" stroke="black" stroke-width="1" /><circle cx="128.11023621875" cy="99.54208359336474" r="1" stroke="black" stroke-width="1" /><circle cx="139.03992747641016" cy="98.78362197080477" r="1" stroke="black" stroke-width="1" /><circle cx="152.68687445193484" cy="97.3835300053164" r="1" stroke="black" stroke-width="1" /><circle cx="165.77054598716958" cy="91.82677165235003" r="1" stroke="black" stroke-width="1" /><circle cx="173.98546775621045" cy="81.3370893123932" r="1" stroke="black" stroke-width="1" /><circle cx="181.13490489913926" cy="69.20243104961436" r="1" stroke="black" stroke-width="1" /><circle cx="187.637795273" cy="55.35433070800002" r="1" stroke="black" stroke-width="1" /><polyline points=" 192.67343983190142,39.47167533989254 193.51923562108152,22.26186203772813 175.5900466283618,13.212598425150006 154.71357471086574,11.624527970907806 140.01170087056778,10.766925011520428 128.48818897465,10.511944446555773 119.01539207489269,10.249084910934187 110.53975287955373,10.316823389799282 102.5984251955,10.377952755899997 94.65709751144627,10.316823389799282 86.18145831610732,10.249084910934187 76.70866141635001,10.511944446555773 65.42809286897163,11.05645361993912 50.772804288552976,11.867471319447198 29.934120450677966,13.401574803100011 12.743093017093301,22.64966440495786 10.662356537685326,39.14352130336137 10.377952755900012,55.354330707999985 10.662356537685326,71.5651401126386 12.387933601368374,88.18826446678537 31.570703890876672,96.36220472315 51.062332896971654,98.5982467480134 65.42809286897162,99.65220779606088 76.70866141634997,100.19671696944422 86.18145831610728,100.4595765050658 94.65709751144627,100.39183802620072 102.59842519549998,100.3307086601 110.5397528795537,100.39183802620073 118.88612461914944,100.10441708934088 128.11023621875,99.54208359336474 139.03992747641016,98.78362197080477 152.68687445193484,97.3835300053164 165.77054598716958,91.82677165235003 173.98546775621045,81.3370893123932 181.13490489913926,69.20243104961436 187.637795273,55.35433070800002 192.67343983190142,39.47167533989254" style="fill:none;stroke:blue;stroke-width:1" /><line x1="263.228346453" y1="55.354330708" x2="448.42519684399997" y2="55.354330708" style="stroke:red;stroke-width:1" /><line x1="355.82677164849997" y1="10.0" x2="355.82677164849997" y2="100.708661416" style="stroke:red;stroke-width:1" /><circle cx="355.82677164849997" cy="55.354330708" r="1" stroke="red" stroke-width="1" /><line x1="326.25984251499995" y1="55.354330708" x2="336.25984251499995" y2="55.354330708" style="stroke:green;stroke-width:1" /><line x1="331.25984251499995" y1="50.354330708" x2="331.25984251499995" y2="60.354330708" style="stroke:green;stroke-width:1" /><circle cx="447.7628403063146" cy="39.143521303361396" r="1" stroke="black" stroke-width="1" /><circle cx="445.68210382690665" cy="22.649664404957882" r="1" stroke="black" stroke-width="1" /><circle cx="428.49107639332203" cy="13.401574803100011" r="1" stroke="black" stroke-width="1" /><circle cx="407.652392555447" cy="11.867471319447212" r="1" stroke="black" stroke-width="1" /><circle cx="392.9971039750283" cy="11.05645361993912" r="1" stroke="black" stroke-width="1" /><circle cx="381.71653542765" cy="10.511944446555773" r="1" stroke="black" stroke-width="1" /><circle cx="372.2437385278927" cy="10.249084910934187" r="1" stroke="black" stroke-width="1" /><circle cx="363.7680993325537" cy="10.316823389799282" r="1" stroke="black" stroke-width="1" /><circle cx="355.82677164849997" cy="10.377952755899997" r="1" stroke="black" stroke-width="1" /><circle cx="347.88544396444627" cy="10.316823389799282" r="1" stroke="black" stroke-width="1" /><circle cx="339.40980476910727" cy="10.249084910934187" r="1" stroke="black" stroke-width="1" /><circle cx="329.93700786935" cy="10.511944446555773" r="1" stroke="black" stroke-width="1" /><circle cx="318.4134959734322" cy="10.766925011520428" r="1" stroke="black" stroke-width="1" /><circle cx="303.71162213313426" cy="11.624527970907792" r="1" stroke="black" stroke-width="1" /><circle cx="282.8351502156382" cy="13.212598425150006" r="1" stroke="black" stroke-width="1" /><circle cx="264.90596122291845" cy="22.261862037728115" r="1" stroke="black" stroke-width="1" /><circle cx="265.75175701209855" cy="39.47167533989251" r="1" stroke="black" stroke-width="1" /><circle cx="270.787401571" cy="55.35433070799999" r="1" stroke="black" stroke-width="1" /><circle cx="277.2902919448607" cy="69.20243104961436" r="1" stroke="black" stroke-width="1" /><circle cx="284.4397290877895" cy="81.33708931239315" r="1" stroke="black" stroke-width="1" /><circle cx="292.65465085683036" cy="91.82677165235" r="1" stroke="black" stroke-width="1" /><circle cx="305.73832239206513" cy="97.38353000531637" r="1" stroke="black" stroke-width="1" /><circle cx="319.3852693675898" cy="98.78362197080477" r="1" stroke="black" stroke-width="1" /><circle cx="330.31496062524997" cy="99.54208359336474" r="1" stroke="black" stroke-width="1" /><circle cx="339.5390722248505" cy="100.10441708934087" r="1" stroke="black" stroke-width="1" /><circle cx="347.88544396444627" cy="100.39183802620072" r="1" stroke="black" stroke-width="1" /><circle cx="355.82677164849997" cy="100.3307086601" r="1" stroke="black" stroke-width="1" /><circle cx="363.7680993325537" cy="100.39183802620073" r="1" stroke="black" stroke-width="1" /><circle cx="372.2437385278927" cy="100.45957650506581" r="1" stroke="black" stroke-width="1" /><circle cx="381.71653542765" cy="100.19671696944422" r="1" stroke="black" stroke-width="1" /><circle cx="392.9971039750283" cy="99.65220779606088" r="1" stroke="black" stroke-width="1" /><circle cx="407.3628639470283" cy="98.59824674801341" r="1" stroke="black" stroke-width="1" /><circle cx="426.85449295312327" cy="96.36220472315003" r="1" stroke="black" stroke-width="1" /><circle cx="446.0372632426316" cy="88.18826446678543" r="1" stroke="black" stroke-width="1" /><circle cx="447.7628403063146" cy="71.5651401126386" r="1" stroke="black" stroke-width="1" /><circle cx="448.04724408809994" cy="55.35433070800002" r="1" stroke="black" stroke-width="1" /><polyline points=" 447.7628403063146,39.143521303361396 445.68210382690665,22.649664404957882 428.49107639332203,13.401574803100011 407.652392555447,11.867471319447212 392.9971039750283,11.05645361993912 381.71653542765,10.511944446555773 372.2437385278927,10.249084910934187 363.7680993325537,10.316823389799282 355.82677164849997,10.377952755899997 347.88544396444627,10.316823389799282 339.40980476910727,10.249084910934187 329.93700786935,10.511944446555773 318.4134959734322,10.766925011520428 303.71162213313426,11.624527970907792 282.8351502156382,13.212598425150006 264.90596122291845,22.261862037728115 265.75175701209855,39.47167533989251 270.787401571,55.35433070799999 277.2902919448607,69.20243104961436 284.4397290877895,81.33708931239315 292.65465085683036,91.82677165235 305.73832239206513,97.38353000531637 319.3852693675898,98.78362197080477 330.31496062524997,99.54208359336474 339.5390722248505,100.10441708934087 347.88544396444627,100.39183802620072 355.82677164849997,100.3307086601 363.7680993325537,100.39183802620073 372.2437385278927,100.45957650506581 381.71653542765,100.19671696944422 392.9971039750283,99.65220779606088 407.3628639470283,98.59824674801341 426.85449295312327,96.36220472315003 446.0372632426316,88.18826446678543 447.7628403063146,71.5651401126386 448.04724408809994,55.35433070800002 447.7628403063146,39.143521303361396" style="fill:none;stroke:blue;stroke-width:1" /></svg>
 

Thanks in advance for any help and explanation

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

I solved this problem with another post present in this community and another one. The links are:

https://www.linuxnet.ch/jasper-reports-inline-images-as-svg-for-better-scaling/

and

http://community.jaspersoft.com/questions/525861/how-use-svg-jasperreports

A little note, if you have/use a inline SVG string instead of SVG file, as showed in this links, it's necessary use this net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText in your report definition.

Link to comment
Share on other sites

  • 3 years later...
  • 1 year later...

marco.

 

Can you post a sample with inline svg loading, my code fails

            <image scaleImage="RetainShape" onErrorType="Blank">                <reportElement x="575" y="1" width="100" height="13" uuid="7cf54aff-65ac-40e5-8dc9-7f95d6f34d49"/>                <imageExpression><![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="13" viewBox="0 0 100 13"><defs><linearGradient id="a" x1="-176.88" y1="316.13" x2="-150.45" y2="316.13" gradientTransform="matrix(3.78, 0, 0, -3.78, 689.01, 1202.56)" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="green"/><stop offset="1" stop-color="green" stop-opacity="0"/></linearGradient></defs><title>gradient</title><path d="M0,1.26H100v10.4H0Z" style="fill:url(#a)"/><path d="M4.51,0V13" style="fill:none;stroke:#000"/></svg>')]]></imageExpression>            </image>[/code]

Error:

Exception: net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.stack: [net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:306), net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:285), net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:274), net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:248), net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:341), net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:608), dynamicreports.Rep3.makeReport(Rep3.java:520), dynamicreports.Rep3.main(Rep3.java:1982)][/code]


 

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