【发布时间】:2016-05-09 05:08:03
【问题描述】:
我正在我的项目中创建一个 pdf 文件。PDF 生成工作正常。创建后,它会在浏览器中打开,但是当我点击保存链接时,它会提示保存整个页面而不是 pdf 文件。可以一个帮帮我好吗? 这是我的代码:
protected void btn_ViewSlip_Click(object sender, EventArgs e)
{
dt_Payslip = mm_salary.GetPayslipData(DDL_Year.SelectedValue.ToString(), DDL_Month.SelectedValue.ToString(), Session["empcd"].ToString());
if (dt_Payslip.Rows.Count > 0)
{
dt_CurrPay = emp_coprofile.GetCurrExp(Session["empcd"].ToString(), DDL_Month.SelectedValue.ToString(), DDL_Year.SelectedValue.ToString());
GenerateDisclaimerPDF();//pdf is generating here
string url = FilesPath.Path_SaveFile + Session["empcd"].ToString() + " - Payslip.pdf";
System.IO.FileInfo file = new System.IO.FileInfo(url);
if (file.Exists)
{
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(url);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
else
{
msg = "Pay slip for "+DDL_Month.SelectedValue.ToString()+"-"+DDL_Year.SelectedValue+" does not exist";
}
}
【问题讨论】:
-
你用“保存链接”代码做什么?
-
不,没有任何保存代码,尽管在浏览器中打开任何pdf文件时,浏览器本身都会显示保存、打印等选项
-
你能添加你的输出截图吗?
-
这里没有添加图片的选项
-
编辑您的问题,您将能够添加图片