zoukankan
html css js c++ java
输出PDF文档到ASP.NET页面
项目中的WORD报表文档最终会被转换为PDF文档,输出到WEB页面中,下面的代码是读取PDF文件并写入到页面输出流中:
protected
void
Page_Load(
object
sender, EventArgs e)
{
try
{
//
query the pdf path
string
pdfna
=
this
.Request.QueryString[
"
pdf
"
];
if
(pdfna
==
null
)
throw
new
Exception(
"
This page can not be accessed directly
"
);
string
pdf
=
"
Reports\\
"
+
pdfna;
pdf
=
Server.MapPath(pdf);
//
read all bytes
if
(File.Exists(pdf)
==
false
)
throw
new
Exception(
"
This report is not created
"
);
FileStream fs
=
File.Open(pdf, FileMode.Open);
byte
[] buffer
=
new
byte
[fs.Length];
fs.Read(buffer,
0
, buffer.Length);
fs.Close();
//
write to response
Response.ContentType
=
"
application/pdf
"
;
Response.AddHeader(
"
content-disposition
"
,
"
filename=
"
+
pdfna);
Response.AddHeader(
"
content-length
"
, buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
catch
(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
Response.Flush();
Response.Close();
Response.End();
}
}
查看全文
相关阅读:
python基础学习笔记(二)
python基础学习笔记(三)
python基础学习笔记(四)
python基础学习笔记(五)
python基础学习笔记(六)
python基础学习笔记(七)
python基础学习笔记(八)
Spring Boot(五):Spring Boot Jpa 的使用
MySQL优化?
⾏级锁定的优点和缺点:
原文地址:https://www.cnblogs.com/swnuwangyun/p/841786.html
最新文章
nginx反向代理
texlive编译lshort-zh-cn
texlive安装与vscode环境配置
坐标系之前的数据转换(比如3857转4326)
springboot集成websocket实现给单人或多人发送数据
gateway统一验证和解析token设置header
大文件分片上传demo
docker配置桥接模式,外网访问centos容器
PCB画图经验(借鉴别人的)
java异常体系
热门文章
Optional详解
透过“锁”事看InnoDB对并发的处理?
mybatis报错:A query was run and no Result Maps were found for the Mapped Statement
volatile实现之缓存锁定
mybatis格式化异常:NumberFormatException,For input string:"x"
list与数组转换的坑
sql踩过的坑
B tree和B+ tree的区别
【Python学习】函数参数传递方法四种(位置,关键字,默认值,包裹位置,包裹关键字传递)
深入浅出接口测试原理及步骤
Copyright © 2011-2022 走看看