如何使用flexpaper+swftools大文件分页转换实现在线预览
展开全部
修改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配置信息:
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 };
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配置信息:
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 };
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询