在网页中在线查看文档(doc、docx 、xls 、xlsx、 pdf 、swf )
步骤一:(涉及到的工具)
在线查看使用FlexPaper软件(http://flexpaper.devaldi.com/download/)
doc、docs、xls、xlsx转换dpf工具openoffice(http://www.openoffice.org/download/index.html)
pdf转成swf工具swftools-0.9.2(http://www.pc6.com/softview/SoftView_51612.html)
步骤二:(配置工程)
1、在项目中导入下载FlexPaper解压后文件(js、css、swf文件等)
2、编写一个html页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css" media="screen"> html, body { height:100%; }body { margin:0; padding:0; overflow:auto; } #flashContent { display:none; }</style> <script type="text/javascript" src="../js/swfobject/swfobject.js"></script><script type="text/javascript" src="../js/flexpaper_flash.js"></script><script type="text/javascript"> <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. --> var swfVersionStr = "10.0.0";<!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->/* var xiSwfUrlStr = "playerProductInstall.swf"; */var xiSwfUrlStr = ""; //值可以任意var flashvars = { SwfFile : escape("lucene4.6.swf"), //swf文件路径(lucene4.6和页面同一个位置) Scale : 0.6, ZoomTransition : "easeOut",ZoomTime : 0.5,ZoomInterval : 0.1,FitPageOnLoad : false,FitWidthOnLoad : true,PrintEnabled : true,FullScreenAsMaxWindow : false,ProgressiveLoading : true,PrintToolsVisible : true,ViewModeToolsVisible : true,ZoomToolsVisible : true,FullScreenVisible : true,NavToolsVisible : true,CursorToolsVisible : true,SearchToolsVisible : true,localeChain: "en_US"};var params = {}params.quality = "high";params.bgcolor = "#ffffff";params.allowscriptaccess = "sameDomain";params.allowfullscreen = "true";var attributes = {};attributes.id = "FlexPaperViewer";attributes.name = "FlexPaperViewer";swfobject.embedSWF("FlexPaperViewer.swf", "flashContent", "800", "600",swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);swfobject.createCSS("#flashContent", "display:block;text-align:center;");</script> </head> <body> <div style="position:absolute;left:200px;top:10px;"><div id="flashContent"> </div> </div></body>
</html>
打开html页面就可以运行,效果如下:
步骤三:pdf转换成swf格式(借鉴别人)
1、下载 jodconverter-2.2.2 ,将lib目录所有jar 复制到项目 lib目录
2、写一个java工具类(doc、dcox、xls、xlsx->pdf->swf)
package com.netsix.util; import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.util.ResourceBundle;
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; /** * 将文件转成swf格式 * * @author Administrator * */
public class ConvertSwf { /** * 入口方法-通过此方法转换文件至swf格式 * @param filePath 上传文件所在文件夹的绝对路径 * @param fileName 文件名称 * @return 生成swf文件名 */ public String beginConvert(String filePath, String fileName) { final String DOC = ".doc"; final String DOCX = ".docx"; final String XLS = ".xls"; final String XLSX = ".xlsx"; final String PDF = ".pdf"; final String SWF = ".swf"; final String TOOL = "pdf2swf.exe"; String outFile = ""; String fileNameOnly = ""; String fileExt = ""; if (null != fileName && fileName.lastIndexOf(".") > 0) { int index = fileName.lastIndexOf("."); fileNameOnly = fileName.substring(0, index); fileExt = fileName.substring(index).toLowerCase(); } String inputFile = filePath + File.separator + fileName; String outputFile = ""; //如果是office文档,先转为pdf文件 if (fileExt.equals(DOC) || fileExt.equals(DOCX) || fileExt.equals(XLS) || fileExt.equals(XLSX)) { outputFile = filePath + File.separator + fileNameOnly + PDF; office2PDF(inputFile, outputFile); inputFile = outputFile; fileExt = PDF; } if (fileExt.equals(PDF)) { String toolFile = filePath + File.separator + TOOL; outputFile = filePath + File.separator + fileNameOnly + SWF; convertPdf2Swf(inputFile, outputFile, toolFile); outFile = outputFile; } return outFile; } /** * 将pdf文件转换成swf文件 * @param sourceFile pdf文件绝对路径 * @param outFile swf文件绝对路径 * @param toolFile 转换工具绝对路径 */ private void convertPdf2Swf(String sourceFile, String outFile, String toolFile) { String command = toolFile + " \"" + sourceFile + "\" -o \"" + outFile + "\" -s flashversion=9 "; try { Process process = Runtime.getRuntime().exec(command); System.out.println(loadStream(process.getInputStream())); System.err.println(loadStream(process.getErrorStream())); System.out.println(loadStream(process.getInputStream())); System.out.println("###--Msg: swf 转换成功"); } catch (Exception e) { e.printStackTrace(); } } /** * office文档转pdf文件 * @param sourceFile office文档绝对路径 * @param destFile pdf文件绝对路径 * @return */ private int office2PDF(String sourceFile, String destFile) { ResourceBundle rb = ResourceBundle.getBundle("OpenOfficeService"); String OpenOffice_HOME = "D:\\Program Files\\OpenOffice 4"; //openoffice安装路径 String host_Str = "127.0.0.1"; //地址String port_Str = "8100"; //端口号try { File inputFile = new File(sourceFile); if (!inputFile.exists()) { return -1; // 找不到源文件 } // 如果目标路径不存在, 则新建该路径 File outputFile = new File(destFile); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } // 如果从文件中读取的URL地址最后一个字符不是 '\',则添加'\' if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '\\') { OpenOffice_HOME += "\\"; } // 启动OpenOffice的服务 String command = OpenOffice_HOME + "program\\soffice.exe -headless -accept=\"socket,host=" + host_Str + ",port=" + port_Str + ";urp;\""; System.out.println("###\n" + command); Process pro = Runtime.getRuntime().exec(command); // 连接openoffice服务 OpenOfficeConnection connection = new SocketOpenOfficeConnection( host_Str, Integer.parseInt(port_Str)); connection.connect(); // 转换 DocumentConverter converter = new OpenOfficeDocumentConverter( connection); converter.convert(inputFile, outputFile); // 关闭连接和服务 connection.disconnect(); pro.destroy(); return 0; } catch (FileNotFoundException e) { System.out.println("文件未找到!"); e.printStackTrace(); return -1; } catch (ConnectException e) { System.out.println("OpenOffice服务监听异常!"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return 1; } static String loadStream(InputStream in) throws IOException{ int ptr = 0; in = new BufferedInputStream(in); StringBuffer buffer = new StringBuffer(); while ((ptr=in.read())!= -1){ buffer.append((char)ptr); } return buffer.toString(); } }
测试类
package com.netsix.test;import com.netsix.util.ConvertSwf;public class MainClass {public static void main(String[] args) {String dirPath = "D:\\workspace\\20140403_WebScaner\\pdf"; // 下载swftools-0.9.2.exe 安装后,复制安装目录中 pdf2swf.exe 到项目附件目录中。String fileName = "lucene4.6.doc";String outPath = new ConvertSwf().beginConvert(dirPath,fileName); System.out.println("生成swf文件:" + outPath); }
}
demo例子:http://download.csdn.net/detail/lin062854/7145653
在网页中在线查看文档(doc、docx 、xls 、xlsx、 pdf 、swf )相关推荐
- html 文档在线查看,在网页中在线查看文档(doc、docx 、xls 、xlsx、 pdf 、swf )
步骤一:(涉及到的工具) 步骤二:(配置工程) 1.在项目中导入下载FlexPaper解压后文件(js.css.swf文件等) 2.编写一个html页面 html, body{ height:100% ...
- (内含两种方式)Android 在线查看文档world丶xls丶ppt等文件
之前做法是偷偷下载文档调用第三方wps打开,完事后偷偷删除,说实话这样有点难受. 后来发现浏览器使用worldonline可以查看文档,放到Android自带webview上直接是一个小红叉, 点击链 ...
- vue - - - - - 在线预览常见文件格式 .doc, .docx, .xls, .xlsx,.pdf
在线预览常见文件 1.HTML5 - ```embed```标签 1.1 注意⚠️ 1.2 使用方式 2. HTML - ```iframe```标签 2.1 注意⚠️ 2.2 使用方式 3. HTM ...
- Word处理控件Aspose.Words功能演示:使用 C++ 创建 MS Word 文档 (DOC/DOCX)
Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此 ...
- doc/docx/xls/xlsx 转PDF
使用语言 python 使用版本 python3 部分文档不能编辑不能解析文档损坏无法处理,运行前需在本地安装Office 参考链接:https://www.cnblogs.com/lzhc/p/10 ...
- doc, docx, xls, xlsx, ppt, pptx,txt。等文件转化为pdf
需要OpenOffice第三插件的支持 ,支持window\linux\mac等系统.doc", "docx", "xls", "xlsx& ...
- nodejs显示word到html文件,如何使用JavaScript在浏览器中呈现Word文档(.doc,.docx)?
目前没有浏览器具有呈现Word文档所需的代码,据我所知,目前也没有用于呈现这些文档的客户端库. 但是,如果您只需要显示Word文档,而不需要编辑它,则可以通过若要显示远程承载的.doc/.docx. ...
- 在web网页中打开word文档
1:首先添加下引用,右击网站→添加引用→弹出的框COM下添加 using Microsoft.Office.Interop.Word; using System; using System.Colle ...
- SharePoint中在线编辑文档
我一直以为只有在Document Library里面的File才会支持在线编辑.直到今天早上我才发现用IE打开List里面的Attachments也是支持在线编辑的,但前提是必须是IE浏览器.我和我的 ...
最新文章
- 禁用页面缓存的几种方法(静态和动态)
- Servlet,过滤器,监听器,拦截器的区别
- Spark读取MySQL中的数据为DataFrame
- springboot访问静态页面404_解决 springboot 2.x 访问静态资源 404的问题
- apache camel_什么时候使用Apache Camel?
- 前端学习(1660):前端系列实战课程之时间对象介绍
- Oracle conn 协议适配器错误解决
- 信号调制产生边频的原理及希尔伯特解调
- C语言排序方法------堆排序
- JAVA MyFirst.java
- java static调用吗_java中使用static
- iOS开发UIScrollView使用详解
- php7 ob get contents,关于ob_get_contents(),ob_end_clean(),ob_start(),的具体用法详解
- putty怎么进入文件夹_如何安装及使用PuTTY
- 电力拖动自动控制系统复习(四)
- 如何正确撰写sci论文中的作者信息
- c语言生成exe文件,打开exe文件闪退怎么办
- ubuntu qq音乐/网易云音乐 播放没有声音,播放mv有声音,解决办法
- 【Linux】用进程控制知识做一个简易版shell
- 如何去除word中的空行