本文整理汇总了Java中net.sf.jasperreports.engine.JasperPrint类的典型用法代码示例。如果您正苦于以下问题:Java JasperPrint类的具体用法?Java JasperPrint怎么用?Java JasperPrint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JasperPrint类属于net.sf.jasperreports.engine包,在下文中一共展示了JasperPrint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generatePDF
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public PDFResponseModel generatePDF(String fileName, String template, String bucketName,
Collection<?> items, Map<String, Object> parameters)
throws ClassNotFoundException, JRException, IOException {
JasperPrint jasperPrint;
InputStream inputStream = null;
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(items);
try {
inputStream = storageUtil.getInputStream(bucketName, template);
jasperPrint = JasperFillManager.fillReport(JasperCompileManager.compileReport(
inputStream), parameters, beanColDataSource);
byte[] pdfBytes = JasperExportManager.exportReportToPdf(jasperPrint);
return new PDFResponseModel(fileName, pdfBytes);
} catch (ClassNotFoundException | JRException | IOException e) {
xLogger.severe("Failed to generate PDF for file name - ", fileName, e);
throw e;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}
示例2: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".xls";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRXlsExporter exporter = new JRXlsExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例3: createReportPDFFile
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
/**
* @param jrxmlTemplate
* @param jsonData
* @param parameters
* @param outputDestination
* @param exportName
* @return
*/
public static String createReportPDFFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters,
String outputDestination, String exportName) {
String sourceFileName = outputDestination + exportName;
try {
// fix json enter char
jsonData = quoteHTML(jsonData);
JasperReport reportTemplate = JRReportTemplate.getJasperReport(jrxmlTemplate);
JRJSONDataSource dataSource = JRJSONDataSource.getInstance(jsonData);
JasperPrint jasperPrint = getJasperPrint(reportTemplate, parameters, dataSource);
return exportPdfFile(jasperPrint, sourceFileName);
} catch (Exception e) {
_log.error(e);
return StringPool.BLANK;
}
}
示例4: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res)
throws Exception {
res.setContentType("text/xml");
res.setHeader("Content-Disposition", "inline; filename=\"file.jrpxml\"");
JRXmlExporter exporter = new JRXmlExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
//exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, Integer.valueOf(1));
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例5: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".rtf";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRRtfExporter exporter = new JRRtfExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例6: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("text/html;charset=UTF-8");
JRHtmlExporter exporter=new JRHtmlExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
req.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
String path=req.getContextPath();
if(path.endsWith("/")){
path+="dorado/bdf2/jasperreports/html.image";
}else{
path+="/dorado/bdf2/jasperreports/html.image";
}
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,path+"?image=");
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例7: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".pptx";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRPptxExporter exporter = new JRPptxExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例8: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".pdf";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRPdfExporter exporter = new JRPdfExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例9: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".csv";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRCsvExporter exporter = new JRCsvExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例10: export
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void export(HttpServletRequest req, HttpServletResponse res) throws Exception {
String fileName=this.getExportFileName(req);
fileName+=".docx";
res.setContentType("application/octet-stream");
res.setHeader("Connection", "close");
res.setHeader("Content-Disposition", "attachment;filename=\"" + new String(fileName.getBytes("utf-8"),"ISO-8859-1") + "\"");
JRDocxExporter exporter = new JRDocxExporter(DefaultJasperReportsContext.getInstance());
JasperPrint jasperPrint=this.getJasperPrint(req);
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
OutputStream ouputStream = res.getOutputStream();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
try {
exporter.exportReport();
} catch (JRException e) {
throw new ServletException(e);
} finally {
if (ouputStream != null) {
ouputStream.flush();
ouputStream.close();
}
}
}
示例11: savePDFReportToOutputStream
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
/**
* Generates a PDF report from a pre-compiled report and returns it into an output stream.
*
* @param jasperPrint
* JasperPrint object which contains a compiled report.
* @param exportParameters
* Export parameters than can be added to configure the resulting report.
* @param outputStream
* The output stream used to return the report.
* @throws JRException
* In case there is any error generating the report an exception is thrown with the
* error message.
*/
public static void savePDFReportToOutputStream(JasperPrint jasperPrint,
Map<Object, Object> exportParameters, OutputStream outputStream) throws JRException {
if (exportParameters != null && exportParameters.size() > 0) {
final JRPdfExporter exporter = new JRPdfExporter();
SimpleExporterInput exporterInput = new SimpleExporterInput(jasperPrint);
SimpleOutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(
outputStream);
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
String jsContent = (String) exportParameters.get(PDF_JAVASCRIPT);
if (jsContent != null) {
configuration.setPdfJavaScript(jsContent);
}
exporter.setExporterInput(exporterInput);
exporter.setExporterOutput(exporterOutput);
exporter.setConfiguration(configuration);
exporter.exportReport();
} else {
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
}
}
示例12: openReport
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
/**
* Abre um relatório usando um datasource genérico.
*
* @param titulo Título usado na janela do relatório.
* @param inputStream InputStream que contém o relatório.
* @param parametros Parâmetros utilizados pelo relatório.
* @param dataSource Datasource a ser utilizado pelo relatório.
* @throws JRException Caso ocorra algum problema na execução do relatório
*/
public static void openReport(
String titulo,
InputStream inputStream,
Map parametros,
JRDataSource dataSource ) throws JRException {
/*
* Cria um JasperPrint, que é a versão preenchida do relatório,
* usando um datasource genérico.
*/
JasperPrint print = JasperFillManager.fillReport(
inputStream, parametros, dataSource );
// abre o JasperPrint em um JFrame
viewReportFrame( titulo, print );
}
示例13: loadReport
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
public void loadReport(String reportName, ReportObject reportObject) {
logging = LoggingEngine.getInstance();
try {
final InputStream inputStream = ShowReport.class
.getResourceAsStream("/com/coder/hms/reportTemplates/" + reportName + ".jrxml");
JasperReport report = JasperCompileManager.compileReport(inputStream);
HashMap<String, Object> parameters = new HashMap<String, Object>();
List<ReportObject> list = new ArrayList<ReportObject>();
list.add(reportObject);
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, beanColDataSource);
final JRViewer viewer = new JRViewer(jasperPrint);
setType(Type.POPUP);
setResizable(false);
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
this.setTitle("Reservation [Report]");
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.setAlwaysOnTop(isAlwaysOnTopSupported());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
this.setIconImage(Toolkit.getDefaultToolkit().
getImage(LoginWindow.class.getResource(LOGOPATH)));
this.setResizable(false);
getContentPane().add(viewer, BorderLayout.CENTER);
} catch (JRException e) {
logging.setMessage("JRException report error!");
}
}
示例14: testInvoice
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
@Test
public void testInvoice(){
List<InvoiceItem> invoiceItems = new ArrayList<>();
int count = 1;
for (IDemandItem demandItem : getDemandItems()) {
InvoiceItem invoiceItem = new InvoiceItem();
invoiceItem.setItem(demandItem.getMaterialId().toString());
invoiceItem.setQuantity(demandItem.getQuantity().toString());
invoiceItem.setRecommended(demandItem.getRecommendedOrderQuantity().toString());
invoiceItem.setRemarks("Blah");
invoiceItem.setBatchId("AB/1234/56"+count);
invoiceItem.setExpiry("11/03/2020");
invoiceItem.setManufacturer("Serum");
invoiceItem.setBatchQuantity(BigDecimal.TEN.toPlainString());
invoiceItem.setSno(String.valueOf(count++));
invoiceItems.add(invoiceItem);
}
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(invoiceItems);
try {
Map<String, Object> hm = new HashMap<>();
JasperPrint jasperPrint = JasperFillManager.fillReport(
JasperCompileManager
.compileReport(Thread.currentThread().getContextClassLoader().getResourceAsStream(
"test_logistimo_invoice.jrxml")), hm, beanColDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "/tmp/logistimo_invoice.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: createReportFile
import net.sf.jasperreports.engine.JasperPrint; //导入依赖的package包/类
/**
* @param jrxmlTemplate
* @param jsonData
* @param parameters
* @param destFileName
* @return
*/
public static String createReportFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters,
String destFileName) {
try {
// fix json enter char
jsonData = quoteHTML(jsonData);
JasperReport reportTemplate = JRReportTemplate.getJasperReport(jrxmlTemplate);
JRJSONDataSource dataSource = JRJSONDataSource.getInstance(jsonData);
JasperPrint jasperPrint = getJasperPrint(reportTemplate, parameters, dataSource);
return exportReport(jasperPrint, destFileName, DocType.PDF);
} catch (Exception e) {
_log.error(e);
return StringPool.BLANK;
}
}