I don't know how to attach the pdf file that is generated.
The error is being thrown by adobe reader.\
It states : adobe reader could not open 'test[1].pdf' because it is either not supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded).
mpaterson
Contributor
4619 Points
1316 Posts
Re: Best way to convert an aspx page to pdf
May 05, 2008 02:45 AM|LINK
Here is the code.
I don't know how to attach the pdf file that is generated.
The error is being thrown by adobe reader.\
It states : adobe reader could not open 'test[1].pdf' because it is either not supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded).
in page_load
string name = "test.pdf"; FileStream fs = new FileStream ( Server.MapPath("~/") + name, FileMode.Create, FileAccess.Write ); StreamWriter sw = new StreamWriter ( fs, System.Text.Encoding.GetEncoding ( "gb2312" ) ); sw.WriteLine ( "Hello World" ); sw.Close ( ); // If inside of a page: Response.AddHeader ( "Content-Disposition", "attachment; filename=" + Server.UrlEncode ( name ) ); Response.ContentType = "application/pdf"; //Response.AddHeader ( "Content-Type", "binary/octet-stream" ); //Response.AddHeader ( "Content-Disposition", "attachment; filename=" + downloadName + "; size=" + downloadBytes.Length.ToString ( ) ); //Response.Flush ( ); //Response.BinaryWrite ( downloadBytes ); Response.Flush ( ); Response.End ( ); Response.WriteFile ( name ); Response.End ( );