如何导出html< div>内容到pdf文件? [英] How to export html <div> content to pdf document?

查看:90
本文介绍了如何导出html< div>内容到pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将html报告导出为word,excel和pdf文档。

解决方案

你可以使用iText,或者它的.NET端口,iTextSharp:

http://en.wikipedia.org/wiki/IText [ ^ ],

< a href =http://itextpdf.com/> http://itextpdf.com/ [ ^ ],

http://sourceforge.net/projects/itextsharp/ [ ^ ],

< a href =http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial> http://www.javatips.net/blog/2011/09/create -pdf-with-itext-java-tutorial [ ^ ]。



我引用了Java文档,因为这是iText上的主要文档。如果您了解C#,您将很容易理解这个Java文档并将其应用于iTextSharp C#或VB.NET代码。



-SA


  Dim  fileName  As  < span class =code-keyword> String  =会话(  ClientGenCode)& ;   Leather_Pdf _ + DateTime.Now.ToShortDateString()
Response.ContentType = application / pdf
Response.AddHeader( content-disposition字符串 .Format( attachment; filename = {0},fileName + .pdf))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim html 作为 字符串 = ViewState( htmlText)。ToString()
Dim sb = New System.Text.StringBuilder()
sb.Append(html)
Dim objSW = StringWriter(sb)
Dim objTW = HtmlTextWriter(objSW)
Dim objSR As StringReader (objSW.ToString())
Dim objPDF = 文档(PageSize.A4,< span class =code-digit> 10
.0F, 10 .0F, 10 .0F, 10 .0F)
Dim objHW = HTMLWorker(objPDF)
PdfWriter.GetInstance(objPDF,Response.OutputStream)
objPDF.Open()
objHW.Par se(objSR)
objPDF.Close()
Response.Write(objPDF)
响应。结束()


检查这个html示例excel



HTML到Excel-使用的JavaScript和 - Excel到HTML [<一个href =http://www.databison.com/html-to-excel-using-javascript-and-excel-to-html-using-vba/target =_ blanktitle =New Window> ^

Hi,
I want to export html reports to word,excel and pdf document.

解决方案

You can use iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^],
http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial[^].

I referenced Java documentation, because this is where the major documentation on iText is. If you understand C#, you will easily understand this Java documentation and apply it to iTextSharp C# or VB.NET code.

—SA


Dim fileName As String = Session("ClientGenCode") & "Leather_Pdf_" + DateTime.Now.ToShortDateString()
            Response.ContentType = "application/pdf"
            Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName + ".pdf"))
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Dim html As String = ViewState("htmlText").ToString()
            Dim sb = New System.Text.StringBuilder()
            sb.Append(html)
            Dim objSW = New StringWriter(sb)
            Dim objTW = New HtmlTextWriter(objSW)
            Dim objSR As New StringReader(objSW.ToString())
            Dim objPDF = New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
            Dim objHW = New HTMLWorker(objPDF)
            PdfWriter.GetInstance(objPDF, Response.OutputStream)
            objPDF.Open()
            objHW.Parse(objSR)
            objPDF.Close()
            Response.Write(objPDF)
            Response.End()


Check this example of html to excel

html-to-excel-using-javascript-and-excel-to-html[^]


这篇关于如何导出html&lt; div&gt;内容到pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