Click here to Skip to main content
15,918,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application where I have a link button in one aspx page which opens another aspx page which is basically a report but predefined wordings, except some numeric values which is coming from the page where the link button is clicked.


C#
string script = "detailedresults=window.open('processdocs/" + doc_file + "?id=" + id + "')";

      ScriptManager.RegisterStartupScript(this, this.GetType(), "jsCall", script, true);



I need to change it like this. When i click on the link , it should open the aspx page as pdf report which user can download and save as pdf to any path. Means the aspx page should be writen based on the id column but it must be to pdf

please advise
Posted
Updated 3-Oct-13 23:11pm
v3

use itextsharp.dll...

Go to http://itextpdf.com/download.php and click "Download iTextSharp". In your Visual Studio project, you need to reference the itextsharp.dll that you just downloaded.
 
Share this answer
 
Comments
Member 10112611 4-Oct-13 2:23am    
so u have any code?
Member 10112611 15-Oct-13 1:18am    
still i couldn't resolve that..I used itext sharp and converted the aspx page to pdf..but the alignemnt gone..any clue?
string url="~//upload//sample.pdf";
Response.Redirect(url);
 
Share this answer
 
Comments
Member 10112611 4-Oct-13 5:41am    
for me the path contains aspx page only . that should be shown as pdf
i tried this

protected void writetoPDF()
   {
       MyPage tmpPage = new MyPage();
       HtmlForm form = new HtmlForm();
       form.Controls.Add(form1);
       tmpPage.Controls.Add(form);
       StringWriter sw = new StringWriter();
       HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
       form.Controls[0].RenderControl(htmlWriter);
       string htmlContent = sw.ToString();
       Document document = new Document();
       // step 2:
       // we create a writer that listens to the document
       // and directs a PDF-stream to a file
       var fileName = HttpContext.Current.ApplicationInstance.Server.MapPath("");
       fileName = fileName + @"\Report.pdf";
       PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));

       // step 3: we open the document
       document.Open();

       // step 4: we add a paragraph to the document
       //document.Add(new Paragraph(htmlContent.ToString()));

       System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));

       // HtmlParser.Parse(document, _xmlr);
       using (TextReader sReader = new StringReader(htmlContent.ToString()))
       {

           List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());

           foreach (IElement elm in list)
           {

               document.Add(elm);

           }

       }

       // step 5: we close the document
       document.Close();

       ShowPdf(fileName);
       if (File.Exists(fileName))
           File.Delete(fileName);
   }
   private void ShowPdf(string s)
   {

       string saveas = qms_control_nbr + ".pdf";
       Response.ClearContent();
       Response.ClearHeaders();
       Response.AddHeader("Content-Disposition", "inline;filename=" + saveas);
       Response.ContentType = "application/pdf";
       Response.WriteFile(s);
       Response.Flush();
       Response.Clear();
   }


this is working but all the formating defined for the aspx page gone.

Can anyoone advice?
 
Share this answer
 

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