当我下载pdf时,文件名将以“响应”的形式显示,同时保存在特定位置,如果我要更改文件的名称,则它将如下图所示。
当我选择相同的默认名称时,它就会完美无缺。
是否可以将名称设置为用户定义。 我正在使用的代码是:
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=filename.pdf");
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
string pdfFilePath = HttpContext.Current.Server.MapPath(".") + "/PDFFiles";
HTMLWorker htmlparser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, HttpContext.Current.Response.OutputStream);
doc.Open();
try
{
doc.Add(new Paragraph("Test PDF Download"));
doc.Close();
HttpContext.Current.Response.Write(doc);
HttpContext.Current.Response.End();
}
catch (Exception ex)
{ }
finally
{
doc.Close();
}