java实现类似百度文库功能(linux)(11页).doc

上传人:1595****071 文档编号:35418205 上传时间:2022-08-21 格式:DOC 页数:11 大小:264.50KB
返回 下载 相关 举报
java实现类似百度文库功能(linux)(11页).doc_第1页
第1页 / 共11页
java实现类似百度文库功能(linux)(11页).doc_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《java实现类似百度文库功能(linux)(11页).doc》由会员分享,可在线阅读,更多相关《java实现类似百度文库功能(linux)(11页).doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、-java实现类似百度文库功能(linux)-第 11 页实现类似百度文库在线观看功能目录实现原理过程2资料和工具准备2工具准备和安装2项目目录及源码5程序运行需要openoffice服务支持12实现原理过程网上大致看了下实现的方式,大体上有四种转换的方式:1. Txt/Word/Excel/PPT=PDF(OpenOffice+JodConverter)=SWF(pdf2swf)=FlexPaper浏览2. Txt/Word/Excel/PPT=PDF(MSOffice+JACOB)=SWF(pdf2swf)=FlexPaper浏览3. Txt/Word/Excel/PPT=SWF (Fla

2、shPaper)= FlexPaper浏览4. Txt/Word/Excel/PPT=SWF(print2flash)= FlexPaper浏览资料和工具准备工具OpenOfficeJodConverterSwftools(pdf2swf)FlexPaper资料方面,大致搜索了百度文库和开源中国上的一些资料,其实都大同小异。工具准备和安装1. 安装openoffice3,这个安装过程很纠结,遇到过各种问题,因为先后在几台服务器上安装过,最顺利的安装方法如下cd RPEMrpm -ivh *.rpm -nodeps force安装后的默认目录是在:/opt/目录下面启动服务:ogram/soff

3、ice -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard &2.来安装openoffice sdkrpm -vih *.rpm其实不用安装 解压了就行安装jodconverter.2.2.2 ,安装了这个之后就已经可以实现DOC转PDF了。解压,复制到一个目录里面去,就能直接用了,调用它里面的/lib/jodconverter-cli-2.2.2.jar这个玩意儿就行,可以直接运行命令测试:顺利的话就直接可以转成功了exec(java -jar /home/download/jodconvert

4、er-2.2.2/lib/jodconverter-cli-2.2.2.jar /home/download/aaa.doc /home/download/1.pdf)4.Linux下安装pdf2swf Tool中文支持安装:1)mkdir p /usr/share/xpdfcd /usr/share/xpdf/2)下载中文支持及字体库wgetftp:/ftp.foolabs.mv Gbsn00lp.ttf gkai00mp.ttf xpdf-chinese-simplified/CMap/cd /usr/share/xpdf/xpdf-chinese-simplified4)vi add-t

5、o-xpdfrc内容如下:unicodeMapEUC-CN/usr/cMapDirAdobe-GB1/usr/share/xpdf/xpdf-chinese-simplified/CMaptoUnicodeDir/usr/share/xpdf/xpdf-chinese-simplified/CMap保存后退出相关Lib包安装:1)yum y install gcc-c+(如果已安装可跳过)SwfTool安装:1)cd /usr/local/5)./configure-prefix=/usr/local/swftools6)make7)make install8)测试一下是否可用./usr/lo

6、cal/swftools/bin/pdf2swf -o /path/output.swf -T -z -t -f /path/yourpdffile.pdf -s languagedir=/usr/share/xpdf/xpdf-chinese-simplified -s flashversion=9项目目录及源码工程目录大致如下:另外,在lib下需要加入JodConverter压缩包中lib目录下的jar包,全部复制进去即可。ConvertServlet的servlet处理类代码如下:package org.edc.test.servlet;import java.io.File;impor

7、t java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.util

8、.PDFImageWriter;import com.artofsolving.jodconverter.DocumentConverter;import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;importnnection;import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;public class ConvertServlet extends HttpServlet

9、/* * */private static final long serialVersionUID = 1L;private File sourceFile;/转换源文件private File pdfFile;/PDF目标文件private File swfFile;/SWF目标文件private Runtime r;private String filename=java;/private String imageUrl=E:WorkspacesWebSwfWebRootimage+filename;private String imageUrl=/opt/wenkudemo/WebRoo

