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.
Any thoughts?
If everything happens for a reason what is the reason for this error?
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.
If everything happens for a reason what is the reason for this error?
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?
If everything happens for a reason what is the reason for this error?
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
Best way to convert an aspx page to pdf
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.
Any thoughts?
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: Best way to convert an aspx page to pdf
May 05, 2008 01:29 AM|LINK
These are two ways to do it, I hope one can help you.
http://alpascual.com/blog/al/archive/2006/11/04/How-to-create-a-PDF-File-in-C_2300_.aspx
http://alpascual.com/blog/al/archive/2006/11/03/How-to-create-a-PDF-from-HTML.aspx
Al
My Blog
mpaterson
Contributor
4619 Points
1316 Posts
Re: Best way to convert an aspx page to pdf
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.
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: Best way to convert an aspx page to pdf
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.
Al
My Blog
mpaterson
Contributor
4619 Points
1316 Posts
Re: Best way to convert an aspx page to pdf
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?
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: Best way to convert an aspx page to pdf
May 05, 2008 02:23 AM|LINK
Please paste the error and the file produced, what extension it is? pdf?
Al
My Blog
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 ( );albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: Best way to convert an aspx page to pdf
May 05, 2008 02:53 AM|LINK
Clear all headers before creating the file
Response.ClearHeaders()
Let me know if that helps
Al
My Blog
mpaterson
Contributor
4619 Points
1316 Posts
Re: Best way to convert an aspx page to pdf
May 05, 2008 03:00 AM|LINK
Nope same thing.
mpaterson
Contributor
4619 Points
1316 Posts
Re: Best way to convert an aspx page to pdf
May 07, 2008 05:01 PM|LINK
Any ideas?