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

下載本文檔

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

文檔簡介

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

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內(nèi)容如下: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壓縮包中l(wèi)ib目錄下的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 ; 轉(zhuǎn)換源文件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(第一步:生成文件對象,準備轉(zhuǎn)換);)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,);轉(zhuǎn)換成逐文件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(第二步:轉(zhuǎn)換為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 (己轉(zhuǎn)換為PDF,無需再次轉(zhuǎn)換);) else System. out. printin (要轉(zhuǎn)換的文件不存在);)轉(zhuǎn)換成swf文件r 二 Runtime. getRuntimeQ ;new Thread () Overridepublic void run() if (!swf () if (pdf () try (PDDocument doc = PDDocum

24、ent. /odd(pdfFile);System, out. printin (頁數(shù)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(第三步:轉(zhuǎn)換為SWF格式路徑: + swf ();System. o”2.printin(第四步:轉(zhuǎn)換為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文件不存在,無法轉(zhuǎn)換);) else System. out. printin (已經(jīng)轉(zhuǎn)為SWF文件,無需再次轉(zhuǎn)換);. 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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

提交評論