点击连接,实现现在预览pdf文件
<a href="javascript:void(0);" οnclick="finPdf()">点击查看pdf</a>
function finPdf(){
window.open("/devDoc?storeName=文件名.pdf", "_blank","top=200,left=200,height=600,width=800,status=yes,toolbar=1,menubar=no,location=no,scrollbars=yes");
}
以上写在页面
//storeName是文件名
@RequestMapping("/devDoc")
@ResponseBody
public void devDoc(HttpServletRequest request, HttpServletResponse response, String storeName) throws Exception {
request.setCharacterEncoding("UTF-8");
String ctxPath = request.getSession().getServletContext().getRealPath("");
String downLoadPath = ctxPath + "/file/" + storeName;
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(downLoadPath));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b))!=-1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
javapdf前台显示 java 预览pdf
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
javaweb 项目pdf.js和print.js 实现pdf预览和批量打印
pdf文件预览,直接批量打印,前后端代码实现
文件流 压缩版 官网 pdfjs printjs -
Java EXCEL在线预览插件 javapdf在线预览
引言最近接到产品需求,用户需要在我们的站点上在线查看 PDF 文件,并且查看时,用户可以对 PDF 文件的进行旋转、缩放、跳转到指定页码等操作。这个太简单了,随便找找就一堆轮子。目前常见的在线 PDF 查看方案: 使用 iframe、embed、object 标签直接加载采用此方案,只需要直接将 PDF 的在线地址设置为标签的 src 属性使用第三方库 PDF.js 加载这个方案麻烦一点,我们
Java EXCEL在线预览插件 java实现word在线预览 js pdf预览 js实现pdf在线预览 js预览pdf -
java pdf 中文不显示 java pdf预览
在浏览器上预览PDF文件,某些情况下来说是一件比较简单的事情,为什么说某些情况下呢,大多数情况下,由于现代浏览器提供的优秀功能,预览PDF文件是一件简单的事情。
java pdf 中文不显示 Java PDF github h5 -
java方法中声明了事务并且该方法加锁
1、注释1.1、注释概述A: 什么是注释用于解释说明程序的文字 B: Java中注释分类单行注释格式: //注释文字多行注释格式: /* 注释文字 */文档注释格式:/** 注释文字 */C: 注释的作用 a:解释说明程序
java方法中声明了事务并且该方法加锁 java 开发语言 System 数据类型