我正在尝试将aspx web面板中的内容导出为pdf。aspx面板包含表格、文本、图表以及最重要的动态google地图。有谁能告诉我怎么做吗?
我已经尝试过了,首先将整个网页转换为位图图像,然后使用iTextSharp将位图转换为pdf格式。这种方法在某种程度上是可行的。然而,我不想在pdf中的aspx页面的所有内容,只是在一个特定的aspx面板的内容。
非常感谢你的好意帮助。
发布于 2013-11-19 04:55:55
将Panel控件的内容呈现为HtmlTextWriter,然后像往常一样写入该文件,如下所示:
protected void YourButton_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=YourPane.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
// Call your panel by ID to render the contents to HTML
YourPanel.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);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}https://stackoverflow.com/questions/20057538
复制相似问题