7 Replies - 4445 Views - Last Post: 19 September 2012 - 07:21 AM Rate Topic: -----

#1 visweswaran28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 29-October 09

How to convert current aspx content to pdf

Posted 03 June 2010 - 12:02 AM

Hi,

I have aspx page in which I loaded tables and other info dynamically, now i want to convert this current page content into pdf, is it possible..
Is This A Good Question/Topic? 0
  • +

Replies To: How to convert current aspx content to pdf

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to convert current aspx content to pdf

Posted 03 June 2010 - 12:09 AM

Yup it's possible (with 3rd party components), but unfortunately we're not going to show you the code until after you show us the effort you've taken to accomplish this task :)
Was This Post Helpful? 0
  • +
  • -

#3 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: How to convert current aspx content to pdf

Posted 03 June 2010 - 07:14 AM

PsychoCoder, I've seen this question asked so many times before...
I've never tried it myself though.
What 3rd party components would you recommend people check out to achieve this?

-Frinny
Was This Post Helpful? 0
  • +
  • -

#4 Robin228  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-September 12

Re: How to convert current aspx content to pdf

Posted 14 September 2012 - 01:05 AM

Hi ,
Even am trying to convert aspx page to pdf. I used iTextsharp to do that. But the problem is my page has text boxes and the pdf file does not show the text box data. am sharing my code. Kindly gv me the solution.

  protected void Page_Load(object sender, EventArgs e)
        {
         
        }

         protected void SendMail()
        {

            var userName = "n-4@gmail.com";
           
            var toAddress = YourEmail.Text.ToString();
            
            const string Password = "Mypassword"          
            string subject = YourSubject.Text.ToString();
            string body = "From: " + YourName.Text + "\n";
            body += "Email: " + YourEmail.Text + "\n";
            body += "Subject: " + YourSubject.Text + "\n";
            body += "Question: \n" + Comments.Text + "\n";
        
           
            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "10.238.52.200";
                smtp.Port = 25;
                smtp.EnableSsl = false;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential(userName, Password);
                smtp.Timeout = 20000;
            }

            smtp.Send(userName, toAddress, subject, body);
        }

         protected void Button1_Click(object sender, EventArgs e)
        {

            Response.ContentType = "application/pdf"; 
            Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache); 
            StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); 
            this.Page.RenderControl(hw); 
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); 
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream); 
            pdfDoc.Open(); 
            htmlparser.Parse(sr); 
           
            Response.Write(pdfDoc);
           

             try
            {
                 SendMail();
               
                DisplayMessage.Text = "Your Comments after sending the mail";
                DisplayMessage.Visible = true;
                YourSubject.Text = "";
                YourEmail.Text = "";
                YourName.Text = "";
                Comments.Text = "";
                pdfDoc.Close();
                Response.End();
            }
            catch (Exception) { }

Was This Post Helpful? 0
  • +
  • -

#5 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 395
  • Joined: 04-January 11

Re: How to convert current aspx content to pdf

Posted 14 September 2012 - 01:44 AM

Will all objects and data inside the page be part of the pdf? Have you tried looking into crystalreports or reportviewer?
Was This Post Helpful? 0
  • +
  • -

#6 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: How to convert current aspx content to pdf

Posted 18 September 2012 - 12:57 PM

A while back, I wrote a web service that uses EvoPDF to generate .pdfs from a dynamically generated asp page. It isn't free, so if that's what you're looking for, you'll have to start searching. EvoPDF was the best value that I found for our needs, and has a really simple (but very configurable) API.

EDIT: Evo's trial is fully functional and unlimited with regards to time. If this is for a project that you aren't trying to earn money from, then it might be a viable option.

This post has been edited by h4nnib4l: 19 September 2012 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

#7 Windina  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 7
  • Joined: 20-August 12

Re: How to convert current aspx content to pdf

Posted 18 September 2012 - 10:37 PM

Use this .NET PDF Component,it can convert webpage of ASPX,HTML and HTM to PDF by below code:

namespace ASPX to PDF
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            String url = "ASPX URL";
            doc.LoadFromHTML(url, false, true, true);
            //Save pdf file.
            doc.SaveToFile("sample.pdf");
            doc.Close();
        }
    }
}   

Was This Post Helpful? 0
  • +
  • -

#8 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: How to convert current aspx content to pdf

Posted 19 September 2012 - 07:21 AM

You failed to point out that that isn't a free solution, either.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1