TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tuman Sahu
1.5k
293
9.3k
getting error Document has no page when convert into pdf
Jan 3 2020 4:32 AM
Hi
I am using .net bind my data into gridview and wanted to convert grid data into pdf file.
but occure a error like Document has no page . My code is bellow .
<form id=
"form1"
runat=
"server"
>
<div>
<asp:GridView ID=
"GridView1"
HeaderStyle-BackColor=
"#3AC0F2"
HeaderStyle-ForeColor=
"White"
RowStyle-BackColor=
"#A1DCF2"
AlternatingRowStyle-BackColor=
"White"
AlternatingRowStyle-ForeColor=
"#000"
runat=
"server"
AutoGenerateColumns=
"false"
OnPageIndexChanging=
"OnPageIndexChanging"
>
</asp:GridView>
<br />
<asp:Button ID=
"btnExport"
runat=
"server"
Text=
"Export To PDF"
OnClick =
"ExportToPDF"
/>
</div>
</form>
Private
Sub
BindGrid()
Dim
strConnString
As
String
= ConfigurationManager.ConnectionStrings(
"safe"
).ConnectionString
Using con
As
New
SqlConnection(strConnString)
Using cmd
As
New
SqlCommand(
"select * from StudentDetails "
)
Using sda
As
New
SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt
As
New
DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
End
Using
End
Using
End
Using
End
Using
End
Sub
Protected
Sub
ExportToPDF(sender
As
Object
, e
As
EventArgs)
Handles
btnExport.Click
Using sw
As
New
StringWriter()
Using hw
As
New
HtmlTextWriter(sw)
'To Export all pages
GridView1.AllowPaging =
False
Me
.BindGrid()
GridView1.RenderControl(hw)
Dim
sr
As
New
StringReader(sw.ToString())
'Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F)
Dim
pdfdoc1
As
New
Document(PageSize.A4, 2.0F, 2.0F, 2.0F, 0.0F)
Dim
htmlparser
As
New
HTMLWorker(pdfdoc1)
PdfWriter.GetInstance(pdfdoc1, Response.OutputStream)
pdfdoc1.Open()
pdfdoc1.NewPage()
htmlparser.Parse(sr)
pdfdoc1.Close()
Response.ContentType =
"application/pdf"
Response.AddHeader(
"content-disposition"
,
"attachment;filename=GridViewExport.pdf"
)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Write(pdfdoc1)
Response.[
End
]()
End
Using
End
Using
End
Sub
Protected
Sub
OnPageIndexChanging(sender
As
Object
, e
As
GridViewPageEventArgs)
Handles
GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
Me
.BindGrid()
End
Sub
Public
Overrides
Sub
VerifyRenderingInServerForm(
ByVal
control
As
Control)
End
Sub
Can any one help me to solve this error.
Reply
Answers (
7
)
in angular with webapi chatbot
upload more size data in asp.net core