在线阅读实现方案.doc

上传人:jian****018 文档编号:9876815 上传时间:2020-04-08 格式:DOC 页数:28 大小:100KB
返回 下载 相关 举报
在线阅读实现方案.doc_第1页
第1页 / 共28页
在线阅读实现方案.doc_第2页
第2页 / 共28页
在线阅读实现方案.doc_第3页
第3页 / 共28页
点击查看更多>>
资源描述
在线阅读一分析实现方式 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的时 候相当复杂,也淘汰掉了。最后直接用的第一种方式。二功能所需工具下载工具OpenOfficehttp:/zh.openoffice.org/new/zh_cn/downloads.htmlJodConverterhttp:/dldx.csdn.net/fd.php?i=992314146801277&s=08dbee95a6e2dda1a95aa8cbf4df197bSwftools(pdf2swf)http:/dldx.csdn.net/fd.php?i=389133735472350&s=2f7430ad3c00cca78ada8b4671a50b24xpdf-chinese-simplified.tar.gz (pdf2swf的中文语言包)ftp:/ftp.foolabs.com/pub/xpdf/xpdf-chinese-simplified.tar.gzFlexPaperhttp:/flexpaper.googlecode.com/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 com.doone.comm.paginaction.Pagination;import com.doone.comm.struts.BaseAction;import com.doone.knowledge.info.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(os.name); 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 /文件格式 * param fileLegalFlag /是否合法标志 false:非法 true:合法 */ public boolean isLegal(String getFileType) boolean fileLegalFlag =false; if(getFileType.equals(TXT) fileLegalFlag = true; else if(getFileType.equals(DOC)|getFileType.equals(DOCX) fileLegalFlag = true; else if(getFileType.equals(PPT)|getFileType.equals(PPTX) fileLegalFlag = true; else if(getFileType.equals(XLS)|getFileType.equals(XLSX) fileLegalFlag = true; return fileLegalFlag; readFile.jsp页面代码如下: 在线阅读 html, body height:100%; body margin:0; padding:0; overflow:auto; #flashContent display:none; !- - http:/172.0.6.26:8081/jd/upload/knowledge/swfFiles/ var fp =new FlexPaperViewer( knowledge/info/FlexPaperViewer, viewerPlaceHolder, config : SwfFile :escape(), Scale :0.6, ZoomTransition : easeOut, ZoomTime :0.5, ZoomInterval : 0.2, FitPageOnLoad : true, FitWidthOnLoad : false, PrintEnabled : false, FullScreenAsMaxWindow : false, ProgressiveLoading : true, MinZoomSize: 0.2, MaxZoomSize: 5, SearchMatchAll : false, InitViewMode : Portrait, ViewModeToolsVisible : true, ZoomToolsVisible : true, NavToolsVisible : true, CursorToolsVisible : true, SearchToolsVisible : true, localeChain: zh_CN ); paramname=movievalue=/
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!