我们具体实现思路是这样的 首先下载并安装openoffice和swftools

openoffice下载地址:http://www.openoffice.org/download/index.html
swftools下载地址:http://www.swftools.org/download.html

本源码下载地址:

去除FlexPaper水印的下载地址:http://pan.baidu.com/s/1pJDNunL

FlexPaper原版源码下载地址:http://pan.baidu.com/s/1c00C42O

本源码采用 j2ee eclipse luna+Apache tomcat7下开发 如果环境不一致,请移植一下。

这是代码的整体架构

代码首先需要修改 com.eda.test.config.db 包下jdbc.properties 我用的是mysql数据库  数据库和数据库脚本都已经打包到了源码

下数据库和测试pdf中,大家自行导入即可,如果用的是其他数据库大家自己修改下建表脚本就好。

其次修改类:ConStant.java类 把OFFICE_HOME和SWFTOOLS_HOME配置为你本机或服务器安装路径。

package com.eda.test.common;

/**
* 常量类
*
* @author luwenbin006@163.com
* @createTime 2014-11-22 下午01:49:58
*/
public class ConStant
{
/** OpenOffice安装根目录 */
public static final String OFFICE_HOME = "C:/Program Files/OpenOffice.org 3"; /** SWFTools安装根目录 */
public static final String SWFTOOLS_HOME = "D:/swftools/"; /** PDF-SWF */
public static final String SWFTOOLS_PDF2SWF_PATH = SWFTOOLS_HOME
+ "pdf2swf.exe"; /** GIF-SWF */
public static final String SWFTOOLS_GIF2SWF_PATH = SWFTOOLS_HOME
+ "gif2swf.exe"; /** PNG-SWF */
public static final String SWFTOOLS_PNG2SWF_PATH = SWFTOOLS_HOME
+ "png2swf.exe"; /** JPEG-SWF */
public static final String SWFTOOLS_JPEG2SWF_PATH = SWFTOOLS_HOME
+ "jpeg2swf.exe"; /** WAV-SWF */
public static final String SWFTOOLS_WAV2SWF_PATH = SWFTOOLS_HOME
+ "wav2swf.exe"; /** PDF合并 */
public static final String SWFTOOLS_PDFCOMBINE_PATH = SWFTOOLS_HOME
+ "swfcombine.exe"; /** 文件上传保存根目录 */
public static final String UPLOAD_BASE_DIR = "upload"; /** SWF文件后缀 */
public static final String SWF_STUFFIX = "swf";
}

下面贴点核心类的代码 FileType枚举类,主要是反映出是什么类型的文件,文件描述。:

package com.eda.test.common;

/**
* 文件类型枚举
* @author luwenbin006@163.com
* @createTime 2014-11-22 下午05:06:11
*/
public enum FileType
{
WORD2003 {
public String getValue()
{
return "Word-2003文档";
}
public String getStuffix()
{
return "doc";
}
},
EXCEL2003 {
public String getValue()
{
return "Excel-2003文档";
}
public String getStuffix()
{
return "xls";
}
},
PPT2003 {
public String getValue()
{
return "PPT-2003文档";
}
public String getStuffix()
{
return "ppt";
}
},
WORD2007 {
public String getValue()
{
return "Word-2007文档";
}
public String getStuffix()
{
return "docx";
}
},
EXCEL2007 {
public String getValue()
{
return "Excel-2007文档";
}
public String getStuffix()
{
return "xlsx";
}
},
PPT2007 {
public String getValue()
{
return "PPT-2007文档";
}
public String getStuffix()
{
return "pptx";
}
},
TXT {
public String getValue()
{
return "记事本文档";
}
public String getStuffix()
{
return "txt";
}
},
PDF {
public String getValue()
{
return "PDF文档";
}
public String getStuffix()
{
return "pdf";
}
};
public abstract String getValue(); public abstract String getStuffix();
}

bean核心类 File文件类:

package com.eda.test.entity;

