引言

由于客户有在线预览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 <!-- saved from url=(0014)about:internet -->
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 <!--首先引入相关的js文件-->
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 <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->
28 var swfVersionStr = "10.0.0";
29 <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
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("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
80 + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>");
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 /// <summary>
7 /// 转换所有的页,图片质量80%
8 /// </summary>
9 /// <param name="pdfPath">PDF文件地址</param>
10 /// <param name="swfPath">生成后的SWF文件地址</param>
11 public static bool PDF2SWF(string pdfPath, string swfPath)
12 {
13 return PDF2SWF(pdfPath, swfPath, 1, GetPageCount(HttpContext.Current.Server.MapPath(pdfPath)), 80);
14 }
15
16 /// <summary>
17 /// 转换前N页,图片质量80%
18 /// </summary>
19 /// <param name="pdfPath">PDF文件地址</param>
20 /// <param name="swfPath">生成后的SWF文件地址</param>
21 /// <param name="page">页数</param>
22 public static bool PDF2SWF(string pdfPath, string swfPath, int page)
23 {
24 return PDF2SWF(pdfPath, swfPath, 1, page, 80);
25 }
26
27 /// <summary>
28 /// PDF格式转为SWF
29 /// </summary>
30 /// <param name="pdfPath">PDF文件地址</param>
31 /// <param name="swfPath">生成后的SWF文件地址</param>
32 /// <param name="beginpage">转换开始页</param>
33 /// <param name="endpage">转换结束页</param>
34 private static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
35 {
36 //swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
37 string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
38 pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
39 swfPath = HttpContext.Current.Server.MapPath(swfPath);
40 if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
41 {
42 return false;
43 }
44 StringBuilder sb = new StringBuilder();
45 sb.Append(" \"" + pdfPath + "\"");
46 sb.Append(" -o \"" + swfPath + "\"");
47 sb.Append(" -s flashversion=9");
48 if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
49 sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
50 sb.Append(" -j " + photoQuality);
51 string Command = sb.ToString();
52 System.Diagnostics.Process p = new System.Diagnostics.Process();
53 p.StartInfo.FileName = exe;
54 p.StartInfo.Arguments = Command;
55 p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
56 p.StartInfo.UseShellExecute = false;
57 p.StartInfo.RedirectStandardError = true;
58 p.StartInfo.CreateNoWindow = false;
59 p.Start();
60 p.BeginErrorReadLine();
61 p.WaitForExit();
62 p.Close();
63 p.Dispose();
64 return true;
65 }
66
67 /// <summary>
68 /// 返回页数
69 /// </summary>
70 /// <param name="pdfPath">PDF文件地址</param>
71 private static int GetPageCount(string pdfPath)
72 {
73 byte[] buffer = System.IO.File.ReadAllBytes(pdfPath);
74 int length = buffer.Length;
75 if (buffer == null)
76 return -1;
77 if (buffer.Length <= 0)
78 return -1;
79 string pdfText = Encoding.Default.GetString(buffer);
80 System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");
81 System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);
82 return matches.Count;
83 }
84 }

然后安装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/1sjnSsyx 密码:jjbx

swftools-2013-04-09-1007下载:http://pan.baidu.com/s/1jGI8H4U

出处:http://www.cnblogs.com/wolf-sun/p/3525437.html
 
存在问题:
 
可惜pdf太大了 swftools转swf时 就崩溃了
解决:
 
flashpaper不支持64位机,不妨试一下print2flash。
 
更新版本的地址:http://www.cnblogs.com/wolf-sun/p/3631381.html

