Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > CONVERT an ASPX page to a PDF file with asp.net c#

Reply
Thread Tools

CONVERT an ASPX page to a PDF file with asp.net c#

 
 
Steven
Guest
Posts: n/a
 
      08-27-2003
Hi. I have a dynamic ASPX page written in C# that I want
to turn into a PDF file and store it for records. Please
help, because I am not sure where to start. Thank you.
 
Reply With Quote
 
 
 
 
Lucas Tam
Guest
Posts: n/a
 
      08-27-2003
"Steven" <(E-Mail Removed)> wrote in news:0d1201c36c99$a75e7f50
$(E-Mail Removed):

> Hi. I have a dynamic ASPX page written in C# that I want
> to turn into a PDF file and store it for records. Please
> help, because I am not sure where to start. Thank you.



ActivePDF has components which can generate ASPX pgaes.

Pricy tho.

--
Lucas Tam ((E-Mail Removed))
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
 
 
 
florentin
Guest
Posts: n/a
 
      05-30-2007
Hi,

Here is a .NET tool that does exactly what you need:
http://www.html-to-pdf.ne

From http://www.developmentnow.com/g/8_20...h-asp-net-c.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
Reply With Quote
 
cmrhema cmrhema is offline
Junior Member
Join Date: Aug 2007
Posts: 2
 
      05-14-2008
I tried but it does not work when there are images inside the aspx page
 
Reply With Quote
 
ankit@rajinfo.com ankit@rajinfo.com is offline
Junior Member
Join Date: Dec 2008
Posts: 3
 
      12-26-2008
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
Mumbai
 
Reply With Quote
 
karabrigham karabrigham is offline
Junior Member
Join Date: Nov 2008
Posts: 5
 
      03-07-2009
There is an .net library that exports data to a pdf using .net. but I don't think it supports images.
datatopdf.com
 
Reply With Quote
 
nidhindask88 nidhindask88 is offline
Junior Member
Join Date: Jul 2011
Posts: 1
 
      07-19-2011
First add reference to your application (itextsharp.dll)

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

// Type this code on button's click

protected void ImgBtnExport_Click(object sender, ImageClickEventArgs e)
{
string filename=txtReportName.text;
string attachment = "attachment; filename=" + filename+ ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
htextw.AddStyleAttribute("font-size", "7pt");
htextw.AddStyleAttribute("color", "Black");

Panel_Name.RenderControl(htextw);//Name of the Panel
Document document = new Document();
document = new Document(PageSize.A4, 5, 5, 15, 5);
FontFactory.GetFont("Arial", 50, iTextSharp.text.BaseColor.BLUE);
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();

StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);

document.Close();
Response.Write(document);
}

//Paste this code some where on page

public override void VerifyRenderingInServerForm(Control control)
{

}

Regards
Nidhin Das K (Assyst International).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASPX page to PDF convert anandvak Software 0 11-04-2009 05:13 AM
export aspx page to word format or pdf format as it is display in aspx page getmeaditi Software 0 03-10-2009 07:15 AM
PDF::Writer, create pdf and insert in other pdf file. Ricardo Pog Ruby 1 03-26-2008 08:24 PM
How to convert .aspx page to .pdf at runtime =?Utf-8?B?U3RlcGhhbmU=?= ASP .Net 3 05-24-2007 09:37 PM
Syntax for call from aspx page to .cs file then to different aspx page MadHatter51 ASP .Net 1 05-17-2006 10:43 AM



Advertisments