查资料看了2种解决方法:

1.通过办公软件dll转换,用flans去看

2.通过Aspose转换成pdf格式,在用js前台读pdf(我用的pdf.js)

今天我解决的就是WORD/EXCEL/PPT 转化成 PDF ,然后 PDF在线阅读

1.WORD/PPT/EXCEL转PPT类(很简单的)

using Aspose.Words;
using Aspose.Cells;
using Aspose.Slides; /// <summary>
/// Office2Pdf 将Office文档转化为pdf
/// </summary>
public class Office2Pdf
{
public Office2Pdf()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// Word转换成pdf
/// </summary>
/// <param name="sourcePath">源文件路径</param>
/// <param name="targetPath">目标文件路径</param>
/// <returns>true=转换成功</returns>
public bool DOCConvertToPDF(string sourcePath, string targetPath)
{
bool result = false;
try
{
Document doc = new Document(sourcePath);
doc.Save(targetPath, Aspose.Words.SaveFormat.Pdf);
result = true;
}
catch
{
result = false;
}
finally
{
}
return result;
} /// <summary>
/// 把Excel文件转换成PDF格式文件
/// </summary>
/// <param name="sourcePath">源文件路径</param>
/// <param name="targetPath">目标文件路径</param>
/// <returns>true=转换成功</returns>
public bool XLSConvertToPDF(string sourcePath, string targetPath)
{
bool result = false; try
{
//Excel
Workbook excel = new Workbook(sourcePath);
excel.Save(targetPath, Aspose.Cells.SaveFormat.Pdf);
result = true;
}
catch
{
result = false;
}
finally
{ }
return result;
}
///<summary>
/// 把PowerPoint文件转换成PDF格式文件
///</summary>
///<param name="sourcePath">源文件路径</param>
///<param name="targetPath">目标文件路径</param>
///<returns>true=转换成功</returns>
public bool PPTConvertToPDF(string sourcePath, string targetPath)
{
bool result;
try
{
//PPT
Presentation ppt = new Presentation(sourcePath);
ppt.Save(targetPath, Aspose.Slides.Export.SaveFormat.Pdf);
result = true;
}
catch
{
result = false;
}
finally
{
}
return result;
}
}

2.做一个上传页面(核心代码)

        private string upFile()
{
int iTotal = Request.Files.Count; if (iTotal == )
{
_msg = "没有数据";
}
else
{
HttpPostedFile file = Request.Files[];
string path = "file\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
string viewPath = "PDF\\web\\" + path;
string ArticlePath = System.Web.HttpContext.Current.Server.MapPath("~") + viewPath;
if (file.ContentLength > || !string.IsNullOrEmpty(file.FileName))
{
//建立图片主文件夹
if (!Directory.Exists(ArticlePath))
{
Directory.CreateDirectory(ArticlePath);
}
saveName = Path.GetFileName(file.FileName);
string extension = Path.GetExtension(file.FileName).ToLower();
string fileName = DateTime.Now.ToString("HH-mm-ss") + extension;
ArticlePath += fileName;
//保存文件
file.SaveAs(ArticlePath);
string pdfpath = ArticlePath.Substring(, ArticlePath.Length - extension.Length) + ".pdf";
if (extension == ".doc" || extension == ".docx")
{
office2pdf.DOCConvertToPDF(ArticlePath, pdfpath);
}
else if (extension == ".ppt" || extension == ".pptx")
{
office2pdf.PPTConvertToPDF(ArticlePath, pdfpath);
}
else if (extension == ".xls" || extension == ".xlsx")
{
office2pdf.XLSConvertToPDF(ArticlePath, pdfpath);
}
else if (extension == ".pdf")
{
}
else
{
this.RegisterStartupScript("newWindow", "<script language='javascript'>alert('非法文件!')</script>");
return "";
}
DelFile(ArticlePath);
savePath = path + fileName.Substring(, fileName.Length - extension.Length) + ".pdf";
return savePath;
}
}
return ""; }

3.效果如下

PPT    :

WORD:

4. DEMO: 下载 (新手上路,希望大家多多指点  )

