Jump to content
JasperReports Library 7.0 is now available ×

How to change the path of a JRImage?


Recommended Posts

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 = ...;[/code]
for (JRBand band : jr.getAllBands()) {[/code]
    for (JRElement el : band.getElements()) {[/code]
        if (el instanceof JRImage) {[/code]
            File oldPath = new File(((JRImage) el).getExpression().getText());[/code]
            String newPath = new Preference("imgDir").getValue() + "/" + oldPath.getName();[/code]
            try {[/code]
                byte[] img = Tools.fileToByteArray(oldPath);[/code]
                try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(newPath))) {[/code]
            } catch (Exception ex) {[/code]
                Logger.getLogger(RelatorioC.class.getName()).log(Level.SEVERE, null, ex);[/code]
            ((JRImage) el).setOnErrorType(OnErrorTypeEnum.BLANK);[/code]

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.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...