java实现类似百文库功能linux_第1页
java实现类似百文库功能linux_第2页
java实现类似百文库功能linux_第3页
java实现类似百文库功能linux_第4页
java实现类似百文库功能linux_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

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

文档简介

1、实现类似百度文库在线观看功能目录实现原理过程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 (Flas

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

3、:/opt/3/program/soffice -headless -accept="socket,host=,port=8100;urp;" -nofirststartwizard &2.来安装openoffice sdkcd OOO330_m20_native_packed-1_en-US.9567/RPMS/rpm -vih *.rpm3.JODConverter其实不用安装 解压了就行安装jodconverter.2.2.2 ,安装了这个之后就已经可以实现DOC转PDF了。解压,复制到一个目录里面去,就能直接用了

4、,调用它里面的/lib/jodconverter-cli-2.2.2.jar这个玩意儿就行,可以直接运行命令测试:顺利的话就直接可以转成功了exec("java -jar /home/download/jodconverter-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) &

5、#160;下载中文支持及字体库wget  ftp:/ftp.foolabs.          unzip font.zipmv Gbsn00lp.ttf gkai00mp.ttf xpdf-chinese-simplified/CMap/cd /usr/share/xpdf/xpdf-chinese-simplified4)vi add-to-xpdfrc内容如下:cidToUnicode   Adobe-GB1  

6、0;    /usr/share/xpdf/xpdf-chinese-simplified/Adobe-GB1.cidToUnicodeunicodeMap     ISO-2022-CN    /usr/share/xpdf/xpdf-chinese-simplified/ISO-2022-CN.unicodeMapunicodeMap     EUC-CN     

7、;        /usr/share/xpdf/xpdf-chinese-simplified/EUC-CN.unicodeMapunicodeMap     GBK           /usr/share/xpdf/xpdf-chinese-simplified/GBK.unicodeMapcMapDir    

8、        Adobe-GB1       /usr/share/xpdf/xpdf-chinese-simplified/CMaptoUnicodeDir                      /usr/share/xp

9、df/xpdf-chinese-simplified/CMapdisplayCIDFontTT Adobe-GB1 /usr/share/xpdf/xpdf-chinese-simplified/CMap/gkai00mp.ttf保存后退出 相关Lib包安装:1)  yum y install gcc-c+(如果已安装可跳过)2)  yum install giflib-devel.x86_643)  yum install zlib-devel.x86_644)  yum install freetyp

10、e-devel.x86_645)  yum install libjpeg-devel.x86_64 SwfTool安装:1)cd /usr/local/5)./configure -prefix=/usr/local/swftools6)make7)make install8)测试一下是否可用./usr/local/swftools/bin/pdf2swf -o /path/output.swf -T -z -t -f /path/yourpdffile.pdf -s languagedir=/usr/share/xpdf/xpdf-chinese-s

11、implified -s flashversion=9项目目录及源码工程目录大致如下:另外,在lib下需要加入JodConverter压缩包中lib目录下的jar包,全部复制进去即可。ConvertServlet的servlet处理类代码如下:package org.edc.test.servlet;import java.io.File;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.

12、HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.pdfbox.pdmodel.PDDocument;import org.apache.pdfbox.util.PDFImageWriter;import com.artofsolving.jodconverter.DocumentConverter;import com.artofsolving.jodconverter.openoffice.conne

13、ction.OpenOfficeConnection;importnnection;import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;public class ConvertServlet extends HttpServlet /* * */private static final long serialVersionUID = 1L;private File sourceFile;/转换源文件private File pdfFile;/PDF目标文件private Fi

14、le swfFile;/SWF目标文件private Runtime r;private String filename="java"/private String imageUrl="E:WorkspacesWebSwfWebRootimage"+filename;private String imageUrl="/opt/wenkudemo/WebRoot/image/"+filename;public void init() throws ServletException /sourceFile = new File("

15、;E:WorkspacesWebSwfWebRootonlineread"+filename+".doc");/pdfFile = new File("E:WorkspacesWebSwfWebRootonlineread"+filename+".pdf");/swfFile = new File("E:WorkspacesWebSwfWebRootonlineread"+filename+".swf");sourceFile = new File("/opt/wenkude

16、mo/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 voi

17、d doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPost(request, response);/* * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * param request the request send by the c

18、lient to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException response.setC

19、ontentType("text/html");/转换成pdf文件if(sourceFile.exists() if(!pdfFile.exists() OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);try connection.connect();DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(sourceFile, pdfFile);pdf

20、File.createNewFile();connection.disconnect(); System.out.println("第二步:转换为PDF格式路径" + pdfFile.getPath(); catch (.ConnectException e) e.printStackTrace();System.out.println("OpenOffice服务未启动");throw e; catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e)

21、e.printStackTrace();System.out.println("读取文件失败");throw e; catch (Exception e)e.printStackTrace();try throw e; catch (Exception e1) e1.printStackTrace(); else System.out.println("已转换为PDF,无需再次转换"); else System.out.println("要转换的文件不存在"); /转换成swf文件r = Runtime.getRuntime();ne

22、w Thread()Overridepublic void run() if(!swfFile.exists()if(pdfFile.exists() try PDDocument doc = PDDocument.load(pdfFile);System.out.println("页数2-"+doc.getNumberOfPages();PDFImageWriter pdfImage=new PDFImageWriter();pdfImage.writeImage(doc, "png", null, 1, 1,imageUrl);doc.close()

23、;/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.getPath() + " -T 9");p.waitFor();swfFile.createNe

24、wFile();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.printStackTrace(); else System.ou

25、t.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.prin

26、tln(""+request.getContextPath();response.sendRedirect(request.getContextPath()+"/onlineread/readfile.jsp");readfile.Jsp显示界面代码如下:<% page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();Strin

27、g basePath = request.getScheme()+":/"+request.getServerName()+":"+request.getServerPort()+path+"/"%><!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.01 Transitional/EN"><html xmlns="/1999/xhtml" lang="en" xml:lang="e

28、n"> <head> <title>在线阅读</title> <style type="text/css" media="screen"> html, body height:100%; body margin:0; padding:0; overflow:auto; #flashContent display:none; </style> <script type="text/javascript" src="./flexpaper/js/f

29、lexpaper_flash_debug.js"></script><script type="text/javascript" src="./flexpaper/js/jquery.js"></script><script type="text/javascript" src="./flexpaper/js/flexpaper_flash.js"></script> </head> <body> <div style="position:absolute;left:200px;top:10px;"> <center> <a id="viewerPlaceHolder" style="width:1000px;height:800px;display:block">努力加载中.</a></center> <script type="text/javascript"> $(document).r

温馨提示

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

最新文档

评论

0/150

提交评论