I set as references three dlls:
- itextsharp.dll: the core library
- itextsharp.xtra.dll: extra functionality (PDF 2!)
- itextsharp.pdfa.dll: PDF/A-related functionality This project is hosted on http://sourceforge.net/projects/itextsharp/ You can find the latest release here: http://sourceforge.net/projects/itextsharp/files/itextsharp/
I get an error when executing this code:
On pdfDoc.Close(), "The document has no pages."
Imports iTextSharp.text
Imports iTextSharp.text.html.simpleparser
Imports iTextSharp.text.pdf
gv.DataBind()
gv.AllowPaging = "False"
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
Dim frm As New HtmlForm()
gv.Parent.Controls.Add(frm)
frm.Attributes("runat") = "server"
frm.Controls.Add(gv)
frm.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.[End]()