实现doc,ppt,txt等格式文件向可以在flexPaper中预览的翻页动画swf的格式转换,一般需要先把doc,ppt,txt等格式的文件先转换为pdf,然后再由pdf转换为swf才能实现在flexpaper中进行预览,实现类似百度豆丁的预览效果,其转换过程需要电脑安装 openoffice,swfTools软件,通过java代码:实现文档格式的转换,下面我将我在一个分布式项目中的一个文档预览部分的思路与大家共享:
1.安装openoffice,swfTools软件,配置好java代码的运行环境。
2.启动openOffice服务:
①、进入openoffice安装目录
cd opeonofiice的安装路径/program
②、启动端口监听
soffice -headless -accept="socket,host=127.0.0.1,port=8080;urp;" -nofirststartwizard
③、查看启动是否成功,存在8080端口即启动成功 netstat -an
3.在eclipse端运行以下java代码,实现文档的格式转换,并保存到
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;
//调用pdf2swf命令进行转换
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 = "世界各地国庆节";
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 = "世界各地国庆节";
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 {
//实现由pdf格式到swf格式的转换
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();
}
}
}
代码已经在MyEclipse上运行测试无误,可以实现将本地文件实现格式转换,
4.注意:注意代码中加载各个软件的本地路径要正确,防止加载不到软件而报错
在代码运行前要启动openoffice服务,否则不能完成文件格式的转换
分享到:
相关推荐
java实现浏览器在线预览offic(doc、xls、ppt)和pdf文件,本人将例子集成到项目中,已成功。 技术原理:将文件先转换成pdf文件,再将pdf文件转换成swf文件,最后显示在浏览器上。 资源描述:本资源包括swftools...
doc pdf转换成swf java语言
java将office文档pdf文档转换成swf文件在线预览
word转图片
经测试完全正确,myeclipse8.5,tomcat6.0.37,openoffice.org3.4.1,还要有jodconverter-2.2.2,swftools-0.9.1,这些都是用到的工具版本和包,尽量选对应版本的,代码测试无误,因为...所以请注意(.doc变成.docx)
全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换 ,word转pdf已做测试很好用!
文件类型包括53个Java源代码文件、17个JAR包文件、15个PNG图片文件、13个JSP页面文件、7个XML配置文件、6个CSS样式文件、6个JavaScript脚本文件、4个Properties配置文件、2个SWF文件、2个JPG图片文件。该系统通过...
Aspose.Words for Java supports processing word (DOC, DOCX, OOXML, RTF) HTML, OpenDocument, PDF, EPUB, XPS, SWF and all image formats. With Aspose.Words you can generate, modify, and convert documents ...
支持处理文字(DOC、DOCX、OOXML、RTF)HTML、OpenDocument、PDF、EPUB、XPS、SWF 和所有图像格式。 使用 Aspose.Words,您可以在不使用 Microsoft Word 的情况下生成、修改和转换文档。 目录 描述 一组 Java 示例,...
}好了,这样通过上面的方法就可以把图片转换成Byte[]对象,然后就把这个对象保存到数据库中去就实现了把图片的二进制格式保存到数据库中去了。下面我就谈谈如何把数据库中的图片读取出来,实际上这是一个相反的过程...
Java利用aspose将word文档转换成pdf格式等全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换 doc.save(os, SaveFormat.PDF); os.close(); } catch (Exception e) { System.out.println("Word 转 Pdf 失败..."); e....
对word文档,doc、docx等等,转为pdf。全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用openoffice转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。
* 实现文件格式转换 * @param sourceFilePath //源文件路径 * @param fullFileName //源文件名称 * @param converterFlag //源文件转换标志 * @throws Exception */ public String convertFile(String ...
word使用aspose转pdf、html...完美去水印,亲测可以转换各种格式,完美去水印,全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
参数值:动画上传前限制的文件扩展名列表,默认为:swf,建议与服务端扩展名检查列表一致 upMediaUrl:视频文件上传接收URL 参数值:接收用户上传的服务器端程序URL,默认留空为禁用上传功能,具体使用方法请参考...
DOC:FrameMaker或FrameBuilder文档;Word Star文档、Word Perfect文档、Microsoft:Word文档;DisplayWrite文档 DOT:Microsoft Word文档模板 DPL:Borland Delph 3压缩库 DRV:驱动程序 DRW:Micrografx ...