singhipst Posted February 12, 2008 Share Posted February 12, 2008 Hi All, I am not sure whether it is possible in Jasper Report or not. I wanted to embed SWF(Flash) file and SVG file in my jasper report using jasper API. Similarly like we embed JPG and GIF files in our report for logo. Please let me know if anybody has tried this. Best Regards: Ritesh Kumar Link to comment Share on other sites More sharing options...
lucianc Posted February 14, 2008 Share Posted February 14, 2008 SVG images can be displayed in a report via an image renderer that uses Batik. I'm not aware of any solution for embedding SWF in a report. Regards,Lucian Link to comment Share on other sites More sharing options...
singhipst Posted February 18, 2008 Author Share Posted February 18, 2008 Hi Lucian, I tried to embed SGV file by Renderer. But no success.I would be thankful If you provide me some sample. Best Regards:Ritesh Kumar Link to comment Share on other sites More sharing options...
lucianc Posted February 21, 2008 Share Posted February 21, 2008 I'm not a Batik expert either, this is just some code I grabbed from the Batik mailing lists. You could give it a try and see whether you like the results. The Batik image renderer looks like Code: package jr.util;import java.awt.Graphics2D;import java.awt.geom.AffineTransform;import java.awt.geom.Rectangle2D;import java.io.File;import java.io.IOException;import net.sf.jasperreports.engine.JRAbstractSvgRenderer;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRRuntimeException;import org.apache.batik.bridge.BridgeContext;import org.apache.batik.bridge.DocumentLoader;import org.apache.batik.bridge.GVTBuilder;import org.apache.batik.bridge.UserAgent;import org.apache.batik.bridge.UserAgentAdapter;import org.apache.batik.bridge.ViewBox;import org.apache.batik.gvt.GraphicsNode;import org.w3c.dom.svg.SVGDocument;public class BatikRenderer extends JRAbstractSvgRenderer{ private static final long serialVersionUID = 1L; private final String svgURI; public BatikRenderer(String svgURI) { this.svgURI = svgURI; } public BatikRenderer(File svgFile) { this(svgFile.toURI().toString()); } public void render(Graphics2D grx, Rectangle2D rectangle) throws JRException { try { UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); SVGDocument svgDoc = (SVGDocument) loader.loadDocument(svgURI); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamic(true); GVTBuilder builder = new GVTBuilder(); GraphicsNode graphicsNode = builder.build(ctx, svgDoc); AffineTransform transform = ViewBox.getViewTransform(null, svgDoc.getRootElement(), (float) rectangle.getWidth(), (float) rectangle.getHeight(), ctx); Graphics2D graphics = (Graphics2D) grx.create(); graphics.translate(rectangle.getX(), rectangle.getY()); graphics.transform(transform); graphicsNode.paint(graphics); } catch (IOException e) { throw new JRRuntimeException(e); } }}[/code] You would then use it in a report in this way: ... new jr.util.BatikRenderer(new java.io.File("..svg file..")) Regards, Lucian Link to comment Share on other sites More sharing options...
singhipst Posted February 22, 2008 Author Share Posted February 22, 2008 Thanks A Lot Link to comment Share on other sites More sharing options...
nandu_bc Posted February 22, 2008 Share Posted February 22, 2008 Hi Lucian, I'm working with Ritesh on this issue. I tried he Batik code to paint svg file. But, the image is rendered very minute (appears as dot). I tried to increse the height and width, but not much diffrence. Can you please help. Please find the JRXML and PDF enclosed. thanks and regards, Nandini [file name=test-dc1f41e07aee88fefd12b8e8226bf253.jrxml size=2405] Post edited by: nandu_bc, at: 2008/02/22 12:35 Link to comment Share on other sites More sharing options...
lucianc Posted February 22, 2008 Share Posted February 22, 2008 Please attach the SVG file and the PDF output as well. What JasperReports version are you using? Regards,Lucian Link to comment Share on other sites More sharing options...
nandu_bc Posted February 23, 2008 Share Posted February 23, 2008 Attached is the svg file [file name=SVGToJasperPDFBatik.zip size=13627] Post edited by: nandu_bc, at: 2008/02/22 17:44 Link to comment Share on other sites More sharing options...
lucianc Posted February 25, 2008 Share Posted February 25, 2008 The SVG doesn't indeed render using the code I posted. I don't know at the moment why that is, and as I said I'm not a Batik/SVG expert so it might take some time to determine the cause (if ever). You might want to investigate this on your own as well. Regards,Lucian Link to comment Share on other sites More sharing options...
nandu_bc Posted March 3, 2008 Share Posted March 3, 2008 Hi Lucian, Thanks for the reply. We are able to resolve this issue. The problem was that the svg file itself was corrupted. Now we are able to render a svg image on the jasper pdf using batik renderer. Thanks and regards,Nandini Link to comment Share on other sites More sharing options...
danc Posted March 29, 2008 Share Posted March 29, 2008 Hi, Lucian, We are currently using FOP and evaluating JasperReports and BIRT basically because we want to have a visual designer. I found that if a image is a SVG, the scaleImage doesn't work right. I set it to Clip, RetainShape and FillFrame, but it always looks like Clip. If the image is JPEG, it works correctly for Clip, RetainShape and FillFrame. Is this a bug? Can it be fixed or any workaround? BTW, In the code you posted here, there are constructors for taking SVG file as parameter, but in net.sf.jasperreports.renderers.BatikRenderer class, there is not constructor to take SVG file. It is useful to have a constructor for take SVG file. Thanks, Dan lucianc wrote:I'm not a Batik expert either, this is just some code I grabbed from the Batik mailing lists. You could give it a try and see whether you like the results.The Batik image renderer looks like Code: You would then use it in a report in this way: ... new jr.util.BatikRenderer(new java.io.File("..svg file..")) [/code]Regards, Lucian Link to comment Share on other sites More sharing options...
lucianc Posted April 1, 2008 Share Posted April 1, 2008 danc wrote: I found that if a image is a SVG, the scaleImage doesn't work right. I set it to Clip, RetainShape and FillFrame, but it always looks like Clip. If the image is JPEG, it works correctly for Clip, RetainShape and FillFrame. Is this a bug? Can it be fixed or any workaround? We could consider this as a bug, please log it BTW, In the code you posted here, there are constructors for taking SVG file as parameter, but in net.sf.jasperreports.renderers.BatikRenderer class, there is not constructor to take SVG file. It is useful to have a constructor for take SVG file. You could extend the built-in Batik renderer and add a java.io.File constructor, or post this as a enhancement request. Regards, Lucian Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now