Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to convert aspx page into pdf and download it but unable to get the inserted values in pdf,my page contains textboxs,images,labels please help me

C#
try
               {
                   string html;


                   if (string.IsNullOrEmpty(tbUrl.Text.Trim()))
                   {
                       throw new ApplicationException("The URL is empty.");
                   }

                   using (var client = new WebClient())
                   {
                       html = client.DownloadString(tbUrl.Text);
                   }


                   //Transform the HTML into PDF


                   var pechkin = Factory.Create(new GlobalConfig());
                   var pdf = pechkin.Convert(new ObjectConfig()
                                           .SetLoadImages(true).SetZoomFactor(1.5)
                                           .SetPrintBackground(true)
                                           .SetScreenMediaType(true)
                                           .SetCreateExternalLinks(true), html);


                   //Return the PDF file

                   Response.Clear();

                   Response.ClearContent();
                   Response.ClearHeaders();

                   Response.ContentType = "application/pdf";
                   Response.AddHeader("Content-Disposition", string.Format("attachment;filename=test.pdf; size={0}", pdf.Length));
                   Response.BinaryWrite(pdf);

                   Response.Flush();
                   Response.End();



               }

               catch (Exception ex)
               {

               }
Posted
Updated 29-Dec-14 5:16am
v2
Comments
Rene Bustos 29-Dec-14 12:26pm    
Hi.Atif Ur Rahman, i have a few questions:

The URl that you trying to download...is yours?

Can you explain deeper how you fill first your Textbox, labels.. etc.etc...


i made the questions 'cause, if all here have a better information about your way,,, we can help you in the best way.

have you heard about itextSharp?

best regards
Atif Ur Rahman 30-Dec-14 8:33am    
yes uri i am trying to download is my uri, and i am filling textboxes manually

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900