【问题标题】:Export page content to PDF using a iTextSharp (include buttons and grids)使用 iTextSharp 将页面内容导出为 PDF(包括按钮和网格)
【发布时间】:2011-07-01 13:11:41
【问题描述】:

如何将我的 aspx 页面(包括按钮和网格)导出为 PDF?

在网上搜索我找到了iTextSharp,但它只适用于普通的html。 如果我的页面有网格或按钮,这些不会出现在 PDF 中。

我当前导出为 PDF 的代码。 此代码仅导出基本 html(无按钮或网格)。

string attachment = "attachment; filename=AllPage.pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.RenderControl(htextw);
Document document = new Document();
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
StringReader str = new StringReader(stw.ToString());
HTMLWorker htmlworker = new HTMLWorker(document);
htmlworker.Parse(str);
document.Close();
Response.Write(document);
Response.End();

【问题讨论】:

    标签: asp.net pdf itextsharp webpage html2pdf


    【解决方案1】:

    只需使用wkhtmltopdf。它可以处理任何没有 ActiveX 控件的东西。

    【讨论】:

    • 他需要 itextsharp,而不是 webkit。
    • 写这篇文章的时候,iText{sharp or other} 在 HTML->PDF 转换方面并不是那么好。它可以/做/它,但不是非常好。 wkhtmltopdf 位于 webkit 之上,几乎可以处理任何你扔给它的东西,包括由 javascript 重写的 html(使用正确的命令行选项)。您可以将 GMail 页面转换为 PDF。太疯狂了。
    • 这很好,在使用 itextsharp 将网页转换为 PDF 时确实不是很好。我从不使用 WKhtmltopdf。我在这个问题中使用的最好的库是 Spire.PDF for .NET。它甚至可以动态广告转PDF,代码简单。只有三行 String url = “Http://apple.com”; doc.LoadFromHTML(url, false, true, true); doc.SaveToFile(“webpageaspdf.pdf”);你可以看看这篇文章,那会很有帮助pdfcsharp.blog.com/2012/11/25/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    相关资源
    最近更新 更多