10、t/image/+filename;public void init() throws ServletException /sourceFile = new File(E:WorkspacesWebSwfWebRootonlineread+filename+.doc);/pdfFile = new File(E:WorkspacesWebSwfWebRootonlineread+filename+.pdf);/swfFile = new File(E:WorkspacesWebSwfWebRootonlineread+filename+.swf);sourceFile = new File(/

11、opt/wenkudemo/WebRoot/onlineread/+filename+.doc);pdfFile = new File(/opt/wenkudemo/WebRoot/onlineread/+filename+.pdf);swfFile = new File(/opt/wenkudemo/WebRoot/onlineread/+filename+.swf);System.out.println(第一步:生成文件对象,准备转换);public void doGet(HttpServletRequest request, HttpServletResponse response)th

12、rows ServletException, IOException doPost(request, response);/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the cl

13、ient * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException response.setContentType(text/html);/转换成pdf文件if(sourceFile.exists() if(!pdfFile.exists() Ope

14、nOfficeConnection connection = new SocketOpenOfficeConnection(8100);try connection.connect();DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(sourceFile, pdfFile);pdfFile.createNewFile();connection.disconnect(); System.out.println(第二步:转换为PDF格式路径 + pdfFile.

15、getPath(); catch (.ConnectException e) e.printStackTrace();System.out.println(OpenOffice服务未启动);throw e; catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) e.printStackTrace();System.out.println(读取文件失败);throw e; catch (Exception e)e.printStackTrace();try throw e; catch

16、(Exception e1) e1.printStackTrace(); else System.out.println(已转换为PDF,无需再次转换); else System.out.println(要转换的文件不存在); /转换成swf文件r = Runtime.getRuntime();new Thread()Overridepublic void run() if(!swfFile.exists()if(pdfFile.exists() try PDDocument doc = PDDocument.load(pdfFile);System.out.println(页数2-+doc.

17、getNumberOfPages();PDFImageWriter pdfImage=new PDFImageWriter();pdfImage.writeImage(doc, png, null, 1, 1,imageUrl);doc.close();/windows/Process p = r.exec(D:/SWFTools/pdf2swf.exe + pdfFile.getPath() + -o + swfFile.getPath() + -T 9);/linuxProcess p = r.exec(pdf2swf + pdfFile.getPath() + -o + swfFile.

18、getPath() + -T 9);p.waitFor();swfFile.createNewFile();System.out.println(第三步:转换为SWF格式路径: + swfFile.getPath();System.out.println(第四步:转换为SWF格式mingcheng: + swfFile.getName();/if(pdfFile.exists() /pdfFile.delete();/ catch (Exception e) e.printStackTrace();try throw e; catch (Exception e1) e1.printStackT

19、race(); else System.out.println(PDF文件不存在,无法转换); else System.out.println(已经转为SWF文件,无需再次转换);.start();HttpSession session = request.getSession();session.setAttribute(fileName, swfFile.getName();System.out.println(我是测试:+session.getAttribute(fileName);System.out.println(+request.getContextPath();response

20、.sendRedirect(request.getContextPath()+/onlineread/readfile.jsp);readfile.Jsp显示界面代码如下: 在线阅读 html, body height:100%; body margin:0; padding:0; overflow:auto; #flashContent display:none; 努力加载中. $(document).ready(function() var fp = new FlexPaperViewer( ./flexpaper/FlexPaperViewer, viewerPlaceHolder, c

21、onfig : SwfFile : escape(Paper.swf), Scale : 0.6, ZoomTransition : easeOut, ZoomTime : 0.5, ZoomInterval : 0.2, FitPageOnLoad : true, FitWidthOnLoad : false, PrintEnabled : true, FullScreenAsMaxWindow : false, ProgressiveLoading : true, MinZoomSize : 0.2, MaxZoomSize : 5, SearchMatchAll : false, Ini

22、tViewMode : Portrait, ViewModeToolsVisible : true, ZoomToolsVisible : true, NavToolsVisible : true, CursorToolsVisible : true, SearchToolsVisible : true, localeChain: zh_CN ); ); 要特别注意的是:FlexPaperViewer的路径一定要正确,id对上。另外,可以用官方的Paper.swf作为测试,只需要将SwfFile的地址改掉即可。程序运行需要openoffice服务支持启动openoffice服务如下:cdC:Program Files (x86)OpenOffice 4program执行/opt/openoffice.org3/program/soffice -headless -accept=socket,host=127.0.0.1,port=8100;urp; -nofirststartwizard大致显示效果如下:

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 单元课程

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

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