如何使用flexpaperviewer+swftools大文件分页转换实现在线预览

JAVA+FLEXPAPER+SWFTOOLS仿百度文库文档在线预览系统设计与实现_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
JAVA+FLEXPAPER+SWFTOOLS仿百度文库文档在线预览系统设计与实现
上传于||文档简介
&&J​A​V​A​+​F​L​E​X​P​A​P​E​R​+​S​W​F​T​O​O​L​S​仿​百​度​文​库​文​档​在​线​预​览​系​统​设​计​与​实​现
大小:682.00B
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢之前总结了在线预览几种常见解决方案,可以戳这里:
客户突然给了比较大的文档,赫然崩溃,项目中采用的是flexpaper+swftools方式实现的,发现在pdf-》swf的时候,转了100页之后,就会出现问题,很无奈,可能客户上传的word文档有问题,客户给的文档,页面方向有横向的,也有纵向的。没办法只能想办法解决了。
最后想到了将他们一页一页的转,说实话我都疯了,几百页的文档,抽支烟回来才转完,你不疯不行啊。
之后想了用其他几种解决方案,由于客户要求文档不能被下载,被复制,要有保密性,这需求,你想保密,想安全,就别放在网上啊,别人只要想要,一张一张的截图,也能给你的文档扣下来,想当年,考研那会儿,我都干过这事,考题都是从网上一张一张截图搞下来的。现在想想,当时真sb。
单页pdf转swf
&这里还是使用这篇文章中的demo:
然后修改PSD2SwfHelper类下的方法PDF2SWF和GetPageCount,将私有改为公有:
/// &summary&
/// PDF格式转为SWF
/// &/summary&
/// &param name="pdfPath"&PDF文件地址&/param&
/// &param name="swfPath"&生成后的SWF文件地址&/param&
/// &param name="beginpage"&转换开始页&/param&
/// &param name="endpage"&转换结束页&/param&
public static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
//swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
swfPath = HttpContext.Current.Server.MapPath(swfPath);
if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
return false;
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -s flashversion=9");
if (endpage & GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
sb.Append(" -j " + photoQuality);
string Command = sb.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName =
p.StartInfo.Arguments = C
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
public partial class Test : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string pdfPath="PDFFile/王牌2_C#_控件查询手册.pdf";
int pageCount = PSD2swfHelper.GetPageCount(Server.MapPath(pdfPath));
for (int i = 1; i &=pageC i++)
//i to i 当前页
PSD2swfHelper.PDF2SWF(pdfPath, "SWFFile/" + i.ToString() + ".swf", i, i, 80);
//这里需要虚拟路径
// PSD2swfHelper.PDF2SWF("PDFFile/王牌2_C#_控件查询手册.pdf", "SWFFile/王牌2_C#_控件查询手册.swf");
修改预览页面,flexpaper配置信息:
参考文章:
var flashvars = {
SwfFile: "{/SWFFile/[*,0].swf,52}",//这里需要修改
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"
测试结果:
这里只是将工作中遇到的问题,记录一下,这种方式,转换速度太慢了,也许你有更好的解决方案,不妨分享一下你的解决方案,不胜感激。
阅读(...) 评论()An error occurred.
Sorry, the page you are looking for is currently unavailable.
Please try again later.
If you are the system administrator of this resource then you should check
for details.
Faithfully yours, nginx.仿百度文库的基本功能,写的比较粗糙,只记录基本过程和步骤
基本步骤:
& & 1、将要展示的office文件 转换成 PDF, &使用工具 openoffice &
& & 2、将PDF文件转换成swf ,实用工具swftools
& & 3、使用flexPaper,显示转换后的swf文件。
基础代码:没有任何校验
& & 1、openoffice转换pdf
& & &下载地址:https://www.openoffice.org/zh-cn/
&&&&& 实用工具: &jodconverter-2.2.2&& 引入所需jar,直接将所有jar都扔进来了
&&&&&首先、下载openOffice软件,并安装,使用dos命令开启服务
&&&&&命令如下:
我安装在了 C:\Program Files (x86)
C:\Program Files (x86)\OpenOffice 4\program&soffice -headless -accept="socket,host=127.0.0.1,port=8100;" -nofirststartwizard
& & 启动后,执行以下命令& & doc文件为原始文件,转换成pdf
File inputFile = new File("D:\\大数据及应用.doc");
File outputFile = new File("D:\\大数据及应用.pdf");
OpenOfficeConnection connection = new SocketOpenOfficeConnection(
"127.0.0.1", 8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
& & 2、swftools将PDF转换swf
& & 下载地址:http://www.swftools.org/download.html
& & 首先安装swftools工具,我是windows 下载exe文件,直接安装,
& & 注:文件夹不要有空格,有空格不识别 &如 &program file &文件夹下 不好使
& & 我安装在了D盘根目录下,该方法来源于网络,资料找的太多不记得从哪位大侠哪拷来得了,
& & 还要注意下面代码被我改成windows的命令了,linux不生效。
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 " + sourcePath + " -o " + destPath
+ fileName + " -f -T
System.out.println(command);
Process pro = Runtime.getRuntime().exec(command);
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(pro.getInputStream()));
while (bufferedReader.readLine() != null);
pro.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return pro.exitValue();
& & 4、flexPaper显示swf
& & 下载地址:/GPL/FlexPaper_2.2.4.zip
& & jsp代码如下
& & 该文件:FlexPaperViewer.swf
&!--首先要引入jquery库及相关的js
下载包里面 找--&
&script type="text/javascript" src="js/jquery.js"&&/script&
&script type="text/javascript" src="js/flexpaper_flash.js"&&/script&
&script type="text/javascript" src="js/flexpaper_flash_debug.js"&&/script&
body内如下
&div style="position:left:10top:10"&
&a id="viewerPlaceHolder" style="width:1260height:780display:block"&&/a&
&script type="text/javascript"&
var fp = new FlexPaperViewer(
'FlexPaperViewer',
'viewerPlaceHolder',
&!--对应于a 标签的id--&
{ config : {
decodeURI('aaa.swf'),
&!--引入的swf文件,decodeURI 解决中文文件名问题--&
Scale : 0.6,
ZoomTransition : 'easeOut',
ZoomTime : 0.5,
ZoomInterval : 0.2,
FitPageOnLoad : true,
FitWidthOnLoad : false,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : false,
MinZoomSize : 0.2,
MaxZoomSize : 5,
SearchMatchAll : false,
InitViewMode : 'Portrait',
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'zh_CN'
&!--改成这个显示中文--&
谢谢,[83],
& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区先附上本人参考的文章,基于的 flexpaper版本 为 1.5,本人由于使用的是 2.1.9 ,故之后说明:
已经支持加载中文文件名
1.通过第三方工具openoffice,将word、excel、ppt、txt等文件转换为pdf文件
2.通过swfTools将pdf文件转换成swf格式的文件
3.通过FlexPaper文档组件在页面上进行展示
2.安装包下载
1.openoffice是Apache下的一个开放免费的文字处理软件
& &下载地址:
2.SWFTools是一组用来处理Flash的swf文件的工具包,我们使用它将pdf文件转成swf文件!
& &下载地址:
3.FlexPaper是一个开源轻量级的在浏览器上显示各种文档的组件
& &下载地址:
4.JODConverter一个Java的OpenDocument 文件转换器,在此我们只用到它的jar包
& &下载地址:
3.安装文件
1.将所下载的文件(JODConverter除外)进行安装,盘符可随自己设定!需要注意的是在openoffice安装完成后,当我们使用它时,需将它的服务打开。在次我们需要以命令的方式打开:
打开dos窗口,进入openoffice安装盘符,输入以下代码来启动服务:
soffice -headless -accept="socket,host=127.0.0.1,port=8100;" -nofirststartwizard
注意最后一个命令前边的‘—’,可不要写错!服务起不来,项目可是继续不下去的哦.
官网启动服务截图如下:
本地截图:
3.开发过程
1.新建项目,将flexpaper文件中的js文件夹(包含了flexpaper_flash_debug.js,flexpaper_flash.js,jquery.js,这三个js文件主要是预览swf文件的插件)拷贝至网站根目录;将FlexPaperViewer.swf拷贝至网站根目录下(该文件主要是用在网页中播放swf文件的播放器),目录结构如下图:
注:需创建upload文件夹
2.创建fileUpload.jsp
&%@&page&language="java"&contentType="text/&charset=UTF-8"&&
&&&&pageEncoding="UTF-8"%&&&
&!DOCTYPE&html&PUBLIC&"-//W3C//DTD&HTML&4.01&Transitional//EN"&"http://www.w3.org/TR/html4/loose.dtd"&&&
&meta&http-equiv="Content-Type"&content="text/&charset=UTF-8"&&&
&title&文档在线预览系统&/title&&&
&&&&body&{margin-top:100background:#font-family:&Verdana,&T}&&
&&&&a&{color:#CE4614;}&&
&&&&#msg-box&{color:&#CE4614;&font-size:0.9text-align:}&&
&&&&#msg-box&.logo&{border-bottom:5px&solid&#ECE5D9;margin-bottom:20padding-bottom:10}&&
&&&&#msg-box&.title&{font-size:1.4font-weight:margin:0&0&30px&0;}&&
&&&&#msg-box&.nav&{margin-top:20}&&
&/style&&&
&div&id="msg-box"&&&
&&&&&form&name="form1"&&method="post"&enctype="multipart/form-data"&action="docUploadConvertAction.jsp"&&&
&&&&&&&&&div&class="title"&&&
&&&&&&&&&&&&请上传要处理的文件,过程可能需要几分钟,请稍候片刻。&&
&&&&&&&&&/div&&&
&&&&&&&&&p&&&
&&&&&&&&&&&&&input&name="file1"&type="file"&&&
&&&&&&&&&/p&&&
&&&&&&&&&p&&&
&&&&&&&&&&&&&input&type="submit"&name="Submit"&value="上传"&&&
&&&&&&&&&/p&&&
&&&&&/form&&&&
3.创建转换页docUploadConvertAction.jsp
&%@&page&language="java"&contentType="text/&charset=UTF-8"&pageEncoding="UTF-8"%&&&
&%@page&import="java.io.*"%&&&
&%@page&import="java.util.Enumeration"%&&&
&%@page&import="com.oreilly.servlet.MultipartRequest"%&&&
&%@page&import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%&&&
&%@page&import="com.cectsims.util.DocConverter"%&&&
//文件上传采用cos组件上传,可更换为commons-fileupload上传,文件上传后,保存在upload文件夹&&
//获取文件上传路径&&
String&saveDirectory&=application.getRealPath("/")+"upload";&&
//打印上传路径信息&&
System.out.println(saveDirectory);&&
//每个文件最大50m&&
int&maxPostSize&=&50&*&1024&*&1024&;&&
//采用cos缺省的命名策略,重名后加1,2,3...如果不加dfp重名将覆盖&&
DefaultFileRenamePolicy&dfp&=&new&DefaultFileRenamePolicy();&&
//response的编码为"UTF-8",同时采用缺省的文件名冲突解决策略,实现上传,如果不加dfp重名将覆盖&&
MultipartRequest&multi&=&new&MultipartRequest(request,&saveDirectory,&maxPostSize,"UTF-8",dfp);&&
//MultipartRequest&multi&=&new&MultipartRequest(request,&saveDirectory,&maxPostSize,"UTF-8");&&
//输出反馈信息&&
&Enumeration&files&=&multi.getFileNames();&&
&&&&&while&(files.hasMoreElements())&{&&
&&&&&&&&System.err.println("ccc");&&
&&&&&&&String&name&=&(String)files.nextElement();&&
&&&&&&&File&f&=&multi.getFile(name);&&
&&&&&&&if(f!=null){&&
&&&&&&&&&String&fileName&=&multi.getFilesystemName(name);&&
&&&&&&&&&//获取上传文件的扩展名&&
&&&&&&&&&String&extName=fileName.substring(fileName.lastIndexOf(".")+1);&&
&&&&&&&&&//文件全路径&&
&&&&&&&&&String&lastFileName=&saveDirectory+"\\"&+&fileN&&
&&&&&&&&&//获取需要转换的文件名,将路径名中的'\'替换为'/'&&
&&&&&&&&&String&converfilename&=&saveDirectory.replaceAll("\\\\",&"/")+"/"+fileN&&
&&&&&&&&&System.out.println(converfilename);&&
&&&&&&&&&//调用转换类DocConverter,并将需要转换的文件传递给该类的构造方法&&
&&&&&&&&&DocConverter&d&=&new&DocConverter(converfilename);&&
&&&&&&&&&//调用conver方法开始转换,先执行doc2pdf()将office文件转换为再执行pdf2swf()将pdf转换为&&
&&&&&&&&&d.conver();&&
&&&&&&&&&//调用getswfPath()方法,打印转换后的swf文件路径&&
&&&&&&&&&System.out.println(d.getswfPath());&&
&&&&&&&&&//生成swf相对路径,以便传递给flexpaper播放器&&
&&&&&&&&&String&swfpath&=&"upload"+d.getswfPath().substring(d.getswfPath().lastIndexOf("/"));&&
&&&&&&&&&System.out.println(swfpath);&&
&&&&&&&&&//将相对路径放入sessio中保存&&
&&&&&&&&&session.setAttribute("swfpath",&swfpath);&&
&&&&&&&&&out.println("上传的文件:"+lastFileName);&&
&&&&&&&&&out.println("文件类型"+extName);&&
&&&&&&&&&out.println("&hr&");&&
&&&&&&&}&&
&!DOCTYPE&html&PUBLIC&"-//W3C//DTD&HTML&4.01&Transitional//EN"&"http://www.w3.org/TR/html4/loose.dtd"&&&
&meta&http-equiv="Content-Type"&content="text/&charset=UTF-8"&&&
&title&Insert&title&here&/title&&&
&&&&body&{margin-top:100background:#font-family:&Verdana,&T}&&
&&&&a&{color:#CE4614;}&&
&&&&#msg-box&{color:&#CE4614;&font-size:0.9text-align:}&&
&&&&#msg-box&.logo&{border-bottom:5px&solid&#ECE5D9;margin-bottom:20padding-bottom:10}&&
&&&&#msg-box&.title&{font-size:1.4font-weight:margin:0&0&30px&0;}&&
&&&&#msg-box&.nav&{margin-top:20}&&
&/style&&&
&&&&&div&&&
&&&&&&&&&form&name="viewForm"&id="form_swf"&action="documentView.jsp"&method="POST"&&&
&&&&&&&&&&&&&input&type='submit'&value='预览'&class='BUTTON&SUBMIT'/&&&
&&&&&&&&&/form&&&
&&&&&/div&&&
4.创建查看页documentView.jsp
&%@&page&language="java"&contentType="text/&charset=UTF-8"&pageEncoding="UTF-8"%&&&
&&&&String&swfFilePath=session.getAttribute("swfpath").toString();&&
&!DOCTYPE&html&PUBLIC&"-//W3C//DTD&HTML&4.01&Transitional//EN"&"http://www.w3.org/TR/html4/loose.dtd"&&&
&meta&http-equiv="Content-Type"&content="text/&charset=UTF-8"&&&
&script&type="text/javascript"&src="js/jquery.js"&&/script&&&
&script&type="text/javascript"&src="js/flexpaper_flash.js"&&/script&&&
&script&type="text/javascript"&src="js/flexpaper_flash_debug.js"&&/script&&&
&style&type="text/css"&media="screen"&&&&
&&&&&&&&&&&&html,&body&&{&height:100%;&}&&
&&&&&&&&&&&&body&{&margin:0;&padding:0;&overflow:&}&&&&&
&&&&&&&&&&&&#flashContent&{&display:&}&&
&&&&&&&&&/style&&&&
&title&文档在线预览系统&/title&&&
&&&&&&&&&div&style="position:left:50top:10"&&&
&&&&&&&&&&&&&a&id="viewerPlaceHolder"&style="width:820height:650display:block"&&/a&&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&&script&type="text/javascript"&&&&
&&&&&&&&&&&&&&&&var&fp&=&new&FlexPaperViewer(&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&'FlexPaperViewer',&&
&&&&&&&&&&&&&&&&&&&&&&&&&'viewerPlaceHolder',&{&config&:&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&SwfFile&:&escape('&%=swfFilePath%&'),&&
&&&&&&&&&&&&&&&&&&&&&&&&&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&:&'SinglePage',&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&ViewModeToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&&ZoomToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&&NavToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&&CursorToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&&SearchToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&localeChain:&'en_US'&&
&&&&&&&&&&&&&&&&&&&&&&&&&}});&&
&&&&&&&&&&&&&/script&&&&&&&&&&&&&&&
&&&&&&&&&/div&&&
5.创建转换类DocConverter.java
package&com.cectsims.&&
import&java.io.BufferedInputS&&
import&java.io.F&&
import&java.io.IOE&&
import&java.io.InputS&&
import&com.artofsolving.jodconverter.DocumentC&&
import&com.artofsolving.jodconverter.openoffice.connection.OpenOfficeC&&
import&com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeC&&
import&com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentC&&
&*&doc&docx格式转换&
public&class&DocConverter&{&&
&&&&private&static&final&int&environment&=&1;//&环境&1:windows&2:linux&&
&&&&private&String&fileS//&(只涉及pdf2swf路径问题)&&
&&&&private&String&outputPath&=&"";//&输入路径&,如果不设置就输出在默认的位置&&
&&&&private&String&fileN&&
&&&&private&File&pdfF&&
&&&&private&File&swfF&&
&&&&private&File&docF&&
&&&&public&DocConverter(String&fileString)&{&&
&&&&&&&&ini(fileString);&&
&&&&&*&重新设置file&
&&&&&*&@param&fileString&
&&&&public&void&setFile(String&fileString)&{&&
&&&&&&&&ini(fileString);&&
&&&&&*&初始化&
&&&&&*&@param&fileString&
&&&&private&void&ini(String&fileString)&{&&
&&&&&&&&this.fileString&=&fileS&&
&&&&&&&&fileName&=&fileString.substring(0,&fileString.lastIndexOf("."));&&
&&&&&&&&docFile&=&new&File(fileString);&&
&&&&&&&&pdfFile&=&new&File(fileName&+&".pdf");&&
&&&&&&&&swfFile&=&new&File(fileName&+&".swf");&&
&&&&&*&转为PDF&
&&&&&*&@param&file&
&&&&private&void&doc2pdf()&throws&Exception&{&&
&&&&&&&&if&(docFile.exists())&{&&
&&&&&&&&&&&&if&(!pdfFile.exists())&{&&
&&&&&&&&&&&&&&&&OpenOfficeConnection&connection&=&new&SocketOpenOfficeConnection(8100);&&
&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&connection.connect();&&
&&&&&&&&&&&&&&&&&&&&DocumentConverter&converter&=&new&OpenOfficeDocumentConverter(connection);&&
&&&&&&&&&&&&&&&&&&&&converter.convert(docFile,&pdfFile);&&
&&&&&&&&&&&&&&&&&&&&//&close&the&connection&&
&&&&&&&&&&&&&&&&&&&&connection.disconnect();&&
&&&&&&&&&&&&&&&&&&&&System.out.println("****pdf转换成功,PDF输出:"&+&pdfFile.getPath()+&"****");&&
&&&&&&&&&&&&&&&&}&catch&(java.net.ConnectException&e)&{&&
&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&System.out.println("****swf转换器异常,openoffice服务未启动!****");&&
&&&&&&&&&&&&&&&&&&&&throw&e;&&
&&&&&&&&&&&&&&&&}&catch&(com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException&e)&{&&
&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&System.out.println("****swf转换器异常,读取转换文件失败****");&&
&&&&&&&&&&&&&&&&&&&&throw&e;&&
&&&&&&&&&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&throw&e;&&
&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&}&else&{&&
&&&&&&&&&&&&&&&&System.out.println("****已经转换为pdf,不需要再进行转化****");&&
&&&&&&&&&&&&}&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&System.out.println("****swf转换器异常,需要转换的文档不存在,无法转换****");&&
&&&&&&&&}&&
&&&&&*&转换成&swf&
&&&&@SuppressWarnings("unused")&&
&&&&private&void&pdf2swf()&throws&Exception&{&&
&&&&&&&&Runtime&r&=&Runtime.getRuntime();&&
&&&&&&&&if&(!swfFile.exists())&{&&
&&&&&&&&&&&&if&(pdfFile.exists())&{&&
&&&&&&&&&&&&&&&&if&(environment&==&1)&{//&windows环境处理&&
&&&&&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&&&&&Process&p&=&r.exec("D:/Program&Files/SWFTools/pdf2swf.exe&"+&pdfFile.getPath()&+&"&-o&"+&swfFile.getPath()&+&"&-T&9");&&
&&&&&&&&&&&&&&&&&&&&&&&&System.out.print(loadStream(p.getInputStream()));&&
&&&&&&&&&&&&&&&&&&&&&&&&System.err.print(loadStream(p.getErrorStream()));&&
&&&&&&&&&&&&&&&&&&&&&&&&System.out.print(loadStream(p.getInputStream()));&&
&&&&&&&&&&&&&&&&&&&&&&&&System.err.println("****swf转换成功,文件输出:"&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&swfFile.getPath()&+&"****");&&
&&&&&&&&&&&&&&&&&&&&&&&&if&(pdfFile.exists())&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&pdfFile.delete();&&
&&&&&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&}&catch&(IOException&e)&{&&
&&&&&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&&&&&throw&e;&&
&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&}&else&if&(environment&==&2)&{//&linux环境处理&&
&&&&&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&&&&&Process&p&=&r.exec("pdf2swf&"&+&pdfFile.getPath()&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&"&-o&"&+&swfFile.getPath()&+&"&-T&9");&&
&&&&&&&&&&&&&&&&&&&&&&&&System.out.print(loadStream(p.getInputStream()));&&
&&&&&&&&&&&&&&&&&&&&&&&&System.err.print(loadStream(p.getErrorStream()));&&
&&&&&&&&&&&&&&&&&&&&&&&&System.err.println("****swf转换成功,文件输出:"&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&+&swfFile.getPath()&+&"****");&&
&&&&&&&&&&&&&&&&&&&&&&&&if&(pdfFile.exists())&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&pdfFile.delete();&&
&&&&&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&&&&&throw&e;&&
&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&}&else&{&&
&&&&&&&&&&&&&&&&System.out.println("****pdf不存在,无法转换****");&&
&&&&&&&&&&&&}&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&System.out.println("****swf已经存在不需要转换****");&&
&&&&&&&&}&&
&&&&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();&&
&&&&&*&转换主方法&
&&&&@SuppressWarnings("unused")&&
&&&&public&boolean&conver()&{&&
&&&&&&&&if&(swfFile.exists())&{&&
&&&&&&&&&&&&System.out.println("****swf转换器开始工作,该文件已经转换为swf****");&&
&&&&&&&&&&&&return&true;&&
&&&&&&&&}&&
&&&&&&&&if&(environment&==&1)&{&&
&&&&&&&&&&&&System.out.println("****swf转换器开始工作,当前设置运行环境windows****");&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&System.out.println("****swf转换器开始工作,当前设置运行环境linux****");&&
&&&&&&&&}&&
&&&&&&&&try&{&&
&&&&&&&&&&&&doc2pdf();&&
&&&&&&&&&&&&pdf2swf();&&
&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&return&false;&&
&&&&&&&&}&&
&&&&&&&&if&(swfFile.exists())&{&&
&&&&&&&&&&&&return&true;&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&return&false;&&
&&&&&&&&}&&
&&&&&*&返回文件路径&
&&&&&*&@param&s&
&&&&public&String&getswfPath()&{&&
&&&&&&&&if&(swfFile.exists())&{&&
&&&&&&&&&&&&String&tempString&=&swfFile.getPath();&&
&&&&&&&&&&&&tempString&=&tempString.replaceAll("\\\\",&"/");&&
&&&&&&&&&&&&return&tempS&&
&&&&&&&&}&else&{&&
&&&&&&&&&&&&return&"";&&
&&&&&&&&}&&
&&&&&*&设置输出路径&
&&&&public&void&setOutputPath(String&outputPath)&{&&
&&&&&&&&this.outputPath&=&outputP&&
&&&&&&&&if&(!outputPath.equals(""))&{&&
&&&&&&&&&&&&String&realName&=&fileName.substring(fileName.lastIndexOf("/"),&&
&&&&&&&&&&&&&&&&&&&&fileName.lastIndexOf("."));&&
&&&&&&&&&&&&if&(outputPath.charAt(outputPath.length())&==&'/')&{&&
&&&&&&&&&&&&&&&&swfFile&=&new&File(outputPath&+&realName&+&".swf");&&
&&&&&&&&&&&&}&else&{&&
&&&&&&&&&&&&&&&&swfFile&=&new&File(outputPath&+&realName&+&".swf");&&
&&&&&&&&&&&&}&&
&&&&&&&&}&&
6.部署发布
启动tomcat,部署当前web应用
地址栏输入http://localhost:8080/ctcesims/documentUpload.jsp 如下图:
单击选择文件,选择您要上传的文档,然后单击上传,处理完成后,打印如下信息,如下图所示:
单击预览按钮,就会生成预览界面,如下图:
4.常见问题
若出现swf无法预览,请访问
将生成swf的文件夹设置为信任文件位置。
以下给出 flexpaper 2.1.9 的不同之处:初始化方式改变,若文件目录与项目目录不在一起,可将附件目录在服务器中设置为虚拟目录
&%@&page&language="java"&contentType="text/&charset=UTF-8"&&
&&&&pageEncoding="UTF-8"%&&&
&&&&//String&swfFilePath=session.getAttribute("swfpath").toString();&&
&!DOCTYPE&html&PUBLIC&"-//W3C//DTD&HTML&4.01&Transitional//EN"&"http://www.w3.org/TR/html4/loose.dtd"&&&
&meta&http-equiv="Content-Type"&content="text/&charset=UTF-8"&&&
&script&type="text/javascript"&src="js/jquery.min.js"&&/script&&&
&script&type="text/javascript"&src="js/flexpaper.js"&&/script&&&
&script&type="text/javascript"&src="js/flexpaper_handlers.js"&&/script&&&
&style&type="text/css"&media="screen"&&&&
&&&&&&&&&&&&html,&body&&{&height:100%;&}&&
&&&&&&&&&&&&body&{&margin:0;&padding:0;&overflow:&}&&&&&
&&&&&&&&&&&&#flashContent&{&display:&}&&
&&&&&&&&&/style&&&&
&title&文档在线预览系统&/title&&&
&&&&&&&&&div&style="position:left:50top:10"&&&
&&&&&&&&&&&&div&id="documentViewer"&class="flexpaper_viewer"&style="width:770height:500px"&&/div&&&
&&&&&&&&&&&&&script&type="text/javascript"&&&&
&&&&&&&&&&&&var&startDocument&=&"Paper";&&
&&&&&&&&&&&&$('#documentViewer').FlexPaperViewer(&&
&&&&&&&&&&&&&&&&&&&&{&config&:&{&&
&&&&&&&&&&&&&&&&&&&&&&&&SWFFile&:&'upload/ddd3.swf',&&
&&&&&&&&&&&&&&&&&&&&&&&&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',&&
&&&&&&&&&&&&&&&&&&&&&&&&RenderingOrder&:&'flash',&&
&&&&&&&&&&&&&&&&&&&&&&&&StartAtPage&:&'',&&
&&&&&&&&&&&&&&&&&&&&&&&&ViewModeToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&ZoomToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&NavToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&CursorToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&SearchToolsVisible&:&true,&&
&&&&&&&&&&&&&&&&&&&&&&&&WMode&:&'window',&&
&&&&&&&&&&&&&&&&&&&&&&&&localeChain:&'en_US'&&
&&&&&&&&&&&&&&&&&&&&}}&&
&&&&&&&&&&&&);&&
&&&&&&&&&&&&&/script&&&&&&&&&&&&&&&
&&&&&&&&&/div&&&
最后,若需要去除打印功能及logo,可重新编译 flexpaper 的 flash文件,网上也有下载
& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区

我要回帖

更多关于 flexpaperviewer 的文章

 

随机推荐