asp.net 页面打开PDF 浏览器无法直接查看pdf和office文件,这种文件一般都是先转换为swf,再使用falsh播放器进行播放。中间的过程就是PDF(或office文件)-》swf文件-》在页面播放。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 PDF转SWF 在页面查看。 pdf2swf using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.IO;using System.Text; public class toSwf { private void Exec(string arguments, string exePath) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = exePath; proc.StartInfo.Arguments = arguments; proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc.Start(); proc.WaitForExit(); proc.Close(); } /// <summary> /// 返回页数 /// </summary> /// <param name="pdfPath">PDF文件地址</param> public int GetPageCount(string pdfPath) { try { byte[] buffer = File.ReadAllBytes(pdfPath); int length = buffer.Length; if (buffer == null) return -1; if (buffer.Length <= 0) return -1; string pdfText = Encoding.Default.GetString(buffer); System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]"); System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText); return matches.Count; } catch (Exception ex) { throw ex; } } /// <summary> /// 将PDF转换为SWF文件 /// </summary> /// <param name="pdfPath">PDF文件路径</param> /// <param name="swfPath">SWF文件路径</param> /// <param name="page"></param> public void ConvertToSwf(string pdfPath, string swfPath, int page) { try { string pdf2swf_exe = @"C:\Program Files (x86)\SWFTools\pdf2swf.exe"; string swfcombine_exe = @"C:\Program Files (x86)\SWFTools\swfcombine.exe"; if (!File.Exists(pdf2swf_exe)) { throw new ApplicationException("Can not find: " + pdf2swf_exe); } StringBuilder sb = new StringBuilder(); sb.Append(" -o \"" + swfPath + "\"");//output sb.Append(" -z"); sb.Append(" -T 9");//flash version sb.Append(" -s disablelinks");//禁止PDF里面的链接 sb.Append(" -p " + "1" + "-" + page);//page range sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85) sb.Append(" \"" + pdfPath + "\"");//input //执行swf转换 this.Exec(sb.ToString(),pdf2swf_exe); string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf"; string arguments = string.Format("\"{0}\" viewport={1} -o {2}", rfxview, swfPath, swfPath); this.Exec(arguments, swfcombine_exe); } catch (Exception ex) { throw ex; } } } 然后调用ConvertToSwf方法。 把相应的参数传进去,执行就OK了。 还要下载安装pdf2swf这个软件的。 现在的浏览器基本都支持在线浏览,但是首先的装adobe 第一 :执行了之后会不会再我写的目录下创建一个swf 的文件呢第二: string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf"; 这个需要修改成我的哪个文件吗 string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf"; 在你的安装目录找。 /// <summary> /// 将PDF转换为SWF文件 /// </summary> /// <param name="pdfPath">PDF文件路径</param> /// <param name="swfPath">SWF文件路径</param> /// <param name="page"></param> public void ConvertToSwf(string pdfPath, string swfPath, int page) 你看看这个上面的注释啊! toSwf ts = new toSwf(); //将其转换为SWF格式 ts.ConvertToSwf(pdf文件路径, SWF文件路径 + ".swf", ts.GetPageCount(pdf文件路径)); C# 关于BCD码的问题 .net生成execl 单元格合并后赋值问题,请各位大侠指点! 草鸟级问题:函数调用,参数传递! visual studio 2010新建项目是出现问题。 键盘问题急急急! 自动保存文本框到数据库的问题 wpf datagrid间隔色+IsMouseOver触发器变色无效 大家帮我解释这段代码是什么意思??? 求教一个算法:如何识别封闭的区域 请问如何实现程序之间的通讯。 程序用.net reactor加密后使用ReportViewer程序自动关闭 如何将图片存入SQL server数据库,然后用C#查找数据库中的图片
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text; public class toSwf
{
private void Exec(string arguments, string exePath)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = exePath;
proc.StartInfo.Arguments = arguments;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
proc.Close();
} /// <summary>
/// 返回页数
/// </summary>
/// <param name="pdfPath">PDF文件地址</param>
public int GetPageCount(string pdfPath)
{
try
{
byte[] buffer = File.ReadAllBytes(pdfPath);
int length = buffer.Length;
if (buffer == null)
return -1;
if (buffer.Length <= 0)
return -1;
string pdfText = Encoding.Default.GetString(buffer);
System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");
System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);
return matches.Count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 将PDF转换为SWF文件
/// </summary>
/// <param name="pdfPath">PDF文件路径</param>
/// <param name="swfPath">SWF文件路径</param>
/// <param name="page"></param>
public void ConvertToSwf(string pdfPath, string swfPath, int page)
{
try
{
string pdf2swf_exe = @"C:\Program Files (x86)\SWFTools\pdf2swf.exe";
string swfcombine_exe = @"C:\Program Files (x86)\SWFTools\swfcombine.exe"; if (!File.Exists(pdf2swf_exe))
{
throw new ApplicationException("Can not find: " + pdf2swf_exe);
} StringBuilder sb = new StringBuilder();
sb.Append(" -o \"" + swfPath + "\"");//output
sb.Append(" -z");
sb.Append(" -T 9");//flash version
sb.Append(" -s disablelinks");//禁止PDF里面的链接
sb.Append(" -p " + "1" + "-" + page);//page range
sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
sb.Append(" \"" + pdfPath + "\"");//input //执行swf转换
this.Exec(sb.ToString(),pdf2swf_exe); string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf";
string arguments = string.Format("\"{0}\" viewport={1} -o {2}", rfxview, swfPath, swfPath);
this.Exec(arguments, swfcombine_exe); }
catch (Exception ex)
{
throw ex;
}
}
}
第二: string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf"; 这个需要修改成我的哪个文件吗
/// 将PDF转换为SWF文件
/// </summary>
/// <param name="pdfPath">PDF文件路径</param>
/// <param name="swfPath">SWF文件路径</param>
/// <param name="page"></param>
public void ConvertToSwf(string pdfPath, string swfPath, int page)
你看看这个上面的注释啊!
//将其转换为SWF格式
ts.ConvertToSwf(pdf文件路径, SWF文件路径 + ".swf", ts.GetPageCount(pdf文件路径));