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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java实现doc向swf格式的转换 转_java实现doc向swf格式的转换 转

發(fā)布時間:2024/10/6 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java实现doc向swf格式的转换 转_java实现doc向swf格式的转换 转 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

實現(xiàn)doc,ppt,txt等格式文件向可以在flexPaper中預覽的翻頁動畫swf的格式轉(zhuǎn)換,一般需要先把doc,ppt,txt等格式的文件先轉(zhuǎn)換為pdf,然后再由pdf轉(zhuǎn)換為swf才能實現(xiàn)在flexpaper中進行預覽,實現(xiàn)類似百度豆丁的預覽效果,其轉(zhuǎn)換過程需要電腦安裝 openoffice,swfTools軟件,通過java代碼:實現(xiàn)文檔格式的轉(zhuǎn)換,下面我將我在一個分布式項目中的一個文檔預覽部分的思路與大家共享:

1.安裝openoffice,swfTools軟件,配置好java代碼的運行環(huán)境。

2.啟動openOffice服務:

①、進入openoffice安裝目錄

cd opeonofiice的安裝路徑/program

②、啟動端口監(jiān)聽

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

③、查看啟動是否成功,存在8080端口即啟動成功?? netstat -an

3.在eclipse端運行以下java代碼,實現(xiàn)文檔的格式轉(zhuǎn)換,并保存到

JodDemo.java:

public class JodDemo {

public static int convertPDF2SWF(String sourcePath, String destPath, String fileName) throws IOException {

//目標路徑不存在則建立目標路徑

File dest = new File(destPath);

if (!dest.exists()) dest.mkdirs();

//源文件不存在則返回

File source = new File(sourcePath);

if (!source.exists()) return 0;

//調(diào)用pdf2swf命令進行轉(zhuǎn)換

String command = "D:\\SWFTools\\pdf2swf.exe" + " -o \"" + destPath + "\\" + fileName + "\"? -s languagedir=D:\\xpdf\\xpdf-chinese-simplified -s flashversion=9 \"" + sourcePath + "\"";

Process pro = Runtime.getRuntime().exec(command);

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(pro.getInputStream()));

while (bufferedReader.readLine() != null);

try {

pro.waitFor();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return pro.exitValue();

}

public static void main(String []args) throws IOException {

String a = "世界各地國慶節(jié)";

String sourcePath = "d:\\"+a+".pdf";

String destPath = "d:\\swf\\";

String fileName = a+".swf";

JodDemo.convertPDF2SWF(sourcePath, destPath, fileName);

}

}

Office2Pdf.java

public class Office2Pdf {

public static void main(String[] args) throws Exception {

String a = "世界各地國慶節(jié)";

off2Pdf(a);

}

public static void off2Pdf(String fileName) {

File inputFile = new File("d:/" + fileName + ".ppt");

File outputFile = new File("d:/" + fileName + ".pdf");

// connect to an OpenOffice.org instance running on port 8100

OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);

try {

connection.connect();

} catch (ConnectException e) {

e.printStackTrace();

}

// convert

DocumentConverter converter = new OpenOfficeDocumentConverter(

connection);

converter.convert(inputFile, outputFile);

connection.disconnect();

}

}

Pdf2Swf.java

public class Pdf2Swf {

//實現(xiàn)由pdf格式到swf格式的轉(zhuǎn)換

public int convertPDF2SWF(String sourcePath, String destPath,

String fileName) throws IOException {

// 目標路徑不存在則建立目標路徑

File dest = new File(destPath);

if (!dest.exists()) {

dest.mkdirs();

}

// 源文件不存在則返回

File source = new File(sourcePath);

if (!source.exists()) {

return 0;

}

String[] envp = new String[1];

envp[0] = "PATH=D:\\SWFTools\\";

String command = "pdf2swf -z -s flashversion=9 \"" + sourcePath

+ "\" -o \"" + destPath + fileName + "\"";

Process pro = Runtime.getRuntime().exec(command, envp);

// System.out.println(command);

BufferedReader bufferedReader = new BufferedReader(

new InputStreamReader(pro.getInputStream()));

while (bufferedReader.readLine() != null) {

String text = bufferedReader.readLine();

System.out.println(text);

}

try {

pro.waitFor();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// 然后在套播放器

command = "swfcombine -z -X 720 -Y 540 \"D:/SWFTools/swfs/rfxview.swf\" viewport=\""

+ destPath + fileName + "\" -o \"" + destPath + fileName + "\"";

pro = Runtime.getRuntime().exec(command, envp);

System.out.println(command);

bufferedReader = new BufferedReader(new InputStreamReader(pro

.getInputStream()));

while (bufferedReader.readLine() != null) {

String text = bufferedReader.readLine();

System.out.println(text);

}

try {

pro.waitFor();

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return pro.exitValue();

}

public static void main(String[] args) {

String sourcePath = "d:/document.pdf";

String destPath = "d:/";

String fileName = "document.swf";

try {

System.out.println(new Pdf2Swf().convertPDF2SWF(sourcePath,

destPath, fileName));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

代碼已經(jīng)在MyEclipse上運行測試無誤,可以實現(xiàn)將本地文件實現(xiàn)格式轉(zhuǎn)換,

4.注意:注意代碼中加載各個軟件的本地路徑要正確,防止加載不到軟件而報錯

在代碼運行前要啟動openoffice服務,否則不能完成文件格式的轉(zhuǎn)換

總結(jié)

以上是生活随笔為你收集整理的java实现doc向swf格式的转换 转_java实现doc向swf格式的转换 转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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