karenper Posted October 12, 2006 Share Posted October 12, 2006 Hi can anyone tell me if its possible to convert a jrxml file to a jpeg image??? pllllllllllllllls this is very urgent.... Link to comment Share on other sites More sharing options...
rsilverns.sympatico.ca Posted October 12, 2006 Share Posted October 12, 2006 Do you mean export your report to a jpeg, or actually take a capture of the report file text and store it as a jpeg? I am not sure of an exporter which exports directly to jpeg, gif etc. But if you export to pdf, there are many ways to convert to an image file. Although pdf itself is a pretty universal format. You can always print-screen the jrxml file in a text editor of your choosing to capture that text. Hth,Robin Link to comment Share on other sites More sharing options...
lucianc Posted October 12, 2006 Share Posted October 12, 2006 I guess that your question is whether you can export a filled report to an jpeg image.. You can, for example by creating a buffered image, using JRGraphics2DExporter to export a filled report page to the buffered image and then use something like Sun's Image I/O APIs or JAI APIs to encode the buffered image into a jpeg. If you want to export all the report pages into a single image, you need to think how the pages will be concatenated into a single image and use export offsets for JRGraphics2DExporter. HTH,Lucian Link to comment Share on other sites More sharing options...
karenper Posted October 13, 2006 Author Share Posted October 13, 2006 hi lucian...thanks for replying..i am kind of new to all this so can u maybe put up a small sample code which involves using exportReportToGraphics2D methods?thanks in advance.... Link to comment Share on other sites More sharing options...
karenper Posted October 13, 2006 Author Share Posted October 13, 2006 also all methods of JRGraphics2DExporter return void. so how can i export the report to a BufferedImage?by report do you mean the pdf file or the compiled jrxml file?My requirement is that from a web application when a report is created it has to be converted to a jpeg image so that this image can be used for certain other reports.all this then has to be done at the server end and cannot involve the client doing anything like saving the image....plllls reply asap...regards,karen Post edited by: karenper, at: 2006/10/13 05:44Post edited by: karenper, at: 2006/10/13 05:45 Link to comment Share on other sites More sharing options...
karenper Posted October 13, 2006 Author Share Posted October 13, 2006 rsilver@bfm.bm wrote:Do you mean export your report to a jpeg, or actually take a capture of the report file text and store it as a jpeg?I am not sure of an exporter which exports directly to jpeg, gif etc. But if you export to pdf, there are many ways to convert to an image file. Although pdf itself is a pretty universal format.You can always print-screen the jrxml file in a text editor of your choosing to capture that text.Hth,RobinI mean mean export my report to a jpeg. I found this tool called ImageMagick which runs a command line function to convert files.but will this help me? this is wat i found -In my program, I start a minimized command prompt and need to wait until theprocess is finished. This can be done like this: System.out.println("invoking convert..."); Process proc = Runtime.getRuntime().exec("cmd /c start /wait /MINc:\ImageMagick2\convert test1.pdf toto.jpg"); try { proc.waitFor(); } catch (InterruptedException intex) { } System.out.println("done convert..."); pls reply asap.... Link to comment Share on other sites More sharing options...
lucianc Posted October 13, 2006 Share Posted October 13, 2006 I'm not sure any more what's this thread about, but maybe this will help.. This is sample code for exporting a report page to a BufferedImage:Code:JasperPrint print = ..;int pageIndex = ..;BufferedImage pageImage = new BufferedImage(print.getPageWidth() + 1, print.getPageHeight() + 1, BufferedImage.TYPE_INT_RGB«»);JRGraphics2DExporter exporter = new JRGraphics2DExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));exporter.exportReport(); And this is some code that uses Sun's Image I/O APIs to encode the buffered image as jpeg:Code:[code]String jpegFilename = ..;Iterator writers = ImageIO.getImageWritersByFormatName("jpeg"«»);ImageWriter writer = (ImageWriter) writers.next();ImageOutputStream ios = ImageIO.createImageOutputStream(new File(jpegFilename));writer.setOutput(ios);writer.write(pageImage); If this looks useful, you should adapt the code for your particular needs. HTH,Lucian Link to comment Share on other sites More sharing options...
karenper Posted October 16, 2006 Author Share Posted October 16, 2006 Hi Lucian,Thanks a lot for your help. It worked very well. Link to comment Share on other sites More sharing options...
Teodor Danciu Posted October 16, 2006 Share Posted October 16, 2006 Hi, Also, the JRGraphics2DExporter could help producing JPG images for generated document pages. We use it in our JRViewer and for printing and should be easy to save those page images into JPG files using specialized Java image libraries. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
ollywatkins Posted March 23, 2010 Share Posted March 23, 2010 thank you so much Lucian!! Link to comment Share on other sites More sharing options...
kumarj84 Posted February 14, 2011 Share Posted February 14, 2011 Hai lucian ! Can u pls send me thh sample code to convert jasper page to image. Link to comment Share on other sites More sharing options...
piramanayagam Posted June 20, 2012 Share Posted June 20, 2012 HI LucianThanks a ton, your works fine. 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