PDF/WORD/EXCEL/PPT 文档在线阅读
查资料看了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 文档在线阅读的更多相关文章
- Java实现在线预览Word,Excel,Ppt文档
效果图:
- word&excel&ppt文档加密方式
ppt excel word
- 在线预览-Java 使用 Print2Flash 实现Office文档在线阅读
近期项目上遇到一个需求是用户上传的文档进行在线浏览,之前有过一篇使用 OpenOffice 将 word 转换成 html 页面进行展示的.现在介绍一个新的工具那就是 Print2Flash . ...
- pdf word excel ppt 在线预览方案收集
https://www.idocv.com/docs.html http://www.cnblogs.com/wolf-sun/p/3569960.html http://coolwanglu.git ...
- 巧用数据流让 Word 文档在线阅读
常常写博客或空间日记的朋友,对网络编辑器(如图1,是CSDN的博客编辑器)并不陌生.也比較easy做出非常绚烂的排版.但这次在做一个BS的项目,客户一直在用Office的软件中的Wor ...
- winform显示word和ppt文档
最近所做的项目中需要在Winform窗体中显示Office文档.刚开始就使用webBrowser控件实现的,但是后来发现这个控件在显示Office文档的时候有个限制:只支持Office2003之前的版 ...
- asp.net 文件下载(txt,rar,pdf,word,excel,ppt)
aspx 文件下载说起来一点都不难,但是在做的过程中还是遇到了一些小小的问题,就是因为这些小小的问题,导致解决起来实在是太难了,其中一个就是Response.End();导致下载文件出现线程终止的情况 ...
- flexPaper +swftools实现文档在线阅读
网上已有很多FlexPaper仿百度文库的一些文章,园子里也有很多大牛的详细教程. 结合这次做的例子,在这里详细记录一下使用Flexpaper实现仿百度文库的效果,及自己在跟着园子里的教程做的时候,遇 ...
- 用R创建Word和PowerPoint文档--转载
https://www.jianshu.com/p/7df62865c3ed Rapp --简书 Microsoft的Office软件在办公软件领域占有绝对的主导地位,几乎每个职场人士都必须掌握Wor ...
随机推荐
- 4. ValueStack 和 OGNL
1. 属性哪来的 当我们通过Action处理完用户请求以后,可以直接在页面中获取到 action 的属性值. 如果我们在页面中尝试遍历四个域中的属性,会发现域中并没有username之类的Action ...
- SQL Tuning 基础概述02 - Explain plan的使用
1.explain plan的使用 SQL> explain plan for delete from t_jingyu; Explained. SQL> select * from ta ...
- 自己封装了一个EF的上下文类.,分享一下,顺便求大神指点
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- xmpp
xmpp学习 下载: Openfire 服务器:Openfire 4.0.2 客户端:Spark 2.7.7 安装 Openfire安装: 根据提示一直下一步,服务器域名设置为:localhost(p ...
- C#开发微信门户及应用(17)-微信企业号的通讯录管理开发之部门管理
前面一篇随笔企业号的一些基础信息,以及介绍如何配置企业号的回调方式实现和企业号服务器进行沟通的桥梁.本篇主要还是继续介绍企业号的开发工作的开展,介绍微信企业号通讯录管理开发功能,介绍其中组织机构里面如 ...
- JavaWeb_day03_员工信息添加修改删除
day03员工的添加,修改,删除 修改功能 思路 : 点击修改员工数据之后,跳转到单行文本,查询要修改的员工id的全部信息,主键id设置为readonly,其余的都可以修改, 修改之后,提交按钮,提交 ...
- 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容
我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...
- 每天一个设计模式-4 单例模式(Singleton)
每天一个设计模式-4 单例模式(Singleton) 1.实际生活的例子 有一天,你的自行车的某个螺丝钉松了,修车铺离你家比较远,而附近的五金店有卖扳手:因此,你决定去五金店买一个扳手,自己把螺丝钉固 ...
- Spring 4 + Quartz 2.2.1 Scheduler Integration Example
In this post we will see how to schedule Jobs using Quartz Scheduler with Spring. Spring provides co ...
- 深入学习jQuery选择器系列第一篇——基础选择器和层级选择器
× 目录 [1]id选择器 [2]元素选择器 [3]类选择器[4]通配选择器[5]群组选择器[6]后代选择器[7]兄弟选择器 前面的话 选择器是jQuery的根基,在jQuery中,对事件处理.遍历D ...