赞
踩
如何页面预览word
1.实现原理
word =》 pdf =》 swf
2步骤
这里面要用到两个jar
一个是 aspose-words-jdk 主要用于 word 转 pdf
关键代码
public static int word2pdf(String sourceFile, String destFile ) {
try {
File file = new File(destFile); // 新建一个空白pdf文档
FileOutputStream os = new FileOutputStream(file);
com.aspose.words.Document doc = new com.aspose.words.Document(sourceFile); // Address是将要被转化的word文档
doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}
一个是 SWFTools
关键代码
/** * 将PDF文档转换为swf格式的FLASH文件. 运行该函数需要用到SWFTools, 下载地址为 * http://www.swftools.org/download.html * @param sourceFile 源文件(即PDF文档)路径, 包括源文件的文件名. 示例: D:\\PDF\\source.pdf * @param destFile 目标文件路径, 即需要保存的文件路径(包括文件名). 示例: D:\\SWF\\dest.swf * @return 操作成功与否的提示信息. 如果返回 -1, 表示找不到源PDF文件, 或配置文件url.properties配置错误; 如果返回 0, * 则表示操作成功; 返回1或其他, 则表示转换失败 * @throws IOException */ public static int pdf2SWF(String sourceFile, String destFile) throws IOException { // 目标路径不存在则建立目标路径 File dest = new File(destFile); if (!dest.getParentFile().exists()) dest.getParentFile().mkdirs(); // 源文件不存在则返回 -1 File source = new File(sourceFile); if (!source.exists()) return -1; //localhost /* String SWFTools_HOME = "D:\\Program Files (x86)\\SWFTools";// SWFTools的安装路径。在我的项目中,我为了便于拓展接口,没有直接将SWFTools的安装路径写在这里,详见附件 // 如果从文件中读取的URL地址最后一个字符不是 '\',则添加'\' // 调用pdf2swf命令进行转换swfextract -i - sourceFilePath.pdf -o destFilePath.swf String command = SWFTools_HOME + "\\pdf2swf.exe -i " + sourceFile + " -o " + destFile; */ String commandStr = "pdf2swf " + sourceFile + " " + destFile; String[] command = { "/bin/sh", "-c", commandStr}; Process process = Runtime.getRuntime().exec(command); final InputStream is1 = process.getInputStream(); new Thread(new Runnable() { public void run() { BufferedReader br = new BufferedReader(new InputStreamReader(is1)); try { while (br.readLine() != null) ; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); InputStream is2 = process.getErrorStream(); BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); StringBuilder buf = new StringBuilder(); // 保存输出结果流 String line = null; while ((line = br2.readLine()) != null) buf.append(line); // 循环等待ffmpeg进程结束 System.out.println("输出结果为:" + buf); return 1; }
最后js 代码
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="1000px" height="830px">
<param name=movie value="*.swf">
<embed src="你的swf文件.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="830px" height="830px">
</embed>
</object>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。