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

antuansoft

Members
  • Posts

    5
  • Joined

  • Last visited

antuansoft's Achievements

Newbie

Newbie (1/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare

Recent Badges

0

Reputation

  1. Solution to populate subreports with a customDataSource I have a main report with 2 subreports inside. Main Report doesnt print anything and simply pass all the info to subreports. You have to create a unique custom DataSource to recover (via BD ,Webservice, etc..) all the info that you need for your 2 subreports. You can follow the customDataServiceSample that you have in samples folder in your JasperServerInstalation. After recover all the data and keep it in local variables i have created two public methods to pass the data to subreports: public JRDataSource getDataSourceToSubreport(){ return new JRBeanCollectionDataSource(data_report_1);} public JRDataSource getDataSourceToSubreport2(){ return new JRBeanCollectionDataSource(data_report_2);}[/code] And finally in the jrxml of the main report in each subreport in the DataSourceExpresion i call to this methods doing this SubReport1: $P{REPORT_DATA_SOURCE}.getDataSourceToSubreport() subReport2: $P{REPORT_DATA_SOURCE}.getDataSourceToSubreport2() The main report not compile, in preview mode in ReportStudio because it doesn´t know about this methods, but it works in jasperServer without problems. All my code is here: ------------CustomDSService.java----------------- public class CustomDSService implements ReportDataSourceService { private JRDataSource ds; private RepositoryService repository; private Map propertyMap; private Map parameterValues; public Map getPropertyMap() { return this.propertyMap; } public void setPropertyMap(Map propertyMap) { this.propertyMap = propertyMap; } public CustomDSService() { this.ds = new CustomDataSource(); } public CustomDSService(JRDataSource ds) { this.ds = ds; } public void closeConnection() {} @SuppressWarnings("unchecked") public void setReportParameterValues(Map parameterValues) { parameterValues.put("REPORT_DATA_SOURCE", this.ds); //Pass input control data to dataService. CustomDataSource ds = (CustomDataSource) this.ds; ds.setParameterValues(parameterValues); } public RepositoryService getRepository() { return this.repository; } public void setRepository(RepositoryService repository) { this.repository = repository; } } ----------------CustomDataSource.java------------------ public class CustomDataSource implements JRDataSource { List<E> data_report_1 = new ArrayList(); List<E> data_report_2 = new ArrayList(); private Map parameterValues; private int index = -1; public CustomDataSource() { super(); } //Public method created by myself to access to report input data before recover data public void setParameterValues(Map parameterValues) { this.parameterValues = parameterValues; fillDataReport1(); fillDataReport2(); } //If your main report doesnt print anything this method is not needed to do anything public boolean next() throws JRException { return false; } //If your main report doesnt print anything this method is not needed to do anything public Object getFieldValue(JRField field) throws JRException { return null; } //method to pass data to subreport public JRDataSource getDataSourceToSubreport(){ return new JRBeanCollectionDataSource(data_report_1); } //method to pass data to subreport public JRDataSource getDataSourceToSubreport2(){ return new JRBeanCollectionDataSource(data_report_2); } ........................ ........................ //TODO Methods to recover data //fillDataReport1(); //fillDataReport1(); } Hope it helps: http://antuansoft.blogspot.com.es/
  2. I have solved this issue in my answer to this question: Use JasperPrintManager with png. You can create a large report with a good resolution and scale the image to a small one. http://community.jaspersoft.com/questions/517024/export-report-image-jpg-bmp-or-any-format
  3. I have solved this issue in my answer to this question: Use JasperPrintManager http://community.jaspersoft.com/questions/517024/export-report-image-jpg-bmp-or-any-format
  4. Yes!! last answer works!!!!! and you can scale the image without loss of resolution and quality. I used JRGraphics2DExporter, but it doesn work using the zoom options, but using JasperPrintManager it works!!!!!! I have scaled the image to 1.6 Here is my code based on last post but updated to the new Jasperreports versions (5.5.0 in my case) JasperPrint is the compiled jrxml with data filled into the report .....JasperReport jasperReport = compileReport("myReport.jrxml");parameters.put("title", "MyReport");.....Fill Data........print = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(data));[/code]FilePath is the destination where the image report will be written. private void extractPrintImage (String filePath, JasperPrint print){ File file = new File(filePath); OutputStream ouputStream= null; try{ ouputStream= new FileOutputStream(file); DefaultJasperReportsContext.getInstance(); JasperPrintManager printManager = JasperPrintManager.getInstance(DefaultJasperReportsContext.getInstance()); BufferedImage rendered_image = null; rendered_image = (BufferedImage)printManager.printPageToImage(print, 0,1.6f); ImageIO.write(rendered_image, "png", ouputStream); }catch(Exception e){ e.printStackTrace(); } }[/code]
×
×
  • Create New...