首页 技术 正文
技术 2022年11月17日
0 收藏 600 点赞 3,493 浏览 2916 个字

引言

之前总结了在线预览几种常见解决方案,可以戳这里:

http://www.cnblogs.com/wolf-sun/p/3569960.html

http://www.cnblogs.com/wolf-sun/p/3525437.html

http://www.cnblogs.com/wolf-sun/p/3574278.html

客户突然给了比较大的文档,赫然崩溃,项目中采用的是flexpaper+swftools方式实现的,发现在pdf-》swf的时候,转了100页之后,就会出现问题,很无奈,可能客户上传的word文档有问题,客户给的文档,页面方向有横向的,也有纵向的。没办法只能想办法解决了。

最后想到了将他们一页一页的转,说实话我都疯了,几百页的文档,抽支烟回来才转完,你不疯不行啊。

之后想了用其他几种解决方案,由于客户要求文档不能被下载,被复制,要有保密性,这需求,你想保密,想安全,就别放在网上啊,别人只要想要,一张一张的截图,也能给你的文档扣下来,想当年,考研那会儿,我都干过这事,考题都是从网上一张一张截图搞下来的。现在想想,当时真sb。

单页pdf转swf

这里还是使用这篇文章中的demo:http://www.cnblogs.com/wolf-sun/p/3525437.html

然后修改PSD2SwfHelper类下的方法PDF2SWF和GetPageCount,将私有改为公有:

   /// <summary>
/// PDF格式转为SWF
/// </summary>
/// <param name="pdfPath">PDF文件地址</param>
/// <param name="swfPath">生成后的SWF文件地址</param>
/// <param name="beginpage">转换开始页</param>
/// <param name="endpage">转换结束页</param>
public static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
{
//swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
swfPath = HttpContext.Current.Server.MapPath(swfPath);
if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
{
return false;
}
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -s flashversion=9");
if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
sb.Append(" -j " + photoQuality);
string Command = sb.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = Command;
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
return true;
}

使用:

  public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pdfPath="PDFFile/王牌2_C#_控件查询手册.pdf"; int pageCount = PSD2swfHelper.GetPageCount(Server.MapPath(pdfPath));
for (int i = ; i <=pageCount; i++)
{
//i to i 当前页
PSD2swfHelper.PDF2SWF(pdfPath, "SWFFile/" + i.ToString() + ".swf", i, i, );
}
//这里需要虚拟路径
// PSD2swfHelper.PDF2SWF("PDFFile/王牌2_C#_控件查询手册.pdf", "SWFFile/王牌2_C#_控件查询手册.swf");
}
}

结果:

[Asp.net]使用flexpaper+swftools大文件分页转换实现在线预览

修改预览页面,flexpaper配置信息:

参考文章:http://www.blogjava.net/jforeverg/archive/2011/07/06/353813.html

http://blog.csdn.net/mishidezhu/article/details/7094490

   var flashvars = {
SwfFile: "{/SWFFile/[*,0].swf,52}",//这里需要修改
Scale: 0.6,
ZoomTransition: "easeOut",
ZoomTime: 0.5,
ZoomInterval: 0.1,
FitPageOnLoad: false,
FitWidthOnLoad: true,
PrintEnabled: true,
FullScreenAsMaxWindow: false,
ProgressiveLoading: true,
PrintToolsVisible: true,
ViewModeToolsVisible: true,
ZoomToolsVisible: true,
FullScreenVisible: true,
NavToolsVisible: true,
CursorToolsVisible: true,
SearchToolsVisible: true,
localeChain: "en_US"
};

测试结果:
[Asp.net]使用flexpaper+swftools大文件分页转换实现在线预览

总结

这里只是将工作中遇到的问题,记录一下,这种方式,转换速度太慢了,也许你有更好的解决方案,不妨分享一下你的解决方案,不胜感激。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918