已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 跨部门协作流程框架指南
- 关于供应链优化项目启动的通知4篇
- 生命至上安全意识从这里开始一年级主题班会课件
- 安全第一校园生活小卫士小学主题班会课件
- 心理健康关注:学会情绪管理的方法小学主题班会课件
- 2026年长沙市岳麓区事业单位人员招聘考试备考题库及答案详解
- 2026年云南省事业单位人员招聘考试参考题库及答案详解
- 2026年思茅地区事业单位人员招聘笔试模拟试题及答案详解
- 2026年天津市河东区事业单位人员招聘笔试参考试题及答案详解
- 提升心理健康,拥抱阳光成长几年级主题班会课件
- 2026年高考英语全国二卷试题(附答案)
- 山东大学2026年强基计划笔试模拟试题及答案解析(满分100分)
- 2026年时政试题及答案(108题)
- 2026年新版七年级下册道德与法治期末素养测试卷(含答案)
- 中国血脂管理指南(2023年版)解读与实践
- 2024-2025学年四川省成都市石室联中教育集团七年级(下)期中数学试卷
- 建立有效护患沟通的技巧
- 2026年合理用药培训试题及答案
- 2025华为经营管理(第8版):华为干部管理
- 食道癌课件教学课件
- 钻孔钢管桩施工工艺流程
评论
0/150
提交评论