导出为pdf |如何显示打开和保存选项

时间:2014-04-10 17:25:27

标签: c# .net pdf export export-to-pdf

我有这个用于导出为pdf的工作代码。当我导出它时,它会询问我保存文件的位置。相反,我想要选择OPEN或SAVE。目前我在做的是:

protected void btnPdf_Click(object sender, EventArgs e)
{

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView2.AllowPaging = false;
    GridView2.DataBind();
    GridView2.RenderControl(hw);
    GridView2.HeaderRow.Style.Add("width", "15%");
    GridView2.HeaderRow.Style.Add("font-size", "10px");
    GridView2.Style.Add("text-decoration", "none");
    GridView2.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView2.Style.Add("font-size", "8px");
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();
}

1 个答案:

答案 0 :(得分:0)

如果您在服务器上有该文件

Response.TransmitFile(//FILE PATH);

如果你不

Response.BinaryWrite(//Pass Byte Array)