PDF/WORD/EXCEL/PPT 文档在线阅读的更多相关文章

  1. Java实现在线预览Word,Excel,Ppt文档

    效果图:

  2. word&excel&ppt文档加密方式

    ppt excel word

  3. 在线预览-Java 使用 Print2Flash 实现Office文档在线阅读

    近期项目上遇到一个需求是用户上传的文档进行在线浏览,之前有过一篇使用 OpenOffice 将 word 转换成 html 页面进行展示的.现在介绍一个新的工具那就是 Print2Flash .    ...

  4. pdf word excel ppt 在线预览方案收集

    https://www.idocv.com/docs.html http://www.cnblogs.com/wolf-sun/p/3569960.html http://coolwanglu.git ...

  5. 巧用数据流让 Word 文档在线阅读

            常常写博客或空间日记的朋友,对网络编辑器(如图1,是CSDN的博客编辑器)并不陌生.也比較easy做出非常绚烂的排版.但这次在做一个BS的项目,客户一直在用Office的软件中的Wor ...

  6. winform显示word和ppt文档

    最近所做的项目中需要在Winform窗体中显示Office文档.刚开始就使用webBrowser控件实现的,但是后来发现这个控件在显示Office文档的时候有个限制:只支持Office2003之前的版 ...

  7. asp.net 文件下载(txt,rar,pdf,word,excel,ppt)

    aspx 文件下载说起来一点都不难,但是在做的过程中还是遇到了一些小小的问题,就是因为这些小小的问题,导致解决起来实在是太难了,其中一个就是Response.End();导致下载文件出现线程终止的情况 ...

  8. flexPaper +swftools实现文档在线阅读

    网上已有很多FlexPaper仿百度文库的一些文章,园子里也有很多大牛的详细教程. 结合这次做的例子,在这里详细记录一下使用Flexpaper实现仿百度文库的效果,及自己在跟着园子里的教程做的时候,遇 ...

  9. 用R创建Word和PowerPoint文档--转载

    https://www.jianshu.com/p/7df62865c3ed Rapp --简书 Microsoft的Office软件在办公软件领域占有绝对的主导地位,几乎每个职场人士都必须掌握Wor ...

随机推荐

  1. SpringMVC一路总结(一)

    SpringMVC听闻已久,早在去年就被学长问到关于SpringMVC的基础知识,当时也没在意.主要是工作中也没有用到关于SpringMVC的技术,因此免于没有时间和精力的借口就没有接触和学习Spri ...

  2. 【分布式】Zookeeper使用--命令行

    一.前言 在学习了Zookeeper相关的理论知识后,下面接着学习对Zookeeper的相关操作. 二.Zookeeper部署 Zookeeper的部署相对来说还是比较简单,读者可以在网上找到相应的教 ...

  3. 自己动手之使用反射和泛型,动态读取XML创建类实例并赋值

    前言: 最近小匹夫参与的游戏项目到了需要读取数据的阶段了,那么觉得自己业余时间也该实践下数据相关的内容.那么从哪入手呢?因为用的是Unity3d的游戏引擎,思来想去就选择了C#读取XML文件这个小功能 ...

  4. 没有神话,聊聊decimal的“障眼法”

    0x00 前言 在上一篇文章<妥协与取舍,解构C#中的小数运算>的留言区域有很多朋友都不约而同的说道了C#中的decimal类型.事实上之前的那篇文章的立意主要在于聊聊使用二进制的计算机是 ...

  5. linux内核数据结构之kfifo

    1.前言 最近项目中用到一个环形缓冲区(ring buffer),代码是由linux内核的kfifo改过来的.缓冲区在文件系统中经常用到,通过缓冲区缓解cpu读写内存和读写磁盘的速度.例如一个进程A产 ...

  6. [Spring]支持注解的Spring调度器

    概述 如果想在Spring中使用任务调度功能,除了集成调度框架Quartz这种方式,也可以使用Spring自己的调度任务框架. 使用Spring的调度框架,优点是:支持注解(@Scheduler),可 ...

  7. DropDownList实现可输入可选择

    1.js版本 <div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); positio ...

  8. LINQ to SQL语句(6)之Group By/Having

    适用场景:分组数据,为我们查找数据缩小范围. 说明:分配并返回对传入参数进行分组操作后的可枚举对象.分组:延迟 1.简单形式: var q = from p in db.Products group ...

  9. C# - 多线程 之 异步编程

    异步编程 同步编程,请求响应模型,同步化.顺序化.事务化. 异步编程,事件驱动模型,以 Fire and Forget 方式实现. 异步编程模式  -§- 异步编程模型 (APM) 模式: IAsyn ...

  10. C# 高效编程笔记2

    C# 高效编程笔记2 1.理解GetHashCode()的陷阱 (1)作用:作为基于散列集合定义键的散列值,如:HashSet<T>,Dictionary<K,V>容器等 (2 ...