将pdf显示到jsp页面

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下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值