Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this the code for i convert datas from gridview to pdf file format.... i get the data's from backend asign to datatable and asign the datatable values to manually created gridview... the code convert the data's as pdf file perfectly .... now i want add logo before the data how can i add it.... Please help me asap.......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Globalization;
using VMSBusiness;
using System.Net;
using System.IO;
using System.Data;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.Web.Configuration;

namespace VMSWeb
{
public class exporttopdf
{

public void GetPdfReport(string filename,DataTable dt1)
{
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;fileName="+filename+"");
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

GridView gvpdf = new GridView();
gvpdf.DataSource = dt1;
gvpdf.DataBind();
gvpdf.AllowPaging = false;
gvpdf.RenderControl(hw);


StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();


HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.Response.End();
}
}
}
}
}
Posted
Comments
Muthuraj.M 3-Jul-14 5:17am    
thank you Naz_Firdouse for ur help.... i hope to tell this its solved my issue

1 solution

 
Share this answer
 
Comments
Muthuraj.M 3-Jul-14 5:17am    
thank you Naz_Firdouse for ur help.... i hope to tell this its solved my issue
Naz_Firdouse 21-Jul-14 7:29am    
welcome :)

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