Question

Locked

How to convert .aspx page to .pdf at runtime

By tuse19 ·
hi,

i am using an .aspx page where i will generate some result with gridview, tables and images. i want to send this page as .pdf attachment with email to some user.

is there any FREE/OPENSOURCE tool in ASP.NET, C# to convert .aspx page to .pdf format?

Please help, it is very urgent....

Thanks

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

How to convert .aspx page to .pdf at runtime

by pn2online In reply to How to convert .aspx page ...

hello,
Have you get any idea on a same post, i too have to implement same in my project.

Let me know if you have any idea.

Collapse -

CutePDF

by dearrohit In reply to How to convert .aspx page ...

I am not sure if this would answer your issue. Install Ghostscript and CutePDF from the below link. http://www.cutepdf.com/Products/CutePDF/writer.asp

Print from your browser and select CutePDF Writer. This will create a PDF of any type of page.

Please go through the web page before installation.

Collapse -

Hiiiiii......

by koras111 In reply to How to convert .aspx page ...

Ok dear I will inform u........

Collapse -

iTextSharp

by giri128 In reply to Hiiiiii......

U can use iTextSharp..
an open source

Collapse -

convert aspx to pdf

by ankit In reply to How to convert .aspx page ...

using iTextSharp
dll
here is code------------
protected void btn_PDF_Click(object sender, EventArgs e)
{
Uri strurl = Request.Url;
string url = strurl.ToString();
string text = GetPageText(url);
string filepath = Server.MapPath("image\\test.htm"); //"c:\\test.htm";
StreamWriter writer = new StreamWriter(filepath);
writer.Write(text);
writer.Close();

htmltopdf();
}

public string GetPageText(string url)
{
string htmlText = string.Empty;
string FILE_NAME = Server.MapPath("image\\test.xml"); //"c:\\test.xml";

try
{

HttpWebRequest requestIP = (HttpWebRequest)WebRequest.Create(url);
requestIP.Timeout = 10000;
using (HttpWebResponse responseIP = (HttpWebResponse)requestIP.GetResponse())
{
using (Stream streamIP = responseIP.GetResponseStream())
{
using (StreamReader readerText = new StreamReader(streamIP))
{
htmlText = readerText.ReadToEnd();
string text = htmlText;

StreamWriter writer = new StreamWriter( FILE_NAME);
writer.Write(text);
writer.Close();
}
}
}
}
finally
{
}
return htmlText;
}


public void htmltopdf()
{
Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("image\\test.pdf"), System.IO.FileMode.Create));

HtmlParser.Parse(doc, Server.MapPath("image\\test.htm"));
//XmlParser.Parse(doc, Server.MapPath("image\\test.xml"));
//ITextHandler h = new ITextHandler(doc, new TagMap("c:\\test.xml"));
//h.Parse("c:\\test.xml");

if (File.Exists(Server.MapPath("image\\test.htm")))
File.Delete(Server.MapPath("image\\test.htm"));
if (File.Exists(Server.MapPath("image\\test.xml")))
File.Delete(Server.MapPath("image\\test.xml"));
}

regards,
ANKIT CHAMPANERIYA
(M.SC(IT),MCP,MCTS)
Software Developer
Raj s/w ltd.

Collapse -

worked for me but got a problem.

by ruma.asm In reply to convert aspx to pdf

Hi

i have used this code for converting aspx page to pdf file and pdf was created also but i am not able to open the pdf file.its giving me the error saying:Adobe reader can not open the file because it is either not supported type or the file is damaged.please let me know if you could help me with this.its really urgent.Thanks in advance.

Collapse -

Same Problem.....

by SonaManu In reply to worked for me but got a p ...

Hi All....
Im also facing the same issue as ruma said. If anybody gets a solution please be kind enough to inform us.

Collapse -

convert aspx to pdf page

by ankit In reply to How to convert .aspx page ...

protected void btn_PDF_Click(object sender, EventArgs e)
{
Uri strurl = Request.Url;
string url = strurl.ToString();
string text = GetPageText(url);
string filepath = Server.MapPath("image\\test.htm"); //"c:\\test.htm";
StreamWriter writer = new StreamWriter(filepath);
writer.Write(text);
writer.Close();

htmltopdf();
}

public string GetPageText(string url)
{
string htmlText = string.Empty;
string FILE_NAME = Server.MapPath("image\\test.xml"); //"c:\\test.xml";

try
{

HttpWebRequest requestIP = (HttpWebRequest)WebRequest.Create(url);
requestIP.Timeout = 10000;
using (HttpWebResponse responseIP = (HttpWebResponse)requestIP.GetResponse())
{
using (Stream streamIP = responseIP.GetResponseStream())
{
using (StreamReader readerText = new StreamReader(streamIP))
{
htmlText = readerText.ReadToEnd();
string text = htmlText;

StreamWriter writer = new StreamWriter( FILE_NAME);
writer.Write(text);
writer.Close();
}
}
}
}
finally
{
}
return htmlText;
}


public void htmltopdf()
{
Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("image\\test.pdf"), System.IO.FileMode.Create));

HtmlParser.Parse(doc, Server.MapPath("image\\test.htm"));
//XmlParser.Parse(doc, Server.MapPath("image\\test.xml"));
//ITextHandler h = new ITextHandler(doc, new TagMap("c:\\test.xml"));
//h.Parse("c:\\test.xml");

if (File.Exists(Server.MapPath("image\\test.htm")))
File.Delete(Server.MapPath("image\\test.htm"));
if (File.Exists(Server.MapPath("image\\test.xml")))
File.Delete(Server.MapPath("image\\test.xml"));
}

regards,
ANKIT CHAMPANERIYA
(M.SC(IT),MCP,MCTS)
Raj s/w ltd
Mumbai

Collapse -

to convert xml to pdf

by bhatiaashu In reply to How to convert .aspx page ...

I have used this code to convert xml to pdf. It gives error document has no pages

Back to Web Development Forum
10 total posts (Page 1 of 1)  

Related Discussions

Related Forums