Export Gridview content to PDF using iTextsharp
-
hi friends, iam unable to to export gridview content to pdf using itextsharp. i surfed through the net but none of them worked for me if any of you provide me the code it would be a great help. Thanks in Advance, Praveen
-
hi friends, iam unable to to export gridview content to pdf using itextsharp. i surfed through the net but none of them worked for me if any of you provide me the code it would be a great help. Thanks in Advance, Praveen
hi there, I'm also looking into converting html to pdf via iTextSharp for the first time here. Just like to take this oportunity to ask you a question (as my VS is going thru an upgrade I havent been able to test this functionality). Are you using this way to convert simple HTML to PDF?
/// <summary>
/// Creates the PDF document with a given content at a given location.
/// </summary>
/// <param name="strFilePath">The file path to write the new PDF to.</param>
/// <param name="strContent">Content in HTML to write to the PDF.</param>
public static void CreatePDFDocument(String strFilePath, String strContent)
{
Document document = new Document(PageSize.A4, 80, 50, 30, 65);
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(strFilePath, FileMode.Create));
XmlTextReader reader = new XmlTextReader(new StringReader(strContent));
reader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
HtmlParser.Parse(document, reader);
}
catch (Exception e)
{
throw e;
}
}Rocky My Blog
-
hi friends, iam unable to to export gridview content to pdf using itextsharp. i surfed through the net but none of them worked for me if any of you provide me the code it would be a great help. Thanks in Advance, Praveen
hi, pls use the code below and chnage it according to ur requirement.Ther grid im using is having 3 columns thats y ive given iTextSharp.text.Table datatable = new iTextSharp.text.Table(3); code ----- using iTextSharp.text; using iTextSharp.text.pdf; public void export() { Document document = new Document(PageSize.A4, 0, 0, 50, 50); System.IO.MemoryStream msReport = new System.IO.MemoryStream(); var fetchtest = from a in dc.SE_Tests select new { a.Test_Code, a.Test_Name, a.Test_Credits }; DataTable dt = ObtainDataTableFromIEnumerable((IEnumerable)fetchtest); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); // we add some meta information to the document document.Open(); iTextSharp.text.Table datatable = new iTextSharp.text.Table(3); datatable.Padding = 2; datatable.Spacing = 0; float[] headerwidths = { 10, 10, 10}; datatable.Widths = headerwidths; // These cells span 2 rows datatable.DefaultCellBorderWidth = 1; datatable.DefaultHorizontalAlignment = 1; datatable.AddCell("Test_Code"); datatable.AddCell(new Phrase("Test_Name", FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.NORMAL))); datatable.AddCell("Credits"); datatable.DefaultCellBorderWidth = 1; ; for (int i = 0; i < dt.Rows.Count; i++) { datatable.AddCell(new Cell(dt.Rows[i]["Test_Code"].ToString()), i+1,0); datatable.AddCell(new Cell(dt.Rows[i]["Test_Name"].ToString()), i+1,1); datatable.AddCell(new Cell(dt.Rows[i]["Test_Credits"].ToString()),i+1,2 ); } document.Add(datatable); } catch (Exception e) { Console.Error.WriteLine(e.Message); } // we close the document document.Close(); Response.Clear();
-
hi, pls use the code below and chnage it according to ur requirement.Ther grid im using is having 3 columns thats y ive given iTextSharp.text.Table datatable = new iTextSharp.text.Table(3); code ----- using iTextSharp.text; using iTextSharp.text.pdf; public void export() { Document document = new Document(PageSize.A4, 0, 0, 50, 50); System.IO.MemoryStream msReport = new System.IO.MemoryStream(); var fetchtest = from a in dc.SE_Tests select new { a.Test_Code, a.Test_Name, a.Test_Credits }; DataTable dt = ObtainDataTableFromIEnumerable((IEnumerable)fetchtest); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); // we add some meta information to the document document.Open(); iTextSharp.text.Table datatable = new iTextSharp.text.Table(3); datatable.Padding = 2; datatable.Spacing = 0; float[] headerwidths = { 10, 10, 10}; datatable.Widths = headerwidths; // These cells span 2 rows datatable.DefaultCellBorderWidth = 1; datatable.DefaultHorizontalAlignment = 1; datatable.AddCell("Test_Code"); datatable.AddCell(new Phrase("Test_Name", FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.NORMAL))); datatable.AddCell("Credits"); datatable.DefaultCellBorderWidth = 1; ; for (int i = 0; i < dt.Rows.Count; i++) { datatable.AddCell(new Cell(dt.Rows[i]["Test_Code"].ToString()), i+1,0); datatable.AddCell(new Cell(dt.Rows[i]["Test_Name"].ToString()), i+1,1); datatable.AddCell(new Cell(dt.Rows[i]["Test_Credits"].ToString()),i+1,2 ); } document.Add(datatable); } catch (Exception e) { Console.Error.WriteLine(e.Message); } // we close the document document.Close(); Response.Clear();
this code is not working
-
hi friends, iam unable to to export gridview content to pdf using itextsharp. i surfed through the net but none of them worked for me if any of you provide me the code it would be a great help. Thanks in Advance, Praveen