.NET實現在網頁中預覽Office文件的3個方法(4)_.Net教程
推薦:asp.net中控制反轉怎么理解?對IOC的解釋為:Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels. 我想對這一概念執行
#region 2.02 轉換PDF文件為SWF格式 +PDFConvertToSwf(string pdfPath, string swfPath, int page)
/// <summary>
/// 轉換PDF文件為SWF格式
/// </summary>
/// <param name="pdfPath">PDF文件路徑</param>
/// <param name="swfPath">SWF生成目標文件路徑</param>
/// <param name="page">PDF頁數</param>
/// <returns>生成是否成功</returns>
public static bool PDFConvertToSwf(string pdfPath, string swfPath, int page)
{
StringBuilder sb = new StringBuilder();
sb.Append(" \"" + pdfPath + "\"");
sb.Append(" -o \"" + swfPath + "\"");
sb.Append(" -z");
//flash version
sb.Append(" -s flashversion=9");
//禁止PDF里面的鏈接
sb.Append(" -s disablelinks");
//PDF頁數
sb.Append(" -p " + "\"1" + "-" + page + "\"");
//SWF中的圖片質量
sb.Append(" -j 100");
string command = sb.ToString();
System.Diagnostics.Process p = null;
try
{
using (p = new System.Diagnostics.Process())
{
p.StartInfo.FileName = _EXEFILENAME;
p.StartInfo.Arguments = command;
p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(_EXEFILENAME);
//不使用操作系統外殼程序 啟動 線程
p.StartInfo.UseShellExecute = false;
//p.StartInfo.RedirectStandardInput = true;
//p.StartInfo.RedirectStandardOutput = true;
//把外部程序錯誤輸出寫到StandardError流中(pdf2swf.exe的所有輸出信息,都為錯誤輸出流,用 StandardOutput是捕獲不到任何消息的...
p.StartInfo.RedirectStandardError = true;
//不創建進程窗口
p.StartInfo.CreateNoWindow = false;
//啟動進程
p.Start();
//開始異步讀取
p.BeginErrorReadLine();
//等待完成
p.WaitForExit();
}
}
catch (Exception ex)
{
Souxuexiao.API.Logger.error(string.Format("轉換PDF文件為SWF格式執行PDFConvertToSwf函數發生異常原因是:{0}", ex.Message));
}
finally
{
if (p != null)
{
//關閉進程
p.Close();
//釋放資源
p.Dispose();
}
}
return File.Exists(swfPath);
}
#endregion
}
}
Office格式轉換
3、將pdf文件轉swf的轉換器放到站點根目錄下新建文件夾pdf2swf(我就是這么配置的,您隨意)
4、配置FlexPaper
預覽頁面引用
分享:delphi選擇文件夾例子所需單元 示例代碼
- 相關鏈接:
- 教程說明:
.Net教程-.NET實現在網頁中預覽Office文件的3個方法(4)
。