import java.io.Serializable;
import java.util.Date; /**
* 文件类
* @author luwenbin006@163.com
* @createTime 2014-11-22 下午04:56:54
*/
public class File implements Serializable
{
private static final long serialVersionUID = -110840196972249172L; /**主键ID*/
private Long id;
/**文件名*/
private String fileName;
/**对应SWF文件web虚拟路径*/
private String webBasePath;
/**文件服务器路径*/
private String distPath;
/**文件大小(KB)*/
private Long fileSize;
/**文件类型*/
private String fileType;
/**文件描述*/
private String description;
/**上传时间*/
private Date uploadDate; public Long getId()
{
return id;
} public void setId(Long id)
{
this.id = id;
} public String getFileName()
{
return fileName;
} public void setFileName(String fileName)
{
this.fileName = fileName;
} public String getWebBasePath()
{
return webBasePath;
} public void setWebBasePath(String webBasePath)
{
this.webBasePath = webBasePath;
} public String getDistPath()
{
return distPath;
} public void setDistPath(String distPath)
{
this.distPath = distPath;
} public Long getFileSize()
{
return fileSize;
} public void setFileSize(Long fileSize)
{
this.fileSize = fileSize;
} public String getFileType()
{
return fileType;
} public void setFileType(String fileType)
{
this.fileType = fileType;
} public String getDescription()
{
return description;
} public void setDescription(String description)
{
this.description = description;
} public Date getUploadDate()
{
return uploadDate;
} public void setUploadDate(Date uploadDate)
{
this.uploadDate = uploadDate;
} public static long getSerialversionuid()
{
return serialVersionUID;
} public File() {} @Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
} @Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof File))
return false;
File other = (File) obj;
if (id == null)
{
if (other.id != null)
return false;
}
else if (!id.equals(other.id))
return false;
return true;
}
}

FileAction操作类,上传,转换,浏览文件 入口action类 - 最重要的一个类:

