All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mntviews.jreport.JRExportPDF Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package com.mntviews.jreport;

import com.mntviews.jreport.exception.JRExportException;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
import net.sf.jasperreports.export.SimplePdfReportConfiguration;

import java.io.ByteArrayOutputStream;

public class JRExportPDF implements JRExportAction {
    static final String EXTENSION = "pdf";
    private static final String MIME_TYPE = "application/pdf";

    @Override
    public ByteArrayOutputStream export(JasperPrint jasperPrint, String configScript) {

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        JRPdfExporter exporterPdf = new JRPdfExporter();
        SimplePdfReportConfiguration configuration = new SimplePdfReportConfiguration();
        exporterPdf.setConfiguration(configuration);
        exporterPdf.setExporterInput(new SimpleExporterInput(jasperPrint));
        exporterPdf.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));

        try {
            exporterPdf.exportReport();
        } catch (JRException e) {
            throw new JRExportException(e);
        }

        return outputStream;
    }

    @Override
    public String getExtension() {
        return EXTENSION;
    }

    @Override
    public String getMimeType() {
        return MIME_TYPE;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy