Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Export Gridview content to PDF using iTextsharp

Export Gridview content to PDF using iTextsharp

Scheduled Pinned Locked Moved ASP.NET
help
5 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4510968
    wrote on last edited by
    #1

    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

    R B R 3 Replies Last reply
    0
    • U User 4510968

      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

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • U User 4510968

        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

        B Offline
        B Offline
        balaji t
        wrote on last edited by
        #3

        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();

        M 1 Reply Last reply
        0
        • B balaji t

          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();

          M Offline
          M Offline
          Member 3117172
          wrote on last edited by
          #4

          this code is not working

          1 Reply Last reply
          0
          • U User 4510968

            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

            R Offline
            R Offline
            Ravi Sant
            wrote on last edited by
            #5

            Better, if you ask same third party for solution.

            ♫ 99 little bugs in the code, 99 bugs in the code We fix a bug, compile it again 101 little bugs in the code ♫

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups