版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实现类似百度文库在线观看功能目录实现原理过程2资料和工具准备2工具准备和安装2项目目录及源码6程序运行需要openoffice服务支持1810/19实现原理过程 网上大致看了下实现的方式,大体上有四种转换的方式:1. Txt/Word/Excel/PPT=PDF(OpenOff ice+JodConverter)=SWF(pdf2swf)=FlexPap er浏览2. Txt/Word/Excel/PPT二PDF (MSOf f ice+JACOB)二SWF (pdf2swf)二FlexPaper 浏览-Txt/Word/ExceLPPT=SWF (FlashPaper)二FlexPaper
2、浏览4T-Txt/Word/Excel/PPT二SWF (print2flash)二)FlexPaper 浏览资料和工具准备工具OpenOfficeJodConverterSwftools(pdf 2swf)FlexPaper资料方面,大致搜索了百度文库和开源中国上的一些资料,其实都大同小异。工具准备和安装1 .安装openoffice3,这个安装过程很纠结,遇到过各种问题,因为先后在几台服务器上安装过,最顺利的安装方法如下tar zxvf 00o_3 3. 0_Linux_x86-64_install-rpm-wJRE_zh-CN. tar. gzcd RPEMrpm -ivh *. rpm
3、 -nodeps - force安装后的默认目录是在:/opt/目录下面启动服务:/opt/openoff ice. org3/program/soffice -headless一accept二socket, host=127 0 0 1, port=8100;urp;/z -nof irststartwizard &2 .来安装 openoffice sdktar zxvf 00o-SDK_3. 3. 0_Linux_x86-64_install-rpm_en-US. tar. gzcd 000330_m20_native_packed-l_en-US. 9567/RPMS/rpm -vih
4、 *. rpm3 . JODConverter其实不用安装 解压了就行安装jodconverter. 2. 2. 2 ,安装了这个之后就已经可以实现DOC转PDF 了。解压,复制到一个目录里面去,就能直接用了,调用它里面的/lib/jodconverter-cli-2. 2. 2. jar这个玩意儿就行,可以直接运行命令测试:java -jar /home/down1oad/jodeonverter-2. 2. 2/1ib/jodconverter-cli-2. 2. 2. jar/home/download/aaa. doc /home/download/1. pdf顺利的话就直接可以转成功
5、了exec (java -jar/home, down 1 oad,/jodconverter-2. 2. 2/lib/jodconverter-cli-2. 2. 2. jar/home, download/aaa. doc /home/down1oad/1. pdf)4 . Linux 下安装 pdf2swf Tool中文支持安装:1) inkdir -p /usr/ share/xpdfcd /usr/share/xpdf/2) 下载中文支持及字体库wgetwget3) tar zxvf xpdf-chinese-simplified. tar. gzunzip font.zipmv G
6、bsnOOlp. ttf gkaiOOmp. ttf xpdf-chinese-simplified/CMap/cd /usr/share/xpdf/xpdf-Chinese-simplified4) vi add-to-xpdfrc内容如下:cidToUnicode Adobe-GBl/usr/share/xpdf/xpdf-chinese-simp1ified/Adobe-GB1. cidToUnicodeunicodeMapISO-2022-CN/us r/share/xpdf/xpdf-chinese-simplif ied/IS0-2022-CN. unicodeMapunicode
7、MapEUC-CN/usr/share/xpdf./xpdf-chinese-simplified/EUC-CN. unicodeMapunicodeMapGBK/usr/share/xpdf/xpdf-chinese-simplified/GBK. unicodeMapcMapDirAdobe-GBl/usr/share/xpdf/xpdf-chinese-simplified/CMaptoUnicodeDir/usr/share/xpdf/xpdf-chinese-simplified/CMapdisplayCIDFontTT Adobe-GBl/usr/share/xpdf/xpdf-c
8、hinese-simplified/CMap/gkaiOOmp.ttf保存后退出相关Lib包安装:1) yum -y install gcc-c+(如果己安装可跳过)2)yum install giflib-devel. x86_643)yum install zlib-devel. x86_644)yum install freetype-devel. x86_645)yum install libjpeg-devel. x86_64SwfTool 安装:1) cd Zusr/local/2) wget3) tar zxvf swftools-0. 9. 1. tar. gz4) cd sw
9、ftools-0. 9. 15) . /configure -prefix=/usr/local/swftools6) make7) make install8)测试一下是否可用 /usr/local/swftools/bin/pdf2swf -o /path/output, swf -T -z -t -f /path/yourpdf s languagedir=/usr/share/xpdf/xpdf-chinese-simplified -s flashversion=9项目目录及源码工程目录大致如下:用 Package Explorer 赛 1 3 WebSwf 3 src“由 org.
10、edc.test.servlett 团 ConvertServlet.java & JRE System Library com.sun.java.jdk.win32. | 园 Java EE 5 Libraries 包 Referenced Libraries/ 言 WebRoot/ 韵 flexpaper t 黄 examples D &js D B php圄 Changelog.txtLLdQQES3 FlexPaperViewer.swf .X highlight.xml index.htmlLICENSE COMMERCIALe UCENSE-UNLIMITED.tzt LICENS
11、E.txtSH3 Paper.swf包9 playerProd uctlnstall.swf 囿 report.xml t & META-INF / onlinereadEH3 Paper.swf readfile.jsp 6 WEB-INFi n dex.isp1另外,在lib下需要加入JodConverter压缩包中lib目录下的jar包,全部复制进去 即可。名称修改日期大小凶 commons-cli-1.2.jar2009/4/11 13:09Executable Jar File41 KB阖 commons-io-1.4.jar2009/4/11 13:10Executable Jar
12、 File107 KB一 DEPENDENCIES.txt2007/12/19 17:44义小文档1 KB国 jodconverter-2.2.2.jar2009/4/11 13:10Executable Jar File32 KB_ jodconverter-cli-2.2.2.jar2009/4/11 13:20Executable Jar File6 KB_ juh-3.0.1.jar2009/4/H 13:10Executable Jar File55 KB国 jurt-3.0.1.jar2009/4/11 13:10Executable Jar File106 KB. ridl-3.
13、0.1.jar2009/4/11 13:10Executable Jar File248 KB国 slf4j-api-1.5.6.jar2009/4/11 13:11Executable Jar File22 KB_ slf4j-jdkl4-1.5.6.jar2009/4/11 13:11Executable Jar File9 KB,unoil-3.0.1jar2009/4/11 13:11Executable Jar File1,329 KBM xstream-1.3.1.jar2009/4/11 13:11Executable Jar File422 KBConvertServlet的s
14、ervlet处理类代码如下:package org. edc. test, servlet;import java. io. File;import java. io. lOException;import javax. servlet. ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet,http.HttpServletResponse;importjavax.servlet.http.HttpSession;
15、import org. apache, pdfbox. pdmodel. PDDocument;import org. apache, pdfbox. util. PDFImageWriter;import com. artofsolving, jodconverter. DocumentConverter;importcom. artofsolving. jodconverter. openoffice, connection. OpenOfficeConnection;importcom. artofsolving. jodconverter. openoffice, connection
16、. SocketOpenOfficeConnec tion;importcom. artofsolving. jodconverter. openoffice, converter. OpenOfficeDocumentConve rter;public class ConvertServlet extends HttpServlet /*/private static final long serialVersionUID = IL;private ; 转换源文件private ; PDF目标文件private ; SWF目标文件private Runtime r;private Strin
17、g =java;/ private String imageUrl=,E: WorkspacesWebSwfWebRootimage,+; private String imageUrl=/opt/wenkudemo/WebRoot/ image/,z+;public void init () throws ServletException sourceFile = newFile (Z,E: WorkspacesWebSwfWebRootonlineread/z+z doc);/pdfFile = newFile (E: WorkspacesWebSwfWebRoot onlineread+
18、. pdf);/swfFile = newFile(E:WorkspacesWebSwfWebRootonlineread. swf);sourceFile = new File(/opt/wenkudemo/WebRoot/onlineread/+doc);pdfFile = new File (,/opt/wenkudemo/WebRoot/onlineread/,+,/. pdf);swfFile = new File(/opt/wenkudemo/WebRoot/onlineread/+swf);System. out. printin(第一步:生成文件对象,准备转换);)public
19、 void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, lOException (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
20、 server* param response the response send by the server to the client* throws ServletException if an error occurred* throws lOException if an error occurred* /public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, lOException (response. setContentTypeCzt
21、ext/htmlz,);转换成逐文件if (source () if(!pdf() OpenOfficeConnection connection = newSocketOpenOfficeConnection(8100);try (connection, connect ();DocumentConverter converter = newOpenOfficeDocumentConverter(connection);converter, convert (sourceFile, pdfFile);pdf ();connection, disconnect ();System. ouZ.
22、printin(第二步:转换为PDF格式 路径 + pdf (); catch (java. net. ConnectException e) e.printStackTrace ();System. out. printin (OpenOffice 服务未启动);throw e; catch(com. artofsolving, jodconverter. openoffice, connection. OpenOfficeException e) e.printStackTrace ();System. out. printin (读取文件失败);throw e; catch (Excep
23、tion e) e.printStackTrace();try (throw e;? catch (Exception el) el. printStackTrace ();) else System. out. print In (己转换为PDF,无需再次转换);) else System. out. printin (要转换的文件不存在);)转换成swf文件r 二 Runtime. getRuntimeQ ;new Thread () Overridepublic void run() if (!swf () if (pdf () try (PDDocument doc = PDDocum
24、ent. /odd(pdfFile);System, out. printin (页数2一+doc. getNumberOfPages ();PDFImageWriter pdfImage=new PDFImageWriter();pdfImage, writelmage(doc, png,null, 1, 1, imageUrl);doc. close ();/windows/Process p = r. exec (z,D:/SWFTools/pdf2swf. exe + pdf ()+ -O + swf() + -T 9);/linuxProcess p = r. exec (,pdf2
25、swf + pdf () + -o + swf () + -T 9);p. wait For ();swf();System. o.printin(第三步:转换为SWF格式路径: + swf ();System. o”2.printin(第四步:转换为SWF格式mingcheng: + swf ();/if (pdf () /pdf ();/) catch (Exception e) e.printStackTrace();try ( throw e;catch (Exception el) el. printStackTrace ();):else System. out. printin
26、(PDF文件不存在,无法转换);) else System. out. printin (已经转为SWF文件,无需再次转换);. start ();HttpSession session = request. getSessionO;session. setAttribute(,swf();System. out. println(我是;则试:+session. getAttribute (,z);System. out. print In C,z,+request. getContextPath ();response. sendRedirect(request. getContextPat
27、h()+/onlineread/read);)read显示界面代码如下:% page language二 java import=java. util. * pageEncoding= ”UTF-8shtml xmlns= lang= en xml: lang= entitle在线阅读/title)style type= text/css media=screen ”)html, body height:100% body ( margin: 0 padding: 0 overflow:auto; #flashContent display:)script type= text/javascr
28、ipt77src=./fl expaper/js/fl expaper_ flashy debug. Js 今/scriptscript type= /text/javascriptsrc=./flexpaper/js/jquery. js 6script type= text/javascriptsrc= . /fl expaper/js/fl expaper_ fl ash. jsdiv style=position:absolute;left:200px; top: 1 Opx; 3 a id= viewerPlaceHolder style= width: 1 OOOpx; heigh t: SOOpx; di splay: bl ock 今努力加载 中script type=text/javascript $(document). ready(function 0 var fp = new FlexPape
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论