浏览器无法直接查看pdf和office文件,这种文件一般都是先转换为swf,再使用falsh播放器进行播放。
中间的过程就是PDF(或office文件)-》swf文件-》在页面播放。

解决方案 »

  1.   

    PDF转SWF    在页面查看。     pdf2swf
      

  2.   


    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;
                }
            }
        }
      

  3.   

    然后调用ConvertToSwf方法。  把相应的参数传进去,执行就OK了。
      

  4.   

    还要下载安装pdf2swf这个软件的。
      

  5.   

    现在的浏览器基本都支持在线浏览,但是首先的装adobe
      

  6.   

    第一 :执行了之后会不会再我写的目录下创建一个swf 的文件呢
    第二: string rfxview = @"C:\Program Files (x86)\SWFTools\swfs\rfxview.swf";  这个需要修改成我的哪个文件吗
      

  7.   

     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)
            
    你看看这个上面的注释啊!
      

  8.   

     toSwf ts = new toSwf();
     //将其转换为SWF格式
     ts.ConvertToSwf(pdf文件路径, SWF文件路径 + ".swf", ts.GetPageCount(pdf文件路径));