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

Exporting report in TIFF format


ranG

Recommended Posts

Does anyone tried this? I know that Jasper reports does not provide any direct functionality to generate reports in TIFF format.

I am not sure whether the future releases will include this functionality.

 

Meantime, If anyone tried this, It will be nice if you could post the codeSample as well.

 

Thanks and I appreciate your time in replying to this.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Thanks Teodord,

 

Appreciate your reply. I know that you are the GURU of Jasper reports, SO I am guessing this question wouldn't be very hard for you. I have a sample application in which I am trying to export my report to graphics2D, While exporting I want to save it in a file as image as I want to convert that image to tiff format using JAI. I am not sure about the foramt of the image output. And also some parameter settings for the exporter.

 

Here's my sample:

String reportFileName = "static_report";

Map parameters = new HashMap();

 

try{

JasperReport jasperReport =(JasperReport) JRLoader.loadObject(getServletContext().getRealPath( "/reports/" + reportFileName + ".jasper"));

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource ());

JRGraphics2DExporter exporter = new JRGraphics2DExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "simpleReportImg");

exporter.exportReportToGraphics2D();

 

}

catch (JRException e)

{

e.printStackTrace();

}

Link to comment
Share on other sites

Thanks Teodord,

 

Appreciate your reply. I know that you are the GURU of Jasper reports, SO I am guessing this question wouldn't be very hard for you. I have a sample application in which I am trying to export my report to graphics2D, While exporting I want to save it in a file as image as I want to convert that image to tiff format using JAI. I am not sure about the foramt of the image output. And also some parameter settings for the exporter.

 

Here's my sample:

String reportFileName = "static_report";

Map parameters = new HashMap();

 

try{

JasperReport jasperReport =(JasperReport) JRLoader.loadObject(getServletContext().getRealPath( "/reports/" + reportFileName + ".jasper"));

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource ());

JRGraphics2DExporter exporter = new JRGraphics2DExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "simpleReportImg");

exporter.exportReportToGraphics2D();

 

}

catch (JRException e)

{

e.printStackTrace();

}

Link to comment
Share on other sites

  • 8 months later...
  • 12 years later...

Hi,

TIFF is a multi-page image format and we can use the JRGraphics2DExporter in JasperReports to export reports to multi-page TIFF files.
The TIFF files are created using the ImageIO API, which is part of the Java Virtual Machine. However, for Java 8, you would also need this plugin:

https://github.com/haraldk/TwelveMonkeys

or this other plugin:

https://github.com/jai-imageio/jai-imageio-core

Since Java 9, support for TIFF is present in the JVM, so the plugin is no longer needed.

Here is some sample code that helps export reports to TIFF:

        ImageWriter writer = ImageIO.getImageWritersByFormatName("TIFF").next();        try (FileOutputStream out = new FileOutputStream(jasperPrint.getName() + ".tiff")) {            try (ImageOutputStream output = ImageIO.createImageOutputStream(out)) {                writer.setOutput(output);                ImageWriteParam params = writer.getDefaultWriteParam();                params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);                params.setCompressionType("Deflate");                float zoom = 3f;                writer.prepareWriteSequence(null);                int pageCount = jasperPrint.getPages().size();                                for (int page = 0; page < pageCount; page++) {                    BufferedImage image = (BufferedImage) JRPrinterAWT.printPageToImage(jasperPrint, page, zoom);                    writer.writeToSequence(new IIOImage(image, null, null), params);                }                writer.endWriteSequence();            }            out.close();        }        catch (Exception e) {            throw new RuntimeException(e);        } finally {            writer.dispose();                }[/code]

Attached is a sample report exported to TIFF using the above code.

I hope this helps.
Teodor

Link to comment
Share on other sites

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...