How to change the path of a JRImage?

I have an application that matters jrxml files to a database. In doing so, I would change the path of the report images to a default directory informed in the application. What I have so far is that
  JasperReport jr = ...; for (JRBand band : jr.getAllBands()) {     for (JRElement el : band.getElements()) {         if (el instanceof JRImage) {             File oldPath = new File(((JRImage) el).getExpression().getText());             String newPath = new Preference("imgDir").getValue() + "/" + oldPath.getName();             try {                 byte[] img = Tools.fileToByteArray(oldPath);                   try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(newPath))) {                     dos.write(img);                     dos.flush();                 }             } catch (Exception ex) {                 Logger.getLogger(RelatorioC.class.getName()).log(Level.SEVERE, null, ex);             }                         ((JRImage) el).setOnErrorType(OnErrorTypeEnum.BLANK);         }     } }
Sorry for any error or discrepancy in the text, translated by google translate. Also unable to format the source code appropriately.
I appreciate any help.
paulo_alonso's picture
Joined: Jan 16 2012 - 6:45am
Last seen: 1 month 6 days ago

0 Answers:

No answers yet