服务器端提供pdf文件下载,非直接访问模式
文件上传到内网,但对外网提供文件下载,不允许外网直接输入路径访问,但PDF怎样实现下载,现在代码如下
第一个doc能够实现下载,docx未能完全实现,第二个pdf解析出来总是中文乱码请求大神怎样才能实现下载,尝试过试用Itestsharp、Acrobat.dll等,最好在我基础上写上源码
object content = string.Empty;
string commandArgument = e.CommandArgument.ToString();
string filePath = commandArgument;
string fileext = System.IO.Path.GetExtension(filePath);
string contentType = string.Empty;
if (fileext == ".doc" || fileext == ".docx")
{
_Application myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
_Document myWordDoc;
contentType = "application/msword";
myWordDoc = myWordApp.Documents.Open(Constant.GetInnerFileServerPath() + filePath);
content = myWordDoc.Content.Text;
myWordDoc.Close();
myWordApp.Quit();
}
else if (fileext == ".pdf")
{
StreamReader sr = null;
Stream ostream = HttpWebResponseUtility.CreateGetHttpResponse(Constant.GetInnerFileServerPath() + filePath, 2000, null, null).GetResponseStream();
sr = new StreamReader(ostream, System.Text.Encoding.UTF8);
string strContent= sr.ReadToEnd();
content = strContent;
contentType = "application/pdf";
}
Response.AppendHeader("Connection", "close");
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(System.IO.Path.GetFileName(filePath), System.Text.Encoding.UTF8));
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = contentType;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(content);
Response.Flush();
Response.End();第一个doc能够实现下载,docx未能完全实现,第二个pdf解析出来总是中文乱码请求大神怎样才能实现下载,尝试过试用Itestsharp、Acrobat.dll等,最好在我基础上写上源码
...全文
相关推荐
基于WinViewer实现office文件,pdf文件,图片,txt文档在线预览,支持打开服务器端文件
基于WinViewer实现office文件,pdf文件,图片,txt文档在线预览,支持打开服务器端文件,ftp上的文件
直接下载pdf文件
php语言直接下载pdf文件 很方便好用的代码
Nginx配置txt、pdf、doc、xls等文件直接下载的方法
主要介绍了Nginx配置txt、pdf、doc、xls等文件直接下载的方法,配置方法很简单,本文直接给出配置示例,需要的朋友可以参考下
php使浏览器直接下载pdf文件的方法
本文介绍如何让用户打开pdf文件时不是直接在浏览器浏览而是直接以下载文件形式把pdf文件下载到电脑
调用URL下载并显示PDF文件
通过URL下载PDF文件并调用PDF阅读器显示 以及通过WEBVIEW 显示PDF 文件