package com.eda.test.action;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import com.eda.test.action.model.FileModel;
import com.eda.test.common.ConStant;
import com.eda.test.common.FileType;
import com.eda.test.common.GerneralSessionAction;
import com.eda.test.entity.File;
import com.eda.test.util.FileUtil;
import com.eda.test.util.FileUtils; /**
* 文件处理Action
*
* @author luwenbin006@163.com
* @createTime 2014-11-22 下午05:04:29
*/
public class FileAction extends GerneralSessionAction<FileModel>
{ /**
* 跳至首页 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
public String toUpload()
{
return "index";
} /**
* 上传文件 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
public String uploadFile()
{
if(isEmptyFile())
{
this.getModel().setMessage("不允许上传空文件!");
return "toUpload";
}
if(checkMaxFileSize())
{
this.getModel().setMessage("上传文件大小限制在20M以内!");
return "toUpload";
}
if (checkFileType())
{
File file = createFile();
boolean isSuccess = getFileService().saveFile(file, this.getModel().getDoc());
this.getModel().setFiles(file);
return "toList";
}
else
{
this.getModel().setMessage("该文件类型不允许上传!");
return "toUpload";
} } /**
* 文件预览 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
public String view()
{ return "view";
} /**
* 查询所有文件 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
public String list()
{
this.getModel().setFileList(getFileService().findAll());
return "list";
} /**
* 创建File对象 方法摘要:这里一句话描述方法的用途
*
* @param
* @return File
*/
private File createFile()
{
/** 文件上传至服务器存放路径 */
String UPLOAD_DIR = getProjectRealPath() + ConStant.UPLOAD_BASE_DIR + "\\";
String BASE_PATH = getBasePath() + ConStant.UPLOAD_BASE_DIR + "/";
File file = new File();
String fileName = this.getModel().getDocFileName();
file.setFileName(fileName);
String temp = getUploadFileName(fileName, null);
String swfBasePath = BASE_PATH + temp;
file.setDistPath(UPLOAD_DIR + temp);
temp = FileUtils.getFileNameNoStuffix(temp) + "." + ConStant.SWF_STUFFIX;
swfBasePath = BASE_PATH + temp;
file.setWebBasePath(swfBasePath);
file.setDescription(this.getModel().getDescription());
file.setFileSize(this.getModel().getDoc().length());
file.setUploadDate(new Date());
String stuffix = FileUtil.getFileSufix(fileName);
file.setFileType(getFileTypeName(stuffix));
return file;
} /**
* 生成上传后文件名称 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
public String getUploadFileName(String orignalFileName, String extension)
{
String stuffix = extension;
if (null == extension || "".equals(extension))
{
stuffix = FileUtil.getFileSufix(orignalFileName);
}
Date currentDate = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
return dateFormat.format(currentDate) + "." + stuffix;
} /**
* 获取文件类型名称 方法摘要:这里一句话描述方法的用途
*
* @param
* @return String
*/
private String getFileTypeName(String fileStuffix)
{
String fileTypeName = "";
if (fileStuffix.equals(FileType.WORD2003.getStuffix()))
{
fileTypeName = FileType.WORD2003.getValue();
}
else if (fileStuffix.equals(FileType.WORD2007.getStuffix()))
{
fileTypeName = FileType.WORD2007.getValue();
}
else if (fileStuffix.equals(FileType.EXCEL2003.getStuffix()))
{
fileTypeName = FileType.EXCEL2003.getValue();
}
else if (fileStuffix.equals(FileType.EXCEL2007.getStuffix()))
{
fileTypeName = FileType.EXCEL2007.getValue();
}
else if (fileStuffix.equals(FileType.PPT2003.getStuffix()))
{
fileTypeName = FileType.PPT2003.getValue();
}
else if (fileStuffix.equals(FileType.PPT2007.getStuffix()))
{
fileTypeName = FileType.PPT2007.getValue();
}
else if (fileStuffix.equals(FileType.TXT.getStuffix()))
{
fileTypeName = FileType.TXT.getValue();
}
else if (fileStuffix.equals(FileType.PDF.getStuffix()))
{
fileTypeName = FileType.PDF.getValue();
}
else
{
fileTypeName = "未知类型";
}
return fileTypeName;
} /**
* 检查文件类型是否允许上传 方法摘要:这里一句话描述方法的用途
*
* @param
* @return boolean
*/
private boolean checkFileType()
{
String fileType = this.getModel().getDocContentType();
if (null == fileType || fileType.equals(""))
{
return false;
}
String[] allowTypes = this.getModel().getAllowTypes().split(",");
for (int i = 0; i < allowTypes.length; i++)
{
if (allowTypes[i].equals(fileType))
{
return true;
}
}
return false;
} /**
* 检查文件大小
*方法摘要:这里一句话描述方法的用途
*@param
*@return boolean
*/
private boolean checkMaxFileSize()
{
if(this.getModel().getMaxUploadSize() < this.getModel().getDoc().length())
{
return true;
}
return false;
} /**
* 检查是否空文件
*方法摘要:这里一句话描述方法的用途
*@param
*@return boolean
*/
private boolean isEmptyFile()
{
return this.getModel().getDoc().length() == 0;
}
}

其他的就大家自己去看源码吧,经过上面的步骤,把源码部署到tomcat就能看到源码运行的效果了,破解版本的FlexPaper似乎设置那些参数有些问题,

就是设置了放大比例什么的没效果,这个如果有影响且不在意logo的,那就用原版本吧或者买一个个人版本或者商业版本。

感谢大家的关注,本文可以转载,转载请注明出处:http://www.cnblogs.com/luwenbin/p/4114576.html

