main
黄海 2 years ago
parent 98269c6377
commit 84ac08e259

@ -831,23 +831,14 @@ public class CollectController extends Controller {
if (type_id == 2) { if (type_id == 2) {
String pdfPath = excelPath.replace(".xlsx", ".pdf"); String pdfPath = excelPath.replace(".xlsx", ".pdf");
AsposeUtil.xls2pdf(excelPath, pdfPath); AsposeUtil.xls2pdf(excelPath, pdfPath);
HttpServletResponse response = getResponse(); OutputStream outputStream = getResponse().getOutputStream();
BufferedInputStream br = new BufferedInputStream(new FileInputStream(pdfPath)); outputStream.write(CommonUtil.convertFileToByteArray(new File(pdfPath)));
byte[] buf = new byte[1024]; outputStream.flush();
int len;
response.reset(); // 非常重要
URL u = new URL("file:///" + pdfPath);
response.setContentType(u.openConnection().getContentType());
String fileName = pdf_filename;
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0) out.write(buf, 0, len);
br.close();
out.close();
renderNull(); renderNull();
} }
} }
/** /**
* *
* *

@ -33,6 +33,17 @@ public class CommonUtil {
public static String WebRoot; public static String WebRoot;
public static byte[] convertFileToByteArray(File file) {
byte[] fileBytes = null;
try (FileInputStream fis = new FileInputStream(file)) {
fileBytes = new byte[(int) file.length()];
fis.read(fileBytes);
} catch (IOException e) {
e.printStackTrace();
}
return fileBytes;
}
//获取当前年份 //获取当前年份
public static String getCurrentYear() { public static String getCurrentYear() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

Loading…
Cancel
Save