如何在按钮单击时导出pdf中的div内容。 [英] How to export div content in pdf on button click.
本文介绍了如何在按钮单击时导出pdf中的div内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在点击按钮时以pdf格式导出div内容。
i在以PDF格式导出div数据时遇到问题
i有这样的.aspx页面中的div ..
< div id =FoodTokenDivrunat =server>
How to export div content in pdf on button click.
...... 。 在.cs页面我在这个标签上创建表格以及我希望在标签上显示的内容之后我执行以pdf格式导出div内容的过程... Response.ContentType =application / pdf; Response.AddHeader(content-disposition,attachment; filename = TokenForFoodTN+ did +。pdf); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter stringWriter = new StringWriter() ; HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter); FoodTokenDiv.RenderControl(htmlTextWriter); < br $> StringReader stringReader = new StringReader(stringWriter.ToString()); Document Doc = new Document( new RectangleReadOnly(350,(i * 10)+200),5f,5f,5f,5f); HTMLWorker htmlparser = new HTMLWorker(Doc); PdfWriter.GetInstance(Doc,Response.OutputStream); Doc.Open(); htmlparser.Parse(stringReader); Doc.Close(); Response.Write(Doc); Response.End(); ....... 这里在Document Doc行我增加根据数据的高度所以我使用i * 10这里10是10px,根据我增加。 请帮帮我... 谢谢... |
.......
in .cs page i create table on this label and whatever i want to show on label after that i do the process of exporting div content in pdf like this...
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TokenForFoodTN" + did + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
FoodTokenDiv.RenderControl(htmlTextWriter);
StringReader stringReader = new StringReader(stringWriter.ToString());
Document Doc = new Document(new RectangleReadOnly(350, (i*10)+200), 5f, 5f, 5f, 5f);
HTMLWorker htmlparser = new HTMLWorker(Doc);
PdfWriter.GetInstance(Doc, Response.OutputStream);
Doc.Open();
htmlparser.Parse(stringReader);
Doc.Close();
Response.Write(Doc);
Response.End();
.......
here in Document Doc line i increase height of the according to data so i use i*10 here 10 is 10px which increase according to i.
please help me...
thanks...
推荐答案
请看下面的链接
使用ITextSharp将Div内容导出为PDF [ ^ ]
使用ASP中的iTextSharp将HTML DIV内容导出为PDF .Net [ ^ ]
Please have a look below links
Export Div Content to PDF Using ITextSharp[^]
Export HTML DIV contents to PDF using iTextSharp in ASP.Net[^]
这篇关于如何在按钮单击时导出pdf中的div内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文