ireport 直接打印 如下代码已可已输出到打印机,但是还是有两个问题 。 50
java使用ireport直接打印如下代码已可将内容输出到打印机,但是还是有两个问题1:显示PDF文件,2:会弹出打印机选择。我要解决这两个问题。代码如下packagec...
java 使用 ireport 直接打印 如下代码已可将内容输出到打印机,但是还是有两个问题 1:显示PDF 文件,2:会弹出打印机选择。我要解决这两个问题。代码如下
package com.test.stu.ireport;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperRunManager;
//此测试可输出到打印机打印出来了。
public class HelloTest5 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String jrxmlSourcePath = this.getServletContext().getRealPath("/" + "report\\hello3.jrxml");
System.out.println(jrxmlSourcePath);
String jrxmlDestSourcePath = this.getClass().getClassLoader().getResource("").getPath().substring(1) + "hello2.jasper";
System.out.println(jrxmlDestSourcePath);
JasperCompileManager.compileReportToFile(jrxmlSourcePath,jrxmlDestSourcePath);
File reportFile = new File (jrxmlDestSourcePath);
if(!reportFile.exists()){
throw new JRRuntimeException("文件 demo-report.jasper不能找到.");
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("parameters1", "K12013102900001");
parameters.put("parameters2", "中文");
//读取模板文件
FileInputStream fileInputStream = new FileInputStream(reportFile);
//将模板转成PDF
byte[] pdfStream = JasperRunManager.runReportToPdf(fileInputStream, parameters,new JREmptyDataSource());
还有部分代码贴不上了。超出内容 展开
package com.test.stu.ireport;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperRunManager;
//此测试可输出到打印机打印出来了。
public class HelloTest5 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String jrxmlSourcePath = this.getServletContext().getRealPath("/" + "report\\hello3.jrxml");
System.out.println(jrxmlSourcePath);
String jrxmlDestSourcePath = this.getClass().getClassLoader().getResource("").getPath().substring(1) + "hello2.jasper";
System.out.println(jrxmlDestSourcePath);
JasperCompileManager.compileReportToFile(jrxmlSourcePath,jrxmlDestSourcePath);
File reportFile = new File (jrxmlDestSourcePath);
if(!reportFile.exists()){
throw new JRRuntimeException("文件 demo-report.jasper不能找到.");
}
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("parameters1", "K12013102900001");
parameters.put("parameters2", "中文");
//读取模板文件
FileInputStream fileInputStream = new FileInputStream(reportFile);
//将模板转成PDF
byte[] pdfStream = JasperRunManager.runReportToPdf(fileInputStream, parameters,new JREmptyDataSource());
还有部分代码贴不上了。超出内容 展开
1个回答
展开全部
jasperReport客户端采用applet,applet和activeX插件的区别大家搜一下,有一堆东西可以借鉴,下载jasperreports-3.0.0,在相应的sample OR demo(记得不清了)中可以找到jasperReport 实现的客户端打印demo,下来就来分析下具体实现。 新建一pri...5142
追问
兄弟 我用的是jasperreports-5.5.0
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询