【问题标题】:How to convert aspx page to pdf file? [duplicate]如何将aspx页面转换为pdf文件? [复制]
【发布时间】:2011-10-05 21:11:56
【问题描述】:

可能重复:
Directly convert .aspx to .pdf

我做了一个aspx页面,并通过asp.net的图表控件在上面生成图表。 但我无法将此生成的图表生成为 pdf 文档。我想将我的 aspx 页面制作为 pdf 文档。预先感谢您的支持。

【问题讨论】:

  • 您的页面是否包含 Flash(用于图表)?
  • 尝试在stackoverflow上搜索'aspx pdf',这个问题每周至少被问一次。
  • 您是想为自己做这件事,还是希望您的访问者能够做到这一点?

标签: asp.net pdf


【解决方案1】:

当您尝试将 aspx 页面转换为 pdf 时,这意味着您要将渲染的 html 转换为 pdf,所以这里有一个很好的链接,虽然我没有尝试过,但看起来很有希望

It's Here

注意:我假设您的页面不包含任何 Flash 图表。

【讨论】:

    【解决方案2】:

    使用 itextsharp.dll 我相信你可以使用这个 dll 获取 pdf 格式的页面 很容易实现。

    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using iTextSharp.text.html;
    using iTextSharp.text.html.simpleparser;
    

    // 这将在按钮单击时发生

      string attachment = "attachment; filename=" + filename+ ".pdf";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        htextw.AddStyleAttribute("font-size", "7pt");
        htextw.AddStyleAttribute("color", "Black");
    
        Panel_Name.RenderControl(htextw);//Name of the Panel
        Document document = new Document();
        document = new Document(PageSize.A4, 5, 5, 15, 5);
        FontFactory.GetFont("Arial", 50, iTextSharp.text.BaseColor.BLUE);
        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);
    

    将其粘贴到页面上的某个位置

    public override void VerifyRenderingInServerForm(Control control)
    {
    
    
    }
    

    【讨论】:

    • 我尝试使用 itextshart.dll 但它给了我在线使用非法字符的错误 - obj.Parse(se);
    • 粘贴一些代码以便我检查
    • stackoverflow.com/questions/6742560/…看看这对你有没有帮助
    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 2011-03-16
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2011-03-10
    相关资源
    最近更新 更多