Exporting Content of HTML table to PDF in NEW TAB

Posted by Self-Innovator under ASP.NET on 12/8/2012 | Points: 10 | Views : 2433 | Status : [Member] | Replies : 2
Hi,
How to export the content of HTML Table to PDF format IN NEW TAB window under a browser. I am exporting content of html to pdf format but it is opening under the same window of a browser i need to open in a new tab window.Please find any soln....

Below is my Code
Export To gridView Button click event

 string PDF = fn_AttachToPDF();
PDF += "<br>Regards,<br> Admin";
Response.ContentType = "application/pdf";
Response.AddHeader("Contact Details", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter();
StringReader sr = new StringReader(PDF.ToString());
sw.GetStringBuilder().ToString();
HtmlTextWriter hw = new HtmlTextWriter(sw);
tblContactDetails.RenderControl(hw);
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);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();


Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Pavanandey on: 12/10/2012 [Member] Bronze | Points: 25

Up
0
Down
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.RenderControl(hw);
gvdetails.HeaderRow.Style.Add("width", "15%");
gvdetails.HeaderRow.Style.Add("font-size", "10px");
gvdetails.Style.Add("text-decoration", "none");
gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvdetails.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

Mark the answer if this helps you

Thanks
Pavan Kumar
Mark Answer if this fits the need

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Eva2012 on: 12/11/2012 [Member] Starter | Points: 25

Up
0
Down
I know a PDF component that can convert html table to PDF in a new tab, but I am not very clear about the detail code. you can try, but you can try:
http://www.codeproject.com/Catalogs/3776/Spire-PDF-for-NET.aspx




Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response