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