1,、安装swftools
2、配置xpdf-chinese-simplified
3、工具类 Converter .java
package net.survey.domain;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
public class Converter {
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 9";
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();
}
}
4、action调用
public String pdf2swf() throws Exception{
String sourcePath="D:\\test\\test.pdf";
String destPath="D:\\test\\";
String fileName="test.swf";
int a=Converter.convertPDF2SWF(sourcePath, destPath, fileName);
return SUCCESS;
}
5、showpdf.jsp
<%@page contentType="text/html;charset=GBK" pageEncoding="GBK" %>
<%@ taglib prefix="ww" uri="/webwork" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
<script type="text/javascript" src="../Scripts/index_js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../js/flexpaper.js"></script>
</head>
<body>
<div id="divGrid" style="display:block;height:680px;"></div>
<script type="text/javascript">
$("#divGrid").FlexPaperViewer(
{ config : {
SwfFile: escape('http://localhost:8080/environment/environment/test.swf'),
Scale : 0.6,
ZoomTransition : 'easeOut',
ZoomTime : 0.5,
ZoomInterval : 0.2,
FitPageOnLoad : true,
FitWidthOnLoad : true,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : false,
MinZoomSize : 0.2,
WMode:window,
MaxZoomSize : 5,
SearchMatchAll : false,
InitViewMode : 'Portrait',
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: 'zh_CN'
}});
</script>
</body>
</html>
6、注意事项:FlexPaperViewer.swf放在WebContent下