1
我有一个带有表格和数据的html的stringbuilder,加载的数据库中的图像。 有无论如何,我可以使用asp.net将html字符串直接导出为pdf。使用asp.net将动态html字符串导出为PDF
谢谢
我有一个带有表格和数据的html的stringbuilder,加载的数据库中的图像。 有无论如何,我可以使用asp.net将html字符串直接导出为pdf。使用asp.net将动态html字符串导出为PDF
谢谢
您可以使用iTextSharp将HTML字符串导出为PDF。
下面的代码:
Imports iTextSharp.text
Imports iTextSharp.text.html.simpleparser
Imports iTextSharp.text.pdf
Protected Sub imgViewPDF_Click(sender As Object, e As ImageClickEventArgs)
Using sw As New StringWriter()
Using hw As New HtmlTextWriter(sw)
Dim sb As New StringBuilder()
sb.Append("<html xmlns='http://www.w3.org/1999/xhtml'>")
sb.Append("<head>")
sb.Append("</head>")
sb.Append("<body>")
sb.Append("</body>")
sb.Append("</html>")
Dim sr As New StringReader(sb.ToString())
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=ExportedClientDocument.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim pdfDoc As New Document(PageSize.A4, 42F, 40F, 90F, 50F)
Dim htmlparser As New HTMLWorker(pdfDoc)
Dim pdfWriter__1 As PdfWriter = PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
End Using
End Using
End Sub
@Ramesh你可以尝试这样的: – 2014-12-03 09:34:48
你找[iTextSharp的(http://sourceforge.net/projects/itextsharp/)? – 2014-12-03 05:23:13