在线阅读实现方案.doc_第1页
在线阅读实现方案.doc_第2页
在线阅读实现方案.doc_第3页
在线阅读实现方案.doc_第4页
在线阅读实现方案.doc_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

在线阅读一分析实现方式 Txt/Word/Excel/PPT=PDF(OpenOffice+JodConverter)=SWF(pdf2swf)=FlexPaper浏览 Txt/Word/Excel/PPT=PDF(MSOffice+JACOB)=SWF(pdf2swf)=FlexPaper浏览 Txt/Word/Excel/PPT=SWF (FlashPaper)= FlexPaper浏览 Txt/Word/Excel/PPT=SWF(print2flash)= FlexPaper浏览前两种方式比较麻烦,都是先转成PDF,再转成SWF,最后用FlexPaper浏览。后两种比较快捷,可直接将源文件转为SWF,用 FlexPaper浏览。由于FlashPaper不是开源工具,加之Win7系统不兼容(我现在用的系统),所以就没采用第三种实现方式。 Print2flash是开源工具,即使公司产品中用到也不会出现版权纠纷,遗憾的是没找到如何用程序控制该工具转换文件的命令。第二种方式转PDF的时 候相当复杂,也淘汰掉了。最后直接用的第一种方式。二功能所需工具下载工具OpenOffice/new/zh_cn/downloads.htmlJodConverter/fd.php?i=992314146801277&s=08dbee95a6e2dda1a95aa8cbf4df197bSwftools(pdf2swf)/fd.php?i=389133735472350&s=2f7430ad3c00cca78ada8b4671a50b24xpdf-chinese-simplified.tar.gz (pdf2swf的中文语言包)/pub/xpdf/xpdf-chinese-simplified.tar.gzFlexPaper/files/FlexPaper_1.4.5_flash.zip本来想把自己实际用到没问题的安装文件上传上来,但是太大了,无法共享。 当时的下载地址又找不到了,好吧,悲催了。截图自己用到的版本三、搭建所需环境及实现第一步:安装OpenOffice。从上述下载地址得到可执行安装文件,直接双击执行,安装过程较为人性化,只需选择下一步即可。此处注意下安装路径,文件转换之前需在Windows命令行窗口打开安装根目录,然后执行开启服务命令。第二步:解压JodConverter。解压目录结构如下图:打开lib文件夹,将其中的jar包复制到Web工程的WebRoot/WEB-INF/lib下。第三步:安装Swftools。从下载的压缩包中解压得到可执行安装文件,直接双击执行。该转换工具用来将 pdf文件转换成swf文件。改工具既可以安装使用实现文件转换,也拷贝安装后Program Files下的Swftools文件夹放到工程中,以绿色软件方式来使用。转换命令将在FileConverterUtil.java中特别指明。第四步:使用Flexpaper。Flexpaper就是一个播放swf文件的播放器。解压后目录如下:其中Paper.swf、所有的txt文件、php文件夹和example文件夹都可以删掉。清理完之后,新建readFile.jsp(jsp页面代码在后面附加),然后将flexpaper文件夹拷贝到WebRoot下即可。FileConverterUtil.java代码如下:import java.io.BufferedReader;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.LineNumberReader;import java.util.HashMap;import java.util.List;import java.util.Properties;import org.apache.struts2.ServletActionContext;import com.artofsolving.jodconverter.DocumentConverter;importcom.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;importcom.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;import m.paginaction.Pagination;import m.struts.BaseAction;import .dao.KnowledgeInfoDao;/* 课件资源管理* authorhsp*/public class KnowledgeInfoAction2 extends BaseAction private Paginationpage = new Pagination();/ 分页对象 private KnowledgeInfoDaoknowledgeInfoFacade; private HashMapknowledgeInfoMap = newHashMap(); /* * 获取知识信息 * return */ SuppressWarnings(unchecked) public String seeKnowledgeInfo()throws Exception String id=this.getRequest().getParameter(kinfoid); /信息评论分页: /设置每页显示多少条 page.setPageRecord(5); /求出总记录数并判断是否为第一次查询 if(getQueryFlag(page) = -1) page.setTotalRecord(knowledgeInfoFacade.getKnowledgeRecommentCount(id); else page.setTotalRecord(getQueryFlag(page); /设置查询条件 this.setPageParameters(page,page); /结果List HashMap infoMap = knowledgeInfoFacade.getKnowledgeInfoInfo(id,page.getPageStart(), page.getPageRecord(); knowledgeInfoMap=(HashMap)infoMap.get(kinfo); if(infoMap.get(krecomment)!=null&!.equals(infoMap.get(krecomment) List list=(List)infoMap.get(krecomment); this.getRequest().setAttribute(recommentList, list); /文件类别 String fileType =this.knowledgeInfoMap.get(KNOWLEDGE_FILE_TYPE).toString().substring(1,knowledgeInfoMap.get(KNOWLEDGE_FILE_TYPE).toString().length(); /是否可预览标志 0普通文档,MP3,SWF,可以预览, 1不支持的文件类型,不能预览 2,MP4播放 String previewFlag=; String returnValue=; /可以预览的文件 if(fileType.equals(XLS) | fileType.equals(PPT) | fileType.equals(DOC) |fileType.equals(PDF) | fileType.equals(TXT) | fileType.equals(MP3) |fileType.equals(SWF) previewFlag = 0; returnValue=nomp4; else if(fileType.indexOf(.MP4)0) returnValue=mp4; previewFlag = 2; else returnValue=nomp4; previewFlag = 1; System.out.println(fileType=+fileType+=+ previewFlag+ previewFlag.equals(0); /*以下为文件预览*/ if(previewFlag.equals(0) /服务器信息 Properties props=System.getProperties(); /不同系统分隔符 String separator=props.getProperty(file.separator); /系统版本Linux,Window XP,Window 7 String os_name=props.getProperty(); String os_flag=; if(os_name.indexOf(Linux)=0) os_flag=linux; else if(os_name.indexOf(Windows)=0) os_flag=window; /服务器存储的文件名称 201212171709212889.doc String sysFileName=this.knowledgeInfoMap.get(KNOWLEDGE_PATH).toString(); /文件原名年会活动初稿请车友定稿.doc String oriFileName =this.knowledgeInfoMap.get(KNOWLEDGE_FNAME).toString(); /文件完整路径 /window下是一个反斜杠 /linux 下是一个正斜杠/home/apache-tomcat-6.0.33/webapps/jd/WebRoot/upload/knowledge/201212181318342606.ppt String fullPath =ServletActionContext.getServletContext().getRealPath(separator+upload+separator+knowledge+separator+sysFileName); /文件夹名称绝对路径 F:workspacedoone-jdeduWebRootuploadknowledge StringfolderName=fullPath.substring(0,fullPath.lastIndexOf(separator); /与sysFileName保持一致,如果已经存在,不再每次生成 String sysFileName_temp =sysFileName.substring(0,sysFileName.lastIndexOf(.); /工程的绝对路径 String basePath = this.getRequest().getScheme()+:/+this.getRequest().getServerName()+:+this.getRequest().getServerPort()+this.getRequest().getContextPath(); File sourceFile; /转换源文件 File pdfFile; /PDF媒介文件 File swfFile; /SWF目标文件 File createPath; /创建文件存放目录 Runtime rt; /转换命令执行类 String finalFilePath = ;/最终显示在前台的转换之后的SWF文件名称 String swfToolsPath =;/swfTools 安装路径, if(os_flag.equals(linux) swfToolsPath=; else swfToolsPath =C:Program FilesSWFTools; /swf if(fileType.equals(SWF) /文件原路径 finalFilePath = basePath+separator+upload+separator+knowledge+separator+sysFileName; System.out.println(ItsSWF=+finalFilePath); /pdf if(fileType.equals(PDF) /PDF格式文件处理方式 rt = Runtime.getRuntime(); sourceFile = new File(fullPath); /创建SWF文件存放目录 createPath = new File(folderName+separator+swfFiles+separator); if(!createPath.isDirectory() createPath.mkdir(); swfFile = new File(folderName+separator+swfFiles+separator+sysFileName_temp+.swf); /为了避免版本问题,不用7,8版本,用9 Process p= null; if(os_flag.equals(window) p =rt.exec(swfToolsPath+pdf2swf.exe + sourceFile.getPath() + -o +swfFile.getPath() + -T 9); else p =rt.exec(pdf2swf -slanguagedir=/usr/local/xpdf-chinese-simplified -T 9 -s poly2bitmap -s zoom=150-s flashversion=9 + sourceFile.getPath()+ -o +swfFile.getPath(); /各系统清理缓存 if(os_flag.equals(window) clearCache(p.getInputStream(),p.getErrorStream(); else if(os_flag.equals(linux) InputStreamReader ir=newInputStreamReader(p.getInputStream(); LineNumberReader input = new LineNumberReader(ir); Stringline; while (line =input.readLine () !=null) System.out.println(linux clear=+line); finalFilePath =basePath+separator+upload+separator+knowledge+separator+swfFiles+separator+sysFileName_temp+.swf; System.out.println(ItsPDF=sourceFile+sourceFile.getPath()+=+swfFile+=+finalFilePath); /非pdf,非swf else System.out.println(Its +fileType+=+sysFileName_temp); /非PDF格式文件处理方式 if(isLegal(fileType.toUpperCase() sourceFile = new File(fullPath); pdfFile = new File(folderName+separator+swfFiles+separator+sysFileName_temp+.pdf); swfFile = new File(folderName+separator+swfFiles+separator+sysFileName_temp+.swf); if(!pdfFile.exists() /获取连接对象 OpenOfficeConnection connection = newSocketOpenOfficeConnection(8100); /取得连接 connection.connect(); /创建文件格式转换对象 DocumentConverter converter = newOpenOfficeDocumentConverter(connection); /实现文件格式转换 converter.convert(sourceFile, pdfFile); /生成已转换的PDF文件 pdfFile.createNewFile(); /释放连接 connection.disconnect(); System.out.println(create a new pdf=+pdfFile.getParent(); if(!swfFile.exists() rt = Runtime.getRuntime(); /执行PDF文件转换成SWF文件命令 /linux命令: pdf2swf -slanguagedir=/usr/local/xpdf-chinese-simplified-T 9 -s poly2bitmap -s zoom=150 -sflashversion=9/home/s.pdf -o /home/%.swf Process p= null; if(os_flag.equals(window) p = rt.exec(swfToolsPath+pdf2swf.exe + pdfFile.getPath() + -o + swfFile.getPath() + -T 9); else p = rt.exec(pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified -T 9 -spoly2bitmap -s zoom=150 -s flashversion=9 + pdfFile.getPath() + -o +swfFile.getPath(); /各系统清理缓存 if(os_flag.equals(window) clearCache(p.getInputStream(),p.getErrorStream(); elseif(os_flag.equals(linux) InputStreamReader ir=newInputStreamReader(p.getInputStream(); LineNumberReader input = new LineNumberReader(ir); String line; while (line = input.readLine () !=null) System.out.println(linux clear=+line); System.out.println(create a new swf=+swfFile.getParent(); else /如果已经存在了pdf,但是swf由于某种原因不存在 if(!swfFile.exists() rt = Runtime.getRuntime(); /执行PDF文件转换成SWF文件命令 /linux命令: pdf2swf -slanguagedir=/usr/local/xpdf-chinese-simplified-T 9 -s poly2bitmap -s zoom=150 -sflashversion=9 /home/s.pdf-o /home/%.swf Process p= null; if(os_flag.equals(window) p= rt.exec(swfToolsPath+pdf2swf.exe + pdfFile.getPath() + -o +swfFile.getPath() + -T 9); else p= rt.exec(pdf2swf -s languagedir=/usr/local/xpdf-chinese-simplified-T 9 -s poly2bitmap -s zoom=150 -s flashversion=9 + pdfFile.getPath() + -o +swfFile.getPath(); /各系统清理缓存 if(os_flag.equals(window) clearCache(p.getInputStream(),p.getErrorStream(); elseif(os_flag.equals(linux) InputStreamReader ir=newInputStreamReader(p.getInputStream(); LineNumberReader input = new LineNumberReader(ir); String line; while (line =input.readLine () !=null) System.out.println(linux clear=+line); System.out.println(pdf exists,but create a new swf=+swfFile.getParent(); System.out.println(pdf exists=+swfFile.getParent(); finalFilePath =basePath+separator+upload+separator+knowledge+separator+swfFiles+separator+sysFileName_temp+.swf; /可以预览的,放解析后的文件完整路径到页面 this.getSession().setAttribute(finalFilePath, finalFilePath); this.getSession().setAttribute(previewFlag,previewFlag); this.getSession().setAttribute(fileType,fileType); return returnValue; /* * 清理缓冲区 * param isi * param ise */ public void clearCache(InputStream isi, InputStream ise) try System.out.println(clearCache=+isi.toString()+=+ise.toString(); final InputStream is1 = isi; /启用单独线程清空InputStream缓冲区 new Thread(new Runnable() public void run() System.out.println(before BufferedReader=); BufferedReaderbr = new BufferedReader(new InputStreamReader(is1); try while(br.readLine() !=null) ; catch (IOException e) e.printStackTrace(); ).start(); /读入ErrorStream缓冲 System.out.println(333333333333333333333333); BufferedReader br = new BufferedReader(new InputStreamReader(ise); /保存缓冲输出结果 StringBuilder buf = new StringBuilder(); String line = null; try System.out.println(beforereadLine=); line = br.readLine(); catch (IOException e) e.printStackTrace(); /循环等待进程结束 while(line !=null) buf.append(line); is1.close(); ise.close(); br.close(); catch (Exception e) System.out.println(clearCacheException=+e+=); e.printStackTrace(); /* * 判断所转换文件类型是否合法 * paramgetFileType /文件格式 * par

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论