简体   繁体   中英

SVG markup in PDF as generated from Jasper Reports

Problem Statement

I have a SVG markup sent from front end javascript to back-end action classes. I am using Jasper Reports to generate PDF which will contain the SVG image( i have markup data only). How do i do that.

What i have tried

I have tried to embed SVG image( having the link to image file) to the PDF file while generating reports.

Looking for

How to embed svg markup so that i can see the image in PDF. Any other best approach to solve it.

According to their own web site (here: http://community.jaspersoft.com/wiki/how-add-svg-image-your-report-jrxml ) you need to include the SVG using a special HTML element:

<imageExpression class="net.sf.jasperreports.engine.JRRenderable">
    <![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.io.File("D:\\tomcat.svg"))]]>
</imageExpression> 

As the question indicates the absence of a SVG markup file , you could stick to the answer by David van Driessche but use a different getter:

BatikRenderer.getInstanceFromText($P{svgMarkup}) for example where svgMarkup is a parameter of String type containing the SVG markup data.

In later versions of jasper reports you no longer need to add class="net.sf.jasperreports.engine.JRRenderable" to the imageExpression.

It is the default in JasperReports 6+ and JasperSoftStudio (JSS) will remove it if you add it in the Source pane.

The Tomcat SVG file provided in the JasperSoft Community answer works nicely. My own SVG file would show properly in MS Edge or Chrome but didn't appear in JSS.

When I added width, height, viewbox and overflow attributes to the svg element, it then did appear in JSS - so try the example first before trying the svg you actually want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM