日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > java >内容正文

java

java x86 模拟,Java模拟实现百度文档在线浏览

發(fā)布時(shí)間:2025/7/14 java 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java x86 模拟,Java模拟实现百度文档在线浏览 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

這個(gè)思路是我參考網(wǎng)上而來(lái),代碼是我實(shí)現(xiàn)。 采用Apache下面的OpenOffice將資源文件轉(zhuǎn)化為pdf文件,然后將pdf文件轉(zhuǎn)化為swf文件,用FlexPaper瀏覽。

ok,

A、下載OpenOffice (轉(zhuǎn)換資源文件)

B、下載JodConverter(調(diào)用OpenOffice)

C、下載Swftools(Pdf2Swf)

D、下載 FlexPaper(瀏覽swf文件)

這里我已經(jīng)全部下載好了,大家只需要下載:

http://download.csdn.net/detail/u010506940/8418553

下載之后,先別急安裝,請(qǐng)看完這篇博文

1、先看我們的MyEclipse工程結(jié)構(gòu)

2、將我們下載下來(lái)的

解壓之后將所有的jar文件拷貝到baiduDoc的lib下面去

3、 ?在WebRoot下面新建文件夾

,將解壓后的

全部拷貝到FlexPaper中去

4、新建BaiDuServlet.java文件

package com.baidu.util;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStream;

import java.net.ConnectException;

import javax.imageio.stream.FileImageInputStream;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

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;

/**

* @Author:NuoYan

* @Date:2015-2-2 下午2:24:58

* TODO: 1、第一步,首先獲取到需要查看的文件

* 2、第二部,將獲取的文件(doc,xls,txt,ppt,03/07版本轉(zhuǎn)化為PDF),這一步需要調(diào)用OpenOffice

* 3、第三部,將資源文件轉(zhuǎn)換好的PDF文件轉(zhuǎn)換為swf文件,使用FlexPaperViewer.swf進(jìn)行瀏覽查看

*/

public class BaiDuServlet extends HttpServlet {

private File sourceFile;// 要轉(zhuǎn)化的源文件

private File pdfFile;// pdf中間文件對(duì)象

private File swfFile;// swf目標(biāo)文件對(duì)象

private String filePath;// 用來(lái)保存文件路徑

private String fileName;// 不包括后綴名的文件名

public File getSourceFile() {

return sourceFile;

}

public void setSourceFile(File sourceFile) {

this.sourceFile = sourceFile;

}

public File getPdfFile() {

return pdfFile;

}

public void setPdfFile(File pdfFile) {

this.pdfFile = pdfFile;

}

public File getSwfFile() {

return swfFile;

}

public void setSwfFile(File swfFile) {

this.swfFile = swfFile;

}

public String getFilePath() {

return filePath;

}

public void setFilePath(String filePath) {

this.filePath = filePath;

}

public String getFileName() {

return fileName;

}

public void setFileName(String fileName) {

this.fileName = fileName;

}

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String saveFileName = request.getParameter("savFile");

System.out.println(saveFileName);

String webPath = request.getRealPath("/");

filePath = webPath + "reader\\" + saveFileName;

fileName = filePath.substring(0, filePath.lastIndexOf("."));

// 創(chuàng)建三個(gè)文件對(duì)象

sourceFile = new File(filePath);

pdfFile = new File(fileName + ".pdf");

swfFile = new File(fileName + ".swf");

System.out.println(pdfFile);

System.out.println(swfFile);

// 1、將源文件轉(zhuǎn)化為pdf格式文件

src2pdf();

try {

// 2、將pdf文件轉(zhuǎn)化為swf文件

pdf2swf();

} catch (Exception e) {

e.printStackTrace();

}

// 將轉(zhuǎn)化好的文件綁定到session上去

request.getSession().setAttribute("swfName", swfFile.getName());

System.out.println(swfFile.getName());

// 重定向到預(yù)覽頁(yè)面

response.sendRedirect(request.getContextPath() + "/reader/baseFile.jsp");

}

/**

* @Author:NuoYan

* @Date:2015-2-2 下午2:28:22 TODO://源文件轉(zhuǎn)化為PDF文件

*/

