Welcome

首页 / 软件开发 / Flex / 如何使用flexpaper+swftools大文件分页转换实现在线预览

如何使用flexpaper+swftools大文件分页转换实现在线预览2015-02-03引言

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

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,将私有改为公有:

 1 /// <summary>
2 /// PDF格式转为SWF
3 /// </summary>
4 /// <param name="pdfPath">PDF文件地址</param>
5 /// <param name="swfPath">生成后的SWF文件地址</param>
6 /// <param name="beginpage">转换开始页</param>
7 /// <param name="endpage">转换结束页</param>
8 public static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
9 {
10 //swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
11 string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
12 pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
13 swfPath = HttpContext.Current.Server.MapPath(swfPath);
14 if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
15 {
16 return false;
17 }
18 StringBuilder sb = new StringBuilder();
19 sb.Append(" "" + pdfPath + """);
20 sb.Append(" -o "" + swfPath + """);
21 sb.Append(" -s flashversion=9");
22 if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
23 sb.Append(" -p " + """ + beginpage + "" + "-" + endpage + """);
24 sb.Append(" -j " + photoQuality);
25 string Command = sb.ToString();
26 System.Diagnostics.Process p = new System.Diagnostics.Process();
27 p.StartInfo.FileName = exe;
28 p.StartInfo.Arguments = Command;
29 p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
30 p.StartInfo.UseShellExecute = false;
31 p.StartInfo.RedirectStandardError = true;
32 p.StartInfo.CreateNoWindow = false;
33 p.Start();
34 p.BeginErrorReadLine();
35 p.WaitForExit();
36 p.Close();
37 p.Dispose();
38 return true;
39 }