Convert源码
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
/**
* @author 李义海
* QQ:407009617
* pdf格式文件转化为swf格式插件
* 插件要求:必须安装SWFTools工具
* 本例安装在:D://SWFTools//pdf2swf.exe 可以根据自己的路径进行修改
*/
public class Convert {
// 文件名:fileName 文件路径(不带文件名):destPath
public static String ConvertPdfToSwf(String fileName,String destPath){
String destName = "",fileExt = "";
StringBuffer command = new StringBuffer();
fileExt = fileName.split("//.")[fileName.split("//.").length-1].toLowerCase();
try{
File file = new File(destPath+fileName);
System.out.println("fileName=="+fileName+"/n file=="+file);
if(!file.exists()){//判断源文件是否存在
return "文件不存在";
}else if(!fileExt.equals("pdf")){//判断文件是否是pdf格式的文件
return "文件不是pdf格式";
}
else{
String swftoolsPath = "D://SWFTools//";//获取pdf转swf工具的路径
if(!swftoolsPath.substring(swftoolsPath.length()-1, swftoolsPath.length()).equals("//")){
swftoolsPath = swftoolsPath+"//"; //在目录后加 "/"
}
if(!destPath.substring(destPath.length()-1, destPath.length()).equals("//")){
destPath = destPath+"//"; //在目录后加 "/"
}
File destFile = new File(destPath);
if(!destFile.exists()){//目标文件路径如果不存在,则创建目录
destFile.mkdirs();
}
destName = file.getName().substring(0, file.getName().length()-4)+".swf"; //得到目标文件名称
command.append("cmd /c ").append(swftoolsPath).append("pdf2swf.exe ").append(" -o ").append(destPath).append(destName).append(" -i ").append(destPath).append(fileName).append(" -s flashversion=9 ");
Process pro = Runtime.getRuntime().exec(command.toString());
BufferedReader buffer = new BufferedReader(new InputStreamReader(pro.getInputStream()));
while(buffer.readLine()!=null);
return pro.toString();
}
}catch (Exception e){
e.printStackTrace();
return "转化失败";
}
}
public static void main(String args[]) {
System.out.println(Convert.ConvertPdfToSwf("test.pdf","E://alipaydirect//"));
}
}
使用:
<!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:; }
</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 flashvars = {
SwfFile : escape("test.swf?v1.4.0rc2-refresh2"),
Scale : 1,
ZoomTransition : "easeOut",
ZoomTime : 0.5,
ZoomInterval : 0.1,
FitPageOnLoad : false,
FitWidthOnLoad : false,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
PrintToolsVisible : true,
ViewModeToolsVisible : false,
ZoomToolsVisible : true,
FullScreenVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: "zh_CN"
};
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",
"650", "600",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
</head>
<body>
<div style="position:absolute;left:10px;top:10px;">
<div id="flashContent">
<p>
需要安装flash 10 及以上版本才可以浏览。
</p>
<script type="text/javascript">
var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
+ pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
</script>
</div>
</div>
</body>
</html>
彷豆丁百度文库 pdf格式文件转化为swf格式插件
最新推荐文章于 2024-11-15 20:04:07 发布