查资料看了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. [SQL] SQL 基础知识梳理(一)- 数据库与 SQL

    SQL 基础知识梳理(一)- 数据库与 SQL [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5902856.html 目录 What's 数据库 ...

  2. 日常css技巧小结(2)-- inline-block带来的迷惑

    一.问题描述 在平时布局中,inline-block使用的频率比很高,主要是因为可以让行标签设置宽高.我在布局过程中,发现了两个“问题”, 1行标签.display:inline-block之后的行标 ...

  3. (福利)分享一个用android编写的简单的APP——爱吖天气

    这是本人随便编写的一个天气的APP,超级简单. 项目已同步至:https://github.com/nanchen2251/AiYaWeatherDemo 基本实现了天气查看,闪屏引导,天气基本信息, ...

  4. 关于png、jpg、gif切图时的使用感悟

    关于png.jpg.gif切图时的使用感悟 曾经切图时都是一股脑所有图全切成jpg格式,最近突然心血来潮简单的研究了下其他图片格式的具体属性,才突然发现走了不少弯路,并没有做到使图片用最小体积展现出最 ...

  5. 2.JAVA之GUI编程布局

    布局管理器 容器中的组件排放方式,就是布局 常见的布局管理器: **************************************************** 1.FlowLayout(流式 ...

  6. 用python实现最长公共子序列算法(找到所有最长公共子串)

    软件安全的一个小实验,正好复习一下LCS的写法. 实现LCS的算法和算法导论上的方式基本一致,都是先建好两个表,一个存储在(i,j)处当前最长公共子序列长度,另一个存储在(i,j)处的回溯方向. 相对 ...

  7. 在线课程笔记—.NET基础

    关于学习北京理工大学金旭亮老师在线课程的笔记. 介绍: 在线课程网址:http://mooc.study.163.com/university/BIT#/c 老师个人网站:http://jinxuli ...

  8. 在Application_Error事件中获取当前的Action和Control

    ASP.NET MVC程序处理异常时,方法有很多,网上也有列举了6种,下面是使用全局处理在Global.asax文件的Application_Error事件中实现.既然是ASP.NET MVC,我需要 ...

  9. 搭建公司内部的NuGet Server

    随着公司业务慢慢的拓展,项目便会越来越来多,很多项目会依赖其他项目DLL,比如一些底层的技术框架DLL引用,还有各业务系统的也有可能会有引用的可能. 项目多,交叉引用多,如果要是有一个DLL更新,那就 ...

  10. 【转】Django Model field reference学习总结

    Django Model field reference学习总结(一) 本文档包含所有字段选项(field options)的内部细节和Django已经提供的field types. Field 选项 ...