引言
由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf转换为swf格式的文件预览的,所以flexpaper一般和swftool配合使用,在程序运行时将pdf文件转换为swf格式的文件。
如果flexpaper不满足你的要求,也可以对其进行二次开发,这里推荐两篇文章,希望对您有所帮助:
http://www.cnblogs.com/xcong/archive/2013/06/20/3142155.html
http://www.cnblogs.com/zamlove/archive/2013/05/07/3065079.html
如何使用flexpaper
测试demo项目结构如图
使用的页面代码:
1 DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 4 <head> 5 <title></title> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 7 <style type="text/css" media="screen"> 8 html, body { 9 height: 100%; 10 } 11 12 body { 13 margin: 0; 14 padding: 0; 15 overflow: auto; 16 } 17 18 #flashContent { 19 display: none; 20 } 21 </style> 22 23 <script type="text/javascript" src="js/swfobject/swfobject.js"></script> 24 <script type="text/javascript" src="js/flexpaper_flash.js"></script> 25 26 <script type="text/javascript"> 27 28 var swfVersionStr = "10.0.0"; 29 30 var xiSwfUrlStr = "playerProductInstall.swf"; 31 32 var flashvars = { 33 SwfFile: escape("Paper.swf"), 34 Scale: 0.6, 35 ZoomTransition: "easeOut", 36 ZoomTime: 0.5, 37 ZoomInterval: 0.1, 38 FitPageOnLoad: false, 39 FitWidthOnLoad: true, 40 PrintEnabled: true, 41 FullScreenAsMaxWindow: false, 42 ProgressiveLoading: true, 43 PrintToolsVisible: true, 44 ViewModeToolsVisible: true, 45 ZoomToolsVisible: true, 46 FullScreenVisible: true, 47 NavToolsVisible: true, 48 CursorToolsVisible: true, 49 SearchToolsVisible: true, 50 localeChain: "en_US" 51 }; 52 var params = { 53 } 54 params.quality = "high"; 55 params.bgcolor = "#ffffff"; 56 params.allowscriptaccess = "sameDomain"; 57 params.allowfullscreen = "true"; 58 var attributes = {}; 59 attributes.id = "FlexPaperViewer"; 60 attributes.name = "FlexPaperViewer"; 61 swfobject.embedSWF( 62 "FlexPaperViewer.swf", "flashContent", 63 "650", "500", 64 swfVersionStr, xiSwfUrlStr, 65 flashvars, params, attributes); 66 swfobject.createCSS("#flashContent", "display:block;text-align:left;"); 67 </script> 68 69 </head> 70 <body> 71 <div style="position:absolute;left:10px;top:10px;"> 72 <div id="flashContent"> 73 <p> 74 To view this page ensure that Adobe Flash Player version 75 10.0.0 or greater is installed. 76 </p> 77 <script type="text/javascript"> 78 var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://"); 79 document.write(""); 81 </script> 82 </div> 83 <div id="errNoDocument" style="padding-top:10px;"> 84 Can't see the document? Running FlexPaper from your local directory? Make sure you have added FlexPaper as trusted. You can do that at <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065">Adobe's website</a>. 85 </div> 86 </div> 87 </body> 88 </html>
效果图
上面的工具栏:打印,全屏等功能可配置。
swftool工具
操作类(本类来自常用类库,从网上下载的,一搜一大把)
1 using System.Web; 2 using System.Text; 3 4 public static class PSD2swfHelper 5 { 6 /// 7 /// 转换所有的页,图片质量80% 8 /// 9 ///
然后安装swftool工具,将安装后的目录中的文件拷贝到tools目录下,如图
test.asp.cs代码
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 8 namespace Wolfy.FlexPaperDemo 9 { 10 public partial class Test : System.Web.UI.Page 11 { 12 protected void Page_Load(object sender, EventArgs e) 13 { 14 //这里需要虚拟路径 15 PSD2swfHelper.PDF2SWF("PDFFile/王牌2_C#_控件查询手册.pdf", "SWFFile/王牌2_C#_控件查询手册.swf"); 16 } 17 } 18 }
结果
如何禁用右键中的打印,复制功能
如果pdf保密性强,不让别人复制,打印等该如何?在上面推荐的两篇文章中,他们对其进行了二次开发,禁用了这个功能。非常感谢,那么之后只需将FlexPaperViewer.swf替换就可以了。
原图
替换后的
说保密只是相对的,在互联网上,只要能看,别人想盗取还是很容易的事,大不了,一张一张的截图。
总结
demo下载:链接:链接:http://pan.baidu.com/s/1hqEpx5a 密码:gupg
swftools-2013-04-09-1007下载:链接:http://pan.baidu.com/s/1c0CvBDA 密码:v38r
博客地址: | http://www.cnblogs.com/wolf-sun/ |
博客版权: | 本文以学习、研究和分享为主,欢迎转载,但必须在文章页面明显位置给出原文连接。 如果文中有不妥或者错误的地方还望高手的你指出,以免误人子弟。如果觉得本文对你有所帮助不如【推荐】一下!如果你有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。 转载:http://www.cnblogs.com/wolf-sun/p/3525437.html |