private void src2pdf() {

if (sourceFile.exists()) {

// 如果不存在,需要轉(zhuǎn)份為PDF文件

if (!pdfFile.exists()) {

// 啟用OpenOffice提供的轉(zhuǎn)化服務(wù)

OpenOfficeConnection conn = new SocketOpenOfficeConnection(8100);

// 連接OpenOffice服務(wù)器

try {

conn.connect();

// 建立文件轉(zhuǎn)換器對(duì)象

DocumentConverter converter = new OpenOfficeDocumentConverter(

conn);

converter.convert(sourceFile, pdfFile);

// 斷開(kāi)鏈接

conn.disconnect();

System.out.println("轉(zhuǎn)換成功");

} catch (ConnectException e) {

e.printStackTrace();

}

} else {

System.out.println("已經(jīng)存在PDF文件,不需要在轉(zhuǎn)換!!");

}

} else {

System.out.println("文件路徑不存在!!!");

}

}

/**

* @Author:NuoYan

* @Date:2015-2-2 下午2:28:32

* @throws Exception

* TODO:PDF轉(zhuǎn)化為SWF文件

*/

private void pdf2swf() throws Exception {

if (!swfFile.exists()) {

if (pdfFile.exists()) {

String command = "C:\\Pdf2swf\\pdf2swf.exe "

+ pdfFile.getPath() + " -o " + swfFile.getPath()

+ " -T 9";

System.out.println("轉(zhuǎn)換命令:" + command);

// Java調(diào)用外部命令,執(zhí)行pdf轉(zhuǎn)化為swf

Runtime r = Runtime.getRuntime();

Process p = r.exec(command);

System.out.println(loadStream(p.getInputStream()));

System.out.println("swf文件轉(zhuǎn)份成功!!!");

System.out.println(swfFile.getPath());

} else {

System.out.println("不存在PDF文件");

}

}

}

private static String loadStream(InputStream in) throws Exception {

int len = 0;

in = new BufferedInputStream(in);

StringBuffer buffer = new StringBuffer();

while ((len = in.read()) != -1) {

buffer.append((char) len);

}

return buffer.toString();

}

}

5、修改index.jsp

百度文庫(kù)在線預(yù)覽

在線預(yù)覽

6、編寫(xiě)baseFile.jsp文件

pageEncoding="UTF-8"%>

在線閱讀

html,body{height: 100%;}

body {

margin: 0;padding: 0;overflow: auto;

}

#flashContent { display:none; }

var fp = new FlexPaperViewer(

'../FlexPaper/FlexPaperViewer',

'viewerPlaceHolder', { config : {

SwfFile : escape('../reader/'),

Scale : 0.6,

ZoomTransition : 'easeOut',

ZoomTime : 0.5,

ZoomInterval : 0.2,

FitPageOnLoad : true,

FitWidthOnLoad : false,

FullScreenAsMaxWindow : false,

ProgressiveLoading : false,

MinZoomSize : 0.2,

MaxZoomSize : 5,

SearchMatchAll : false,

InitViewMode : 'Portrait',

PrintPaperAsBitmap : false,

ViewModeToolsVisible : true,

ZoomToolsVisible : true,

NavToolsVisible : true,

CursorToolsVisible : true,

SearchToolsVisible : true,

localeChain: 'zh_CN'

}});

注意baseFile.jsp中的代碼,不會(huì)你可以參考這里

/**************************************************************************************/

7、注意事項(xiàng)

1、這個(gè)

文件安裝路徑不要太深,免得Java調(diào)用外部命令,不能執(zhí)行,我這里是C盤(pán)下的Pdf2swf文件夾

2、

2.1、紅色1標(biāo)記路徑不能錯(cuò),我就犯這個(gè)錯(cuò)誤了

2.2、紅色標(biāo)記2還可以寫(xiě)http://127.0.0.1:8080/baiduDoc/reader/...

3、啟動(dòng)OpenOffice的命令,不是直接雙擊啟動(dòng)的。?官網(wǎng)啟動(dòng)方式如下:

安裝完openoffice后,進(jìn)入命令界面->cd 進(jìn)入安裝目錄,如下:

1.安裝服務(wù)

cd C:\Program Files (x86)\OpenOffice4\program

這一步你可以看你的OpenOffice安裝哪里

執(zhí)行

soffice -headless-accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

2.查看是否安裝成功

2.1查看端口對(duì)應(yīng)的pid

netstat -ano|findstr "8100"

2.2查看pid對(duì)應(yīng)的服務(wù)程序名

tasklist|findstr "ipd值"

效果圖示:

有問(wèn)題,請(qǐng)留言來(lái)找我吧!ok?不要閑我的資源貴哦!哈哈~

總結(jié)

以上是生活随笔為你收集整理的java x86 模拟,Java模拟实现百度文档在线浏览的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。