java實現(xiàn)類似百文庫功能linux_第1頁
java實現(xiàn)類似百文庫功能linux_第2頁
java實現(xiàn)類似百文庫功能linux_第3頁
java實現(xiàn)類似百文庫功能linux_第4頁
java實現(xiàn)類似百文庫功能linux_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、實現(xiàn)類似百度文庫在線觀看功能目錄實現(xiàn)原理過程2資料和工具準備2工具準備和安裝2項目目錄及源碼5程序運行需要openoffice服務支持12實現(xiàn)原理過程網(wǎng)上大致看了下實現(xiàn)的方式,大體上有四種轉(zhuǎn)換的方式: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,這個安裝過程很糾結(jié),遇到過各種問題,因為先后在幾臺服務器上安裝過,最順利的安裝方法如下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 ,安裝了這個之后就已經(jīng)可以實現(xiàn)DOC轉(zhuǎn)PDF了。解壓,復制到一個目錄里面去,就能直接用了

4、,調(diào)用它里面的/lib/jodconverter-cli-2.2.2.jar這個玩意兒就行,可以直接運行命令測試:順利的話就直接可以轉(zhuǎn)成功了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內(nèi)容如下: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保存后退出 相關(guān)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壓縮包中l(wèi)ib目錄下的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;/轉(zhuǎn)換源文件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("第一步:生成文件對象,準備轉(zhuǎn)換");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");/轉(zhuǎn)換成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("第二步:轉(zhuǎn)換為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("已轉(zhuǎn)換為PDF,無需再次轉(zhuǎn)換"); else System.out.println("要轉(zhuǎn)換的文件不存在"); /轉(zhuǎn)換成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("頁數(shù)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("第三步:轉(zhuǎn)換為SWF格式路徑:" + swfFile.getPath();System.out.println("第四步:轉(zhuǎn)換為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文件不存在,無法轉(zhuǎn)換"); else System.out.println("已經(jīng)轉(zhuǎn)為SWF文件,無需再次轉(zhuǎn)換");.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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論