Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 06, 2011 03:21 AM by rupertnishanth
May 05, 2008 12:58 AM|LINK
Does anyone know a good way to convert an aspx page to a pdf document?
I have been playing around with iTextSharp but I can't find anything that would do that.
May 05, 2008 01:29 AM|LINK
These are two ways to do it, I hope one can help you.
May 05, 2008 01:48 AM|LINK
So basically, based on the first link, you're creating the pdf file but where in your code snippet is the page being rendered as pdf?
Is that where you're adding to the headers?
Forgive my ignorance but I'm a bit confused by it.
May 05, 2008 02:00 AM|LINK
yes you are correct, whatever is displayed on the HTML will be on the PDF, you got it.
May 05, 2008 02:16 AM|LINK
It appears to be working accept i'm getting an error when I try to open the file saying the file isn't in the proper format or it has been damaged (if sent in an email as an attachment).
Any ideas as to the cause of this?
May 05, 2008 02:23 AM|LINK
Please paste the error and the file produced, what extension it is? 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.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).
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 ( );
May 05, 2008 02:53 AM|LINK
Clear all headers before creating the file
Let me know if that helps
May 05, 2008 03:00 AM|LINK
Nope same thing.
May 07, 2008 05:01 PM|LINK