资源简介
使用maven构建工具。前端使用pdf插件。后台搭建的springmvc框架,主要用于web在线预览pdf、word、excel文件。不需要安装office等其他插件
代码片段和文件信息
package com.controller;
import com.util.Excel2Pdf;
import com.util.Word2Pdf;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Created by wangyi on 2017/11/9.
*/
@Controller
@RequestMapping(“/review“)
public class ReviewController {
@RequestMapping(“/word“)
public void reviewWord(HttpServletRequest request HttpServletResponse response) throws Exception{
response.setHeader(“content-disposition“ “attachment;filename=“ + URLEncoder.encode(“word“ “UTF-8“));
String path = request.getServletContext().getRealPath(“/“);
FileInputStream fis = new FileInputStream(path+“/resources/file/4894.docx“);
OutputStream out = response.getOutputStream();
Word2Pdf.word2pdf(fisout);
// byte[] bs = new byte[1024];
// int len = 0;
// while ((len = fis.read(bs)) != -1) {
// out.write(bs 0 len);
// }
out.close();
}
@RequestMapping(“/excel“)
public void reviewExcel(HttpServletRequest request HttpServletResponse response) throws Exception{
response.setHeader(“content-disposition“ “attachment;filename=“ + URLEncoder.encode(“excel“ “UTF-8“));
String path = request.getServletContext().getRealPath(“/“);
FileInputStream fis = new FileInputStream(path+“/resources/file/123.xlsx“);
OutputStream out = response.getOutputStream();
Excel2Pdf.excel2pdf(fisout);
// byte[] bs = new byte[1024];
// int len = 0;
// while ((len = fis.read(bs)) != -1) {
// out.write(bs 0 len);
// }
fis.close();
out.close();
}
@RequestMapping(“/pdf“)
public void reviewPdf(HttpServletRequest request HttpServletResponse response) throws IOException{
response.setHeader(“content-disposition“ “attachment;filename=“ + URLEncoder.encode(“pdf“ “UTF-8“));
String path = request.getServletContext().getRealPath(“/“);
FileInputStream fis = new FileInputStream(path+“/resources/file/123.pdf“);
OutputStream out = response.getOutputStream();
byte[] bs = new byte[1024];
int len = 0;
while ((len = fis.read(bs)) != -1) {
out.write(bs 0 len);
}
fis.close();
out.close();
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 300 2017-11-09 20:10 pdfDemo\.idea\artifacts\pdfDemo_war.xm
文件 2718 2017-11-13 09:44 pdfDemo\.idea\artifacts\pdfDemo_war_exploded.xm
文件 626 2017-11-09 20:10 pdfDemo\.idea\compiler.xm
文件 514 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__aopalliance_aopalliance_1_0.xm
文件 536 2017-11-09 20:14 pdfDemo\.idea\libraries\Maven__aspose_aspose_license_14_9_0.xm
文件 529 2017-11-13 09:44 pdfDemo\.idea\libraries\Maven__aspose_aspose_words_14_11_0.xm
文件 466 2017-11-09 20:14 pdfDemo\.idea\libraries\Maven__aspose_cells_9_0_0.xm
文件 605 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__commons_fileupload_commons_fileupload_1_2_1.xm
文件 503 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__commons_io_commons_io_1_4.xm
文件 572 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__commons_logging_commons_logging_1_1_1.xm
文件 578 2017-11-09 20:31 pdfDemo\.idea\libraries\Maven__javax_servlet_javax_servlet_api_3_1_0.xm
文件 437 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__jstl_jstl_1_2.xm
文件 609 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 623 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 637 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 616 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 658 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 616 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 609 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 602 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 630 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 609 2017-11-09 20:17 pdfDemo\.idea\libraries\Maven__org_springfr
文件 566 2017-11-09 22:08 pdfDemo\.idea\misc.xm
文件 254 2017-11-09 20:09 pdfDemo\.idea\modules.xm
文件 76502 2017-11-15 16:37 pdfDemo\.idea\workspace.xm
文件 1016315 2016-12-18 00:18 pdfDemo\123.pdf
文件 168 2017-11-09 20:13 pdfDemo\demo.html
文件 584 2017-11-09 16:39 pdfDemo\license.xm
文件 3178 2017-11-13 09:44 pdfDemo\pdfDemo.iml
文件 4334 2017-11-13 10:02 pdfDemo\pom.xm
............此处省略1049个文件信息
- 上一篇:android仿淘宝界面
- 下一篇:基于java的电子邮件系统B/S源代码
评论
共有 条评论