首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将aspx面板导出为pdf

将aspx面板导出为pdf
EN

Stack Overflow用户
提问于 2013-11-19 04:46:18
回答 1查看 3.9K关注 0票数 0

我正在尝试将aspx web面板中的内容导出为pdf。aspx面板包含表格、文本、图表以及最重要的动态google地图。有谁能告诉我怎么做吗?

我已经尝试过了,首先将整个网页转换为位图图像,然后使用iTextSharp将位图转换为pdf格式。这种方法在某种程度上是可行的。然而,我不想在pdf中的aspx页面的所有内容,只是在一个特定的aspx面板的内容。

非常感谢你的好意帮助。

EN

回答 1

Stack Overflow用户

发布于 2013-11-19 04:55:55

Panel控件的内容呈现为HtmlTextWriter,然后像往常一样写入该文件,如下所示:

代码语言:javascript
复制
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();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20057538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档