The page displays the document(doc to swf)
在页面中显示文档信息供客户在线查看文档内容 目前activex控件可以较好的完成文档的在线编辑和查看功能,但是找了很多网站都是对外收费的。根据需求并不需要对文档进行在线编辑,只要能够查看,所以采用doc转换为pdf在转换为swf使用flexpaper在线显示。 本章针对win7 64bit 系统 java环境开发 1.安装OpenOffice,swfTools软件,配置好java代码的运行环境。 3.现在language包xpdf-chinese-simplified.tar和项目开发使用工具包jodconverter ??? 将jodconverter解压以后,把lib下面的jar包全部添加到项目 doc2pdf处理方法,E:toolsswftools是swfTools安装路径,D:xpdfxpdf-chinese-simplified为xpdf-chinese-simplified文件夹路径
import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; 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 = "E:toolsswftoolspdf2swf.exe" + " -o "" + destPath + "" + fileName + "" -s languagedir=D:xpdfxpdf-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(); } } doc2pdf测试类 8100:opeonofiice中设置的端口,由于启动此服务占用内存比较大,所以使用后将连接释放。 package com.wenhi.cms.common.util.swf; import java.io.File; import java.net.ConnectException; 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; public class Office2Pdf { public static void main(String[] args) throws Exception { String a = "业务需求0319"; off2Pdf(a); } public static void off2Pdf(String fileName) { File inputFile = new File("d:/" + fileName + ".doc"); 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方式,这种方式有个需要注意的地方,在调用安装程序处理时在系统上配置环境变量并不能 被程序调用,window中测试如此。所以需要写完整路径 Runtime.exec() 有四种调用方法 ??? * public Process exec(String command); package com.wenhi.cms.common.util.swf; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; public class Pdf2Swf { //实现由pdf格式到swf格式的转换 public int convertPDF2SWF(String sourcePath,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=E:toolsswftools"; // String command = "pdf2swf -z -s flashversion=9 "" + sourcePath // + "" -o "" + destPath + fileName + """; String command = "E:toolsswftoolspdf2swf.exe -z -s flashversion=9 "" + sourcePath + "" -o "" + destPath + fileName + """; Runtime rt = Runtime.getRuntime(); //Process pro = rt.exec(cmd,envp); 这种方法不能使用虽然配置有环境变量但是程序不能够自动调用 Process pro = rt.exec(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) { e.printStackTrace(); } // 然后在套播放器 command = "E:toolsswftoolsswfcombine -z -X 720 -Y 540 "E:/tools/swftools/swfs/rfxview.swf" viewport="" + destPath + fileName + "" -o "" + destPath + fileName + """; pro = Runtime.getRuntime().exec(command); 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) { e.printStackTrace(); } return pro.exitValue(); } public static void main(String[] args) { String sourcePath = "d:/业务需求0319.pdf"; String destPath = "d:/"; String fileName = "业务需求0319.swf"; try { System.out.println(new Pdf2Swf().convertPDF2SWF(sourcePath,destPath,fileName)); } catch (IOException e) { e.printStackTrace(); } } } 注意:注意代码中加载各个软件的本地路径要正确,防止加载不到软件而报错 ?????????在代码运行前要启动openoffice服务,否则不能完成文件格式的转换 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- PostgreSQL数据库dblink和postgres_fdw扩展使用比较
- c# – 需要linq to objects查询嵌套集合
- Redux系列02:一个炒鸡简单的react+redux例子
- 如何更改React material-ui中的活动标签颜色?
- cocos2d-x 3.2 物理碰撞机制
- Flex 自定义右键菜单
- oracle 11gR2 for win7旗舰版64安装以及连接plsql和NaviCat
- [C#.NET][SpecFlow] 使用 Scenario Outline 执行多次验证
- React with TypeScript 系列(一) --概述
- flashbuilder4 单选 RadioButton RadioButtonGroup