[Asp.net]使用flexpaper+swftools大文件分頁轉換實現在線預覽


引言

之前總結了在線預覽幾種常見解決方案,可以戳這里:

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     }

使用:

 1  public partial class Test : System.Web.UI.Page
 2     {
 3         protected void Page_Load(object sender, EventArgs e)
 4         {
 5             string pdfPath="PDFFile/王牌2_C#_控件查詢手冊.pdf";
 6             
 7             int pageCount = PSD2swfHelper.GetPageCount(Server.MapPath(pdfPath));
 8             for (int i = 1; i <=pageCount; i++)
 9             {
10                 //i to i 當前頁
11                 PSD2swfHelper.PDF2SWF(pdfPath, "SWFFile/" + i.ToString() + ".swf", i, i, 80);
12             }
13             //這里需要虛擬路徑
14            // PSD2swfHelper.PDF2SWF("PDFFile/王牌2_C#_控件查詢手冊.pdf", "SWFFile/王牌2_C#_控件查詢手冊.swf");
15         }
16     }

結果:

修改預覽頁面,flexpaper配置信息:

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

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

 1   var flashvars = {
 2             SwfFile: "{/SWFFile/[*,0].swf,52}",//這里需要修改
 3             Scale: 0.6,
 4             ZoomTransition: "easeOut",
 5             ZoomTime: 0.5,
 6             ZoomInterval: 0.1,
 7             FitPageOnLoad: false,
 8             FitWidthOnLoad: true,
 9             PrintEnabled: true,
10             FullScreenAsMaxWindow: false,
11             ProgressiveLoading: true,
12             PrintToolsVisible: true,
13             ViewModeToolsVisible: true,
14             ZoomToolsVisible: true,
15             FullScreenVisible: true,
16             NavToolsVisible: true,
17             CursorToolsVisible: true,
18             SearchToolsVisible: true,
19             localeChain: "en_US"
20         };

測試結果:

總結

這里只是將工作中遇到的問題,記錄一下,這種方式,轉換速度太慢了,也許你有更好的解決方案,不妨分享一下你的解決方案,不勝感激。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM