package util;
import java.io.File;
import java.util.regex.Pattern;
/**
*
*
* @desc 需要swftools第三插件的支持 ,支持window\linux\mac等系统
*/
public class Office2Swf {
/**
* 根据操作系统的名称,获取执行pdf->swf文件的命令
*
* @param pdfFile
* 转换的pdf源文件路径
* @param swfOutFilePath
* 输出的swf文件路径
* @return
*/
private static String getCommand(String pdfFile, String swfOutFilePath) {
String command = null;
String osName = System.getProperty("os.name");
if (null == swfOutFilePath || "".equals(swfOutFilePath.trim())) {
swfOutFilePath = pdfFile.toLowerCase().replaceAll(".pdf", ".swf");
}
if (Pattern.matches("Linux.*", osName)) {
command = "pdf2swf " + pdfFile + " -o " + swfOutFilePath + " -T 9 -f -s languagedir=/usr/local/xpdf/xpdf-chinese-simplified";
} else if (Pattern.matches("Windows.*", osName)) {
command = "D:/Program Files/SoftWare/work/swftools/pdf2swf.exe -t " + pdfFile + " -o " + swfOutFilePath
+ " -T 9 -f";
} else if (Pattern.matches("Mac.*", osName)) {
}
return command;
}
/**
* 将pdf转换swf文件,在线预览
*
* @param pdfInputFilePath
* 待转换的pdf源文件路径
* @param swfOutFilePath
* 输出的swf目标文件路径,如果未指定(null),则按在源文件当前目录生成同名的swf文件
* @return swf目标文件路径
*/
public static String pdf2Swf(String pdfInputFilePath, String swfOutFilePath) {
String command = getCommand(pdfInputFilePath, swfOutFilePath);
try {
Process pro = Runtime.getRuntime().exec(command);
pro.waitFor();
return pdfInputFilePath.replaceAll("." + getPostfix(pdfInputFilePath), ".swf");
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* 将office文件直接转换为swf文件
*
* 如果是pdf直接轉換
*
* @param inputFilePath
* 待转换的源office文件路径
* @param outputSwfPath
* 输出的swf目标文件路径,如果未指定(null),则按在源文件当前目录生成同名的swf文件
* @return swf目标文件路径
*/
public static String office2Swf(String inputFilePath, String outputSwfPath) {
String outputPdfPath = null;
if ("pdf".equals(getPostfix(inputFilePath))) {
String swfName = new File(outputSwfPath).getName();
String pdfName = new File(inputFilePath).getName();
String new_swfName = swfName.replace("." + getPostfix(outputSwfPath), ".pdf");
outputPdfPath = inputFilePath.replace(pdfName, new_swfName);
File old_inputFilePath = new File(inputFilePath);
File new_outputPdfPath = new File(outputPdfPath);
old_inputFilePath.renameTo(new_outputPdfPath); // 把pdf重命名
outputSwfPath = pdf2Swf(outputPdfPath, outputSwfPath);
} else {
if (null == outputSwfPath || "".equals(outputSwfPath.trim())) {
outputPdfPath = inputFilePath.replace("." + getPostfix(inputFilePath), ".pdf");
} else {
outputPdfPath = outputSwfPath.replace("." + getPostfix(outputSwfPath), ".pdf");
}
boolean isSucc = Office2PDF.openOffice2Pdf(inputFilePath, outputPdfPath);
if (isSucc) {
outputSwfPath = pdf2Swf(outputPdfPath, outputSwfPath);
}
}
return outputSwfPath;
}
/**
* 获取文件的后缀名
*/
private static String getPostfix(String inputFilePath) {
String postfix = null;
if (null != inputFilePath && !"".equals(inputFilePath.trim())) {
int idx = inputFilePath.lastIndexOf(".");
if (idx > 0) {
postfix = inputFilePath.substring(idx + 1, inputFilePath.trim().length());
}
}
return postfix;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
FLexPaper实现java在线预览源码
共41个文件
jar:18个
class:3个
java:3个
4星 · 超过85%的资源 需积分: 10 13 下载量 135 浏览量
2017-12-01
19:55:30
上传
评论
收藏 5.21MB ZIP 举报
温馨提示
FLexPaper实现java在线预览源码 去掉logo,去掉打印,去掉右键打印,可复制中文,二次开发
资源推荐
资源详情
资源评论
收起资源包目录
WebOffice2.zip (41个子文件)
WebOffice2
.project 910B
WebContent
WEB-INF
lib
slf4j-api-1.5.6.jar 22KB
slf4j-jdk14-1.5.6.jar 9KB
jstl-impl.jar 379KB
jodconverter-cli-2.2.2.jar 6KB
jodconverter-2.2.2.jar 31KB
jcom.jar 67KB
jurt-3.0.1.jar 106KB
javax.servlet.jsp.jstl.jar 44KB
ridl-3.0.1.jar 248KB
jsf-impl.jar 1.78MB
juh-3.0.1.jar 54KB
unoil-3.0.1.jar 1.3MB
commons-cli-1.2.jar 40KB
commons-fileupload-1.2.2.jar 58KB
jsf-api.jar 593KB
jodconverter-core 3.0-beta-4.jar 68KB
commons-io-1.4.jar 106KB
xstream-1.3.1.jar 421KB
web.xml 594B
upload
readonline.jsp 2KB
META-INF
MANIFEST.MF 39B
FlexPaper
js
flexpaper_flash_debug.js 11KB
jquery.js 89KB
flexpaper_flash.js 10KB
swfFiles
FlexPaperViewer.swf 614KB
readfile.jsp 661B
src
util
Office2PDF.java 3KB
Office2Swf.java 4KB
servlet
UploadServlet.java 3KB
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 98B
org.eclipse.wst.common.component 482B
.jsdtscope 567B
build
classes
util
Office2PDF.class 4KB
Office2Swf.class 3KB
servlet
UploadServlet.class 5KB
.classpath 842B
共 41 条
- 1
资源评论
- 渡边沐风2018-08-31pom 文件如何配置袁宝东2018-11-19没有pom文件,
袁宝东
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 555springboot + vue 线上教学平台.zip(可运行源码+数据库文件+文档)
- 554springcloud + vue 房产销售平台.zip(可运行源码+数据库文件+文档)
- 小霸王坦克游戏源码.7z
- 蓝桥杯单片机基础学习项目(LED,数码管,蜂鸣器,继电器,按键控制)
- 553springboot + vue 某银行OA系统.zip(可运行源码+数据库文件+文档)
- DatabaseWatermarkingBasedonTextFormat
- yolov8常用二维码检测检测+数据集
- -移动通信-网络课程设计与研究
- 基于Python的PCA人脸识别算法的原理及实现代码+文档详解.zip
- 甘肃移动全业务工程建设项目管理流程优化研究
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功