




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实现类似百度文库在线观看功能目录实现原理过程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 (FlashPaper)= FlexPaper浏览4. Txt/Word/Excel/PPT=SWF(print2flash)= FlexPaper浏览资料和工具准备工具OpenOfficehttp:/ftp.nluug.nl/office/openoffice/stable/3.3.0/OOo_3.3.0_Linux_x86_install-rpm_en-US.tar.gzhttp:/ftp.nluug.nl/office/openoffice/stable/3.3.0/OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gzJodConverter/projects/jodconverter/files/latest/download?source=filesSwftools(pdf2swf)/download.html/swftools-0.9.1.tar.gzFlexPaper/files/FlexPaper_1.4.5_flash.zip资料方面,大致搜索了百度文库和开源中国上的一些资料,其实都大同小异。工具准备和安装1. 安装openoffice3,这个安装过程很纠结,遇到过各种问题,因为先后在几台服务器上安装过,最顺利的安装方法如下tar zxvf OOo_3.3.0_Linux_x86-64_install-rpm-wJRE_zh-CN.tar.gzcd RPEMrpm -ivh *.rpm -nodeps force安装后的默认目录是在:/opt/目录下面启动服务:/opt/3/program/soffice -headless -accept=socket,host=,port=8100;urp; -nofirststartwizard &2.来安装openoffice sdktar zxvf OOo-SDK_3.3.0_Linux_x86-64_install-rpm_en-US.tar.gzcd OOO330_m20_native_packed-1_en-US.9567/RPMS/rpm -vih *.rpm3.JODConverter其实不用安装 解压了就行安装jodconverter.2.2.2 ,安装了这个之后就已经可以实现DOC转PDF了。解压,复制到一个目录里面去,就能直接用了,调用它里面的/lib/jodconverter-cli-2.2.2.jar这个玩意儿就行,可以直接运行命令测试:java -jar /home/download/jodconverter-2.2.2/lib/jodconverter-cli-2.2.2.jar /home/download/aaa.doc /home/download/1.pdf顺利的话就直接可以转成功了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)下载中文支持及字体库wget/pub/xpdf/xpdf-chinese-simplified.tar.gzwget/download/font.zip3)tar zxvf xpdf-chinese-simplified.tar.gzunzip font.zipmv Gbsn00lp.ttf gkai00mp.ttf xpdf-chinese-simplified/CMap/cd /usr/share/xpdf/xpdf-chinese-simplified4)vi add-to-xpdfrc内容如下:cidToUnicodeAdobe-GB1/usr/share/xpdf/xpdf-chinese-simplified/Adobe-GB1.cidToUnicodeunicodeMapISO-2022-CN/usr/share/xpdf/xpdf-chinese-simplified/ISO-2022-CN.unicodeMapunicodeMapEUC-CN/usr/share/xpdf/xpdf-chinese-simplified/EUC-CN.unicodeMapunicodeMapGBK/usr/share/xpdf/xpdf-chinese-simplified/GBK.unicodeMapcMapDirAdobe-GB1/usr/share/xpdf/xpdf-chinese-simplified/CMaptoUnicodeDir/usr/share/xpdf/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 freetype-devel.x86_645)yum install libjpeg-devel.x86_64SwfTool安装:1)cd /usr/local/2)wget/swftools-0.9.1.tar.gz3)tar zxvf swftools-0.9.1.tar.gz4)cd swftools-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/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;import 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.PDFImageWriter;import com.artofsolving.jodconverter.DocumentConverter;import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;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 File 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(E:WorkspacesWebSwfWebRootonlineread+filename+.doc);/pdfFile = new File(E:WorkspacesWebSwfWebRootonlineread+filename+.pdf);/swfFile = new File(E:WorkspacesWebSwfWebRootonlineread+filename+.swf);sourceFile = new File(/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)throws 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 client * 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() OpenOfficeConnection 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.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 (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.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.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.printStackTrace(); 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.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 FlexPa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 习作:写信(教学设计)-2024-2025学年语文四年级上册统编版
- 内蒙古开鲁县高中生物 第四章 细胞的物质输入和输出 4.1 物质跨膜运输教学设计 新人教版必修1
- 五年级下册英语教案-Unit 3 Review |冀教版(三起)
- 九年级历史下册 第3课 凡尔赛-华盛顿体系的建立教学设计 岳麓版
- 人教部编版八年级下册茅屋为秋风所破歌教学设计及反思
- 安全生产环保年度培训
- 大疆无人机培训内容
- 人教部编版七年级历史上第14课 沟通中外文明的“丝绸之路”教学设计
- 人教部编版三年级上册8 卖火柴的小女孩教学设计及反思
- 2024内蒙古呼伦贝尔经济技术开发区城市建设投资集团有限责任公司公开招聘8人笔试参考题库附带答案详解
- 三级安全培训考试题附参考答案(完整版)
- 庄子:当我们无路可走的时候(原文)
- 02J611-2 轻质推拉钢大门
- DB51-T 3176-2024 四川省中心乡镇消防救援站建设规范
- DB11T 2279-2024 社会单位消防安全评估规范
- 养生理疗馆门店管理手册02
- 店里装修合同范本
- 酒店品牌建设与管理教案
- QB/T 2660-2024 化妆水(正式版)
- 国家湿地公园科普宣教规划方案
- 外国美术史1-史前美术省公开课金奖全国赛课一等奖微课获奖课件
评论
0/150
提交评论