我正在嘗試生成並下載PDF文件。它一直說文件類型錯誤或文件被損壞。ASP.Net C#生成並下載PDF文件
這裏是我的代碼的幫助
protected void downloadFile(int index)
{
string strContent = "<html> <body> <div> <b> Tjeu! </b> </div> <div> <INPUT TYPE=CHECKBOX NAME=\"maillist\" disabled=\"disabled\">Yes! Put me on the list! </div> </body> </html>";
string attach = "attachment; filename=wordtest.pdf";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = System.Net.Mime.MediaTypeNames.Application.Pdf;
HttpContext.Current.Response.AddHeader("content-disposition", attach);
HttpContext.Current.Response.Write(strContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}
THX)
當你用記事本打開現有的PDF文件(比如)你不會看到HTML。將HTML文件重命名爲.PDF不會使其成爲PDF。 – spender 2011-04-25 13:35:19