JAVA实现word doc docx pdf excel的在线浏览 - 仿百度文库 源码的更多相关文章

  1. Java生鲜电商平台-小程序或者APP优惠券的设计与源码实战

    Java生鲜电商平台-小程序或者APP优惠券的设计与源码实战 说明:Java生鲜电商平台-小程序或者APP优惠券的设计与源码实战,优惠券是一种常见的促销方式,在规定的周期内购买对应商品类型和额度的商品 ...

  2. java将word文件转为pdf

    import java.io.File; import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch; public ...

  3. Java转换Word文件到PDF文件

    使用Docx4j将Word文件转换为PDF文件: public static void convertDocxToPDF(String docxFilePath, String pdfPath) th ...

  4. pywin32 pywin32 docx文档转html页面 word doc docx 提取文字 图片 html 结构

    https://blog.csdn.net/X21214054/article/details/78873338# python docx文档转html页面 - 程序猿tx - 博客园 https:/ ...

  5. 【ASP.NET 进阶】仿百度文库文档在线预览(支持格式.pdf,.doc,docx,xls,xlsx,.ppt,pptx)

    在[ASP.NET]PDF文件在线预览(类似百度文库)基础上进行了office文件到pdf文件的转换,然后在显示出来,效果如下: 问题说明: 1.请通过以下方式添加 Office COM 组件. 2. ...

  6. Java+FlexPaper+swfTools仿百度文库文档在线预览系统设计与实现

    笔者最近在给客户开发文档管理系统时,客户要求上传到管理系统的文档(包括ppt,word,excel,txt)只能预览不允许下载.笔者想到了百度文库和豆丁网,百度文库和豆丁网的在线预览都是利用flash ...

  7. Java网络编程与NIO详解11:Tomcat中的Connector源码分析(NIO)

    本文转载 https://www.javadoop.com 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.c ...

  8. Java日期时间API系列8-----Jdk8中java.time包中的新的日期时间API类的LocalDate源码分析

    目录 0.前言 1.TemporalAccessor源码 2.Temporal源码 3.TemporalAdjuster源码 4.ChronoLocalDate源码 5.LocalDate源码 6.总 ...

  9. word doc转pdf

    from win32com.client import constants, gencache # TODO pip install pywin32 -i http://mirrors.aliyun. ...

随机推荐

  1. 安装oracle 12c遇到问题

    安装前步骤:更改用户账户控制设置:从不通知  出现 "SEVERE: [FATAL] [INS-30014] 无法检查指定的位置是否位于 CFS 上" 解决办法:重新设置hosts ...

  2. C# ACM poj1006

    中国剩余定理 public static void acm1006(int a, int b, int c, int d) { * ; * ; * ; * * ; ) * z; ) * y; ) * ...

  3. CSS3滤镜!!!

    <!DOCTYPE html> <html> <head> <style> img { width: 33%; height: auto; float: ...

  4. 给div设置一个关闭按钮.

    造轮子好难. 用惯了框架提供的组件,某天自己要做个伪组件(或者在他人创建的页面效果上添加新功能)会发现很难. 所以,碰到了,就一定要做下记录.以供日后查阅. 如图,弹出DIV右上角的关闭按钮是我此次添 ...

  5. (poj)1806 Currency Exchange

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

  6. 【译】velocity

    本文原文地址:http://davidwalsh.name/intro-javascript-animation 就像许多开发者确信的那样,在Web上使用CSS实现动画并不是唯一的方式,我们也可以使用 ...

  7. Kinetic使用注意点--canvas

    <virtual> new Canvas(width, height) 参数: width:canvas宽度 height:canvas高度 方法: applyShadow(shape, ...

  8. sbrk and coreleft

    一.sbrk 函数来源:TC2.0.Linux 函数名: sbrk 功 能: 增加程序可用数据段空间,增加大小由参数 incr决定 . 返回值:函数调用成功返回一指针,指向新的内存空间.函数调用失败则 ...

  9. spring IOC源码分析(2)

    refresh这个方法包含了整个BeanFactory初始化的过程,定位资源由obtainFreshBeanFactory()来完成, protected ConfigurableListableBe ...

  10. 使用KVC

    KVC是Key Value Coding的简称,意思是键值编码,号称Cocoa的大招.它是一种可以直接通过字符串key(对象在名称)来访问或修改对象属性的机制. 使用 1.利用KVC可以随意修改一个对 ...