java在线预览网络pdf文件和图片
2018-01-16 14:22
363 查看
后台代码:
public void previewFileOnline(){
BufferedInputStream bis = null;
OutputStream os = null;
try {
String path = request("filePath");//网络图片地址
response().setContentType("text/html; charset=UTF-8");
if("pdf".equalsIgnoreCase(request("type"))){
response().setContentType("application/pdf");
}else{
response().setContentType("image/jpeg");
}
URL url =new URL(path);
bis = new BufferedInputStream(url.openStream());
os = response().getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count =bis.read(buffer)) != -1){
os.write(buffer, 0,count);
}
os.flush();
}catch (Exceptione) {
e.printStackTrace();
} finally {
if (os !=null){
try {
os.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
if (bis !=null){
try {
bis.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
}
}
前台代码:
public void previewFileOnline(){
BufferedInputStream bis = null;
OutputStream os = null;
try {
String path = request("filePath");//网络图片地址
response().setContentType("text/html; charset=UTF-8");
if("pdf".equalsIgnoreCase(request("type"))){
response().setContentType("application/pdf");
}else{
response().setContentType("image/jpeg");
}
URL url =new URL(path);
bis = new BufferedInputStream(url.openStream());
os = response().getOutputStream();
int count = 0;
byte[] buffer = new byte[1024 * 1024];
while ((count =bis.read(buffer)) != -1){
os.write(buffer, 0,count);
}
os.flush();
}catch (Exceptione) {
e.printStackTrace();
} finally {
if (os !=null){
try {
os.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
if (bis !=null){
try {
bis.close();
} catch (IOExceptione) {
e.printStackTrace();
}
}
}
}
前台代码:
window.open("${ctx}/battFile_previewFileOnline?filePath="+filePath+"&type="+type);
相关文章推荐
- java集成pdf.js实现pdf文件在线预览
- java通过调用OpenOffice将office文件转化为pdf 在线预览之步骤一
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- JAVA用flexpaper实现在线预览PDF文件
- C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
- PDF.js在线预览pdf、图片、txt类型文件
- java下载网络文件, ppt,pdf,图片
- 滴水穿石--Java 生成PDF文件--iText使用之插入图片和中文乱码
- java代码生成PDF文件-表格和图片
- PDF在线预览(java实现)
- java在线预览txt、word、ppt、execel,pdf代码
- linux在线预览pdf文件开发思路
- java在线预览txt、word、ppt、execel,pdf代码
- java通过url在线预览Word、excel、ppt、pdf、txt文档中的内容【只获得其中的文字】
- 使用tcpdf软件 在线预览pdf文件
- java导出pdf文件(插入图片及信息)
- java导出pdf文件(插入图片及信息)
- java将office文档pdf文档转换成swf文件在线预览
- Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用jcom转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。