Okay everyone, I thought I found a solution, but it's not working. I found this asp.net forum link:export gridview to pdf - ASP.NET Forums. It mentions a dll called Itextsharp which allows conversions to pdf.
Well I mirrored the code on the link to mine for a repeater and I get this error:
Server Error in '/questionaire' Application.
--------------------------------------------------------------------------------
The document has no pages.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.IOException: The document has no pages.
Source Error:
Line 132:
Line 133: 'clean up ;;
Line 134: document.Close()
Line 135: writer.Close()
Line 136: 'deleate the tempfile
Has anyone used Itextsharp before? My code is below, does anyone know why i'm getting this message? Or is there another way to export to a pdf?
Thanks again for all and any help.
Code:
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.IO
Imports System.Text
Imports System.IO.stream
Imports System.data
Imports System.Net.Mail
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.UserControl
Imports System.Web.UI.WebControls
Imports System.Web.Management
Imports System.Diagnostics.Process
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Partial Class addrowgridview
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Repeater1.DataSourceID = SqlDataSource1.ID
Repeater1.DataBind()
End Sub
Dim Total As Integer = 0
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get the html form reapeater1''
Dim stringWrite = New System.IO.StringWriter()
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Repeater1.RenderControl(htmlWrite)
Dim html As String = "<html><body>" + stringWrite.ToString() + "</body></html>"
'set up the response''
Response.Clear()
Response.ContentType = "application/pdf"
'create pdf document''
Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)
'create pdf writer, output directly to outPutStream''
Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
document.Open()
Repeater1.DataSourceID = SqlDataSource1.ID
Repeater1.DataBind()
'Create tempfile to hold the html''
Dim tempfile As String = Path.GetTempFileName()
Using tempwriter As New System.IO.StreamWriter(tempfile, False)
tempwriter.Write(html)
End Using
'pares the html into the document''
HtmlParser.Parse(document, tempfile)
'clean up ;;
document.Close()
writer.Close()
'deleate the tempfile
File.Delete(tempfile)
writer = Nothing
document = Nothing
Response.End()
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
' Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim memory As New MemoryStream
' Me.Repeater1.WritePdfToResponse()
End Sub
End Class
Bookmarks