3rwin Posted March 21, 2007 Share Posted March 21, 2007 I am using JasperReports in a Java application and I'm using the JRViewer to view the reports. How can I limit the offered formats in the JRViewer save dialog? Link to comment Share on other sites More sharing options...
3rwin Posted March 21, 2007 Author Share Posted March 21, 2007 Maybe not the best way to do this but ... Remove all the formats:Code:JRViewer viewer = new JRViewer(jasperPrint);JRSaveContributor[] save = viewer.getSaveContributors();for (int i=0; i<save.length; i++) { viewer.removeSaveContributor(save);} Add the ones you need (taken from the initSaveContributors in the JRViewer class):Code:[code]final String[] DEFAULT_CONTRIBUTORS = {"net.sf.jasperreports.view.save.JRPrintSaveContributor","net.sf.jasperreports.view.save.JRPdfSaveContributor","net.sf.jasperreports.view.save.JRRtfSaveContributor","net.sf.jasperreports.view.save.JRHtmlSaveContributor","net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor","net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor","net.sf.jasperreports.view.save.JRCsvSaveContributor","net.sf.jasperreports.view.save.JRXmlSaveContributor","net.sf.jasperreports.view.save.JREmbeddedImagesXmlSaveContributor"}; for(int i = 0; i < DEFAULT_CONTRIBUTORS.length; i++) { try { Class saveContribClass = JRClassLoader.loadClassForName(DEFAULT_CONTRIBUTORS); Method method = saveContribClass.getMethod("getInstance",(Class[])null); JRSaveContributor saveContrib = (JRSaveContributor)method.invoke(null,(Object[])null); viewer.addSaveContributor(saveContrib); } catch (Exception e) { }} Remove the ones you don't need from the DEFAULT_CONTRIBUTORS.Post edited by: 3rwin, at: 2007/03/21 11:02 Link to comment Share on other sites More sharing options...
kiyone Posted November 20, 2008 Share Posted November 20, 2008 I've limited the save formats as described in the example in the previous posting.Everything worked fine the for several months.I had to update to a newer version of JasperReports (from jasperreports-1.3.3.jar to jasperreports-3.1.2.jar)and now i'm getting an Exception:java.lang.NoSuchMethodException: net.sf.jasperreports.view.save.JRPdfSaveContributor.getInstance() Link to comment Share on other sites More sharing options...
buedenbenderd Posted March 30, 2009 Share Posted March 30, 2009 This code is working after JR 3.0 Code: Post Edited by Daniel at 03/30/09 13:03 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