Click here to Skip to main content
15,913,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using iTextsharp dll for export pdf from gridview.
It doesn't display the all records from gridview, it displays only current page record, but i want to display all page records.

Please Help me.

Thanks in advance.
Posted
Updated 17-May-11 0:21am
v2
Comments
[no name] 17-May-11 6:21am    
Post your code we will guide you where you went wrong.
ankitmalviyans 17-May-11 6:56am    
code for Default.aspx
----------------------


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td align="right">
<asp:ImageButton ID="btnPDF" runat="server" ImageUrl="~/PDF.jpg" Width="32px"
Height="32px" onclick="btnPDF_Click"/>
</td>
</tr>
<tr>
<td>
<asp:GridView runat="server" ID="gvdetails" DataSourceID="dsdetails" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false">
<rowstyle backcolor="#EFF3FB">
<footerstyle backcolor="#507CD1" font-bold="True" forecolor="White">
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<alternatingrowstyle backcolor="White">
<columns>
<asp:BoundField DataField="UserId" HeaderText="UserId" />
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Location" HeaderText="Location" />


</td>
</tr>
</table>
<asp:SqlDataSource ID="dsdetails" runat="server" ConnectionString="<%$ConnectionStrings:dbconnection %>"
SelectCommand="select * from UserInformation"/>
</div>
</form>
</body>
</html>


Code For Default.aspx.cs
-----------------------------

using System;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
protected void btnPDF_Click(object sender, ImageClickEventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.RenderControl(hw);
gvdetails.HeaderRow.Style.Add("width", "15%");
gvdetails.HeaderRow.Style.Add("font-size", "10px");
gvdetails.Style.Add("text-decoration", "none");
gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvdetails.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}
veeru111 20-Dec-12 7:09am    
By fallowing this code getting .pdf but data in columns not in correct alignment so please solve this problem this will helps to me._thank you.

This code snippets generate the PDF report on Button click event.For that I taken one dynamic grid then bind it into HTML code because for generating PDF we have to Make HTML code first try this I think u got solution.
protected void PrintReportButton_Click(object sender, EventArgs e)
    {
       
        #region DataGrid Bind

        DataGrid grdFinal = new DataGrid();


        objClientReportBL._ClientReportId = Request.QueryString["ClientReportId"].ToString();
        objClientReportBL.Reportdata();

        grdFinal.DataSource = objClientReportBL.ds.Tables[0];
        grdFinal.DataBind();

        Response.Buffer = true;
        Response.ClearContent();
        Response.ClearHeaders();
        #endregion

        #region ERROR Method
       Response.ContentType = "application/vmd.pdf";
       

        Response.AddHeader("content-disposition", "attachment;filename=ClientReport.pdf");
       

        EnableViewState = false;


        using (StringWriter sw = new StringWriter())
        {
            HtmlTextWriter hw = new HtmlTextWriter(sw);

            grdFinal.RenderControl(hw);

            Response.Write(sw.ToString());
            Response.Flush();
            //    Response.Close();
            Response.End();
        }
        #endregion
    }
 
Share this answer
 
this link will help you :)
Export gridview to pdf using iTextsharp[^]
 
Share this answer
 
Comments
ankitmalviyans 17-May-11 7:07am    
Sorry ,
But the my requirement is all the data is in pdf whether it is display in gridview firstpage or its 2nd page so on............I want to full record is in pdf .If the pagination is allowed.
Hi...Ankit...
For that functionality have to convert all the data into HTML then u can proceed then u have to download COM library...and there is one class name is PDFMANAGER using that u can Arrange PDF...this COM library u can get from http://www.asppdf.com/ ..... try this..
------------------------------------
HAVE A NICE DAY
IF IT HELPS PLEASE VOTE IT.....up
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900