java web在线预览pdf

网上浏览了好多博客,就不一一列举了

主要利用了pdfpreview这个js插件

我这边目前到不用调用接口把上传的文件自动转化成swf文件,目前我是安装后直接用pdf2swf把pdf转换成swf,然后页面的调用如下:

<!-- 预览pdf插件 begin -->
<script type="text/javascript" src="<%=basePath%>static/resources/pdfPreview/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>static/resources/pdfPreview/flexpaper.js"></script>
<script type="text/javascript" src="<%=basePath%>static/resources/pdfPreview/flexpaper_handlers.js"></script>
<script type="text/javascript" src="<%=basePath%>static/resources/pdfPreview/flexpaper_handlers_debug.js"></script>
<!-- 预览pdf插件 end -->

<div style="position:absolute;top:20px;left:50px;"" id="pdfContent" align="center">
	<div><button type="button" class="floatleft wybutton red small" οnclick="goback()">返回</button><br><br></div>
	<div id="documentViewer" class="flexpaper_viewer" style="width:900px;height:450px;"></div>
</div>

<script type="text/javascript">
function openSwf(name){//name写一个相对路径就可以了 不支持绝对路径
	$("#pdfList").hide();
	$("#pdfContent").show();
	$('#documentViewer').FlexPaperViewer(
		{ config : {//new FlexPaperView要传三个参数  这里的是FlexPaperViewer,viewerPlaceHolder,和config  
			SwfFile : escape('static/resources/pdfPreview/'+name),//需要Flex打开的文档,但是我发现没有FlexPaperViewer.swf的时候就不恩能够运行
	        Scale : 0.6,//缩放
	        ZoomTransition : 'easeOut',//缩放样式的选择  
	        ZoomTime : 0.5,//缩放使用的时间  
	        ZoomInterval : 0.2,//缩放比例之间间隔,默认值为0.1,该值为正数。
	        FitPageOnLoad : true,//自适应页面,工具栏上有  
	        FitWidthOnLoad : true,//自适应宽度,工具栏上有  
	        FullScreenAsMaxWindow : false,//如果设置为true的时候,点击全屏并不是全屏而是一个新页面,独立的flex播放的时候用这个比较合适  
	        ProgressiveLoading : true,//true的话不全部加载文档,边看边加载  
	        MinZoomSize : 0.2,//最大缩放比例  
	        MaxZoomSize : 2,//最小缩放比例  
	        SearchMatchAll : true,//为true的时候搜索的时候便会出现高亮  
	        InitViewMode : 'Portrait',//设置启动模式如"Portrait" or "TwoPage"
	        RenderingOrder : 'flash',
	        StartAtPage : '',

	        ViewModeToolsVisible : true,//工具栏上是否显示样式选择框
	        ZoomToolsVisible : true,//工具栏上是否显示缩放工具 
	        NavToolsVisible : true,//工具栏上是否显示导航工具  
	        CursorToolsVisible : true,//工具栏上是否显示光标工具  
	        SearchToolsVisible : true,//工具栏上是否显示搜索  
	        WMode : 'window',
	        localeChain: 'en_US'//设置语言  
		}}
	);
}

function getStudyList(path){
	var studyName = $("#studyName").val();
	$.ajax({
		type:"POST",
		async:false,
		url:path+"getStudyList.action?start=1&&rows=10&&name="+studyName,
		dataType:"json",
		success:function(jstr){
			if(jstr==null) return false;
			$studyList = $("#studyList");
			var pageCount = jstr.pageCount;
			var curPage = jstr.curPage;
			
			var studyList = jstr.result;
			var tempStr="";
			var index = 0;
			if(studyList==""||studyList==null){
			}
			else if(typeof(studyList) != "undefined"){
				$.each(studyList,function(studyList,value){
					if(value.type==1){
						index = index*1+1;
						tempStr +='<tr><td>'+index+'</td><td>'+value.name+'</td><td><a οnclick=openSwf("'+value.path+'")>查看</a></td><tr>';
					}
				});
			}
			$studyList.html("");
			$studyList.append(tempStr);
			$('#example').html("");
			if(pageCount>1){
				  var options = {
				    currentPage: curPage,
					totalPages: pageCount,
					showFirstPage:false,
					showPrePage:true,
					showNextPage:true,
					showLastPage:false,
					itemTexts: function (type, page, current) {
						switch (type) {
							case "first":
						    	return "<<";
						  	case "prev":
						      	return "<";
						  	case "next":
						      	return ">";
						  	case "last":
						      	return ">>";
						  	case "page":
						      	return page;
						}
					},
					onPageClicked: function (event, originalEvent, type, page) {
						var studyName = $("#studyName").val();
						$.ajax({
							type:"POST",
							async:false,
							url:path+"getStudyList.action?start="+page+"&&rows=10&&name="+studyName,
							dataType:"json",
							success:function(jstr){
								if(jstr==null) return false;
								$studyList = $("#studyList");
								
								var studyList = jstr.result;
								var tempStr="";
								if(page==1){
									index = 0; 
								}
								else{
									index = (page-1)*10;
								}
								if(studyList==""||studyList==null){
								}
								else if(typeof(studyList) != "undefined"){
									$.each(studyList,function(studyList,value){
										if(value.type==1){
											index = index*1+1;
											tempStr +='<tr><td>'+index+'</td><td>'+value.name+'</td><td><a οnclick=openSwf("'+value.path+'")>查看</a></td><tr>';
										}
									});
								}
								$studyList.html("");
								$studyList.append(tempStr);
							},
							error:function(){
								alert("获取穴位失败");
							}
						});
					}
				}
				$('#example').bootstrapPaginator(options);
			}
		},
		error:function(){
			alert("获取穴位失败");
		}
	});
}
</script>

提醒一下在转化的时候,pdf2swf里的转换格式要用no viewer不然没法显示哈,我当初也被坑了好久才发现



最后上一下效果图哈



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值