FlexPaper+SWFTool+操作类=在线预览PDF(转)的更多相关文章

  1. FlexPaper+SWFTool+操作类=在线预览PDF

    引言 由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf转换为swf格式的文件预览的,所以flexpaper一般和swf ...

  2. 在线预览PDF

    FlexPaper+SWFTool+操作类=在线预览PDF   引言 由于客户有在线预览PDF格式的需求,在网上找了一下解决方案,觉得FlexPaper用起来还是挺方便的,flexpaper是将pdf ...

  3. .net mvc使用FlexPaper插件实现在线预览PDF,EXCEL,WORD的方法

    FlexPaper插件可以实现在浏览器中在线预览pdf,word,excel等. 在网上看到很多关于这个插件实现预览的技术,但是很难做到word和excel在线预览. pdf很好实现. 首先下载相关的 ...

  4. 网页中动态嵌入PDF文件/在线预览PDF内容https://www.cnblogs.com/xgyy/p/6119459.html

    #网页中动态嵌入PDF文件/在线预览PDF内容# 摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如 ...

  5. WEB在线预览PDF

    这是我在博客园发表的第一篇文章.以后会陆续把在线预览其他格式文档的解决方案发表出来. 解决思路:把pdf转换成html显示. 在线预览pdf我暂时了解3种解决方案,欢迎大家补充. 方案一: 利用pdf ...

  6. 用pdf.js实现在移动端在线预览pdf文件

    用pdf.js实现在移动端在线预览pdf文件1.下载pdf.js    官网地址:https://mozilla.github.io/pdf.js/ 2.配置    下载下来的文件包,就是一个demo ...

  7. #网页中动态嵌入PDF文件/在线预览PDF内容#

    摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如下: 代码片段1: 1 <object ty ...

  8. 前端实现在线预览pdf、docx、xls、ppt等文件

    思路:前台将各种格式的附件上传到服务器----后台通过方法将这些格式的文件转化成图片,前台通过放映ppt的方式将其展示在页面上. 关键点:reveal.js 参考文章:https://www.awes ...

  9. 网页嵌入pdf、在线预览pdf工具及插件(转)

    摘要:在web开发时我们有时会需要在线预览PDF内容,在线嵌入pdf文件: 问题1:如何网页中嵌入PDF: 在网页中: 常用的几种PDF预览代码片段如下: 代码片段1: 1 <object ty ...

随机推荐

  1. 清理收缩VMware虚拟机MacOS系统的vmdk文件大小

    屌丝行和差的主要标准,尽管持续性眼贪婪mbp.但是,从另一方面限制患有米,只是在虚拟机中播放MacOS.(我不会告诉你我的笔记本i5+120SSD+500HHD+12G内存,跑MacOS虚拟机一点不卡 ...

  2. 私人定制javascript中数组小知识点(Only For Me)

    先上笑话,1.刚看到一个游泳的,想起公司组织去三亚旅游,老板跳海里,各种挣扎,捞上来老板第一句话:我记得我会游泳的啊. 2.媳妇说:老公对不起,我把你新买的自行车撞散架了! 老公:没事宝贝,你若安好, ...

  3. CSharp设计模式读书笔记(11):外观模式(学习难度:★☆☆☆☆,使用频率:★★★★★)

    定义: 外观模式:为子系统中的一组接口提供一个统一的入口.外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 模式角色与结构: 示例代码: using System; using Sys ...

  4. hdu2191 悼念512汶川大地震遇难同胞——珍惜如今,感恩生活

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 Problem ...

  5. 针对不同手机系统的LBS地图定位解决方案

    原文:针对不同手机系统的LBS地图定位解决方案 摘要: 针对目前的三种手机系统:Android安卓.S60塞班.IOS苹果,做出的三种不同的手机地图应用解决方案. 查阅了多数地图API对手机的支持情况 ...

  6. Github Pages 静态网页建站

    创建仓库 略.详见GitHub使用教程. 仓库属性设置 找Github Pages项.点击自己主动生成,依照提示操作,就会得到该项目的gh-pages 分支. 公布站点成功,地址为 http://ch ...

  7. C#中使用ref 和 out 的一点认识

    ref 通常我们向方法中传递的是值,方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢弃,而原来的值不会受到影响. 这种情况是通常的,当然还有另外一种情况,我们向方法传递 ...

  8. Java初认识--函数和数组

    一.函数 1.函数的定义 函数就是定义在类中的具有特定功能的一段独立小程序,函数也称为方法. java中最小的功能单元就是函数. 2.函数的格式 修饰符 返回值类型 函数名(参数类型 形式参数1,参数 ...

  9. Oracle 免费的数据库

    Oracle 免费的数据库--Database 快捷版 11g 安装使用与"SOD框架"对Oracle的CodeFirst支持 一.Oracle XE 数据库与连接工具安装使用 O ...

  10. SSAS系列——【08】多维数据(程序展现Cube)

    原文:SSAS系列--[08]多维数据(程序展现Cube) 1.引用DLL? 按照之前安装的MS SQLServer的步骤安装完成后,发现在新建的项目中“Add Reference”时居然找不到Mic ...