export gridview to pdf

Last post 08-23-2008 3:35 AM by karanpaul. 18 replies.

Sort Posts:

  • export gridview to pdf

    06-04-2008, 12:36 PM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

     Hi,

    Can anyone tell me if i can use http://itextsharp.sourceforge.net/ library with VB code???

     I mean all my project is in VB, so can i use this library?

    Thanks
     

  • Re: export gridview to pdf

    06-04-2008, 12:53 PM
    • All-Star
      29,891 point All-Star
    • HeartattacK
    • Member since 01-08-2007, 12:53 PM
    • Dhaka, Bangladesh
    • Posts 3,239
    • Moderator
      TrustedFriends-MVPs

    You should be able to...just add the itextsharp.dll into the bin folder / add a reference to it.

    All that glitters is gold-
    Only shooting stars break the mold.

    Read my blog: www.heartysoft.com

    Tell me what tutorials / articles / videos you want to see on my site.
  • Re: export gridview to pdf

    06-04-2008, 12:56 PM
    • Contributor
      3,068 point Contributor
    • blurearc
    • Member since 04-25-2008, 11:15 AM
    • Mumbai India
    • Posts 537

    yes it is quite possible.... because it doesn't matter in which .net language you DLL is created ..
    all you have to do just add ITextSharp.DLL as a refrence in your project and start using it..
    For example I create controls and libs gor my team in C3 and they use itin VB

    "Mark as answered if you feel this helps you"
    "Curiosity is Bliss"
    Regards,

    Ravi Kant Srivastava
    (Sr. Consultant I)
    Neudesic
    Hyd'bad
    INDIA
  • Re: export gridview to pdf

    06-04-2008, 1:09 PM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

     Hi to you all,

     being said what you all said, can anyone tell me why i get this errors?

    tWriter(sw)
            GridView1.RenderControl(htw)
            Dim html As String = "<html><body>" + sw.ToString() + "</body></html>"

            'Set up the response
            Response.Clear()
            Response.ContentType = "application/pdf"

            'Create pdf document
            Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)   -> here: it doesn't recognize the Pagesize. It's says: Pagesize is not declared

            'Create pdf writer, output directly to OutputStream
            Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)  -> here: it doesn't recognize the PdfWriter.  It's says: PdfWriter is not declared
            document.Open()
            'Create tempfile to hold the HTML:
            Dim tempFile As String = Path.GetTempFileName()  -> here. it's says the same thing as the others
            Using tempwriter As New IO.StreamWriter(tempFile, False)
                tempwriter.Write(html)
            End Using

            'Parse the HTML into the document
            HtmlParser.Parse(document, tempFile)  -> -> here. it's says the same thing as the others

            'Cleanup
            document.Close()
            writer.Close()

            'Delete the tempfile:
            File.Delete(tempFile)  -> here. it's says the same thing as the others

            writer = Nothing
            document = Nothing
            Response.[End]()


        End Sub

     

    Thanks
     

  • Re: export gridview to pdf

    06-08-2008, 10:33 PM

    Hi wop_nuno,

    Please add namespace of this third party component into your application.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: export gridview to pdf

    06-09-2008, 5:02 AM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

    Hi Qin Dian Tang,

     Thanks for the reply, but can you explain in detail what you want me to do?

    I'm quiet new to all this thing, so if you could explain it to me, i would really appreciate.

     
    Thanks.
     

  • Re: export gridview to pdf

    06-09-2008, 9:51 PM

    Hi wop_nuno,

    Like adding a general namespace you just need to do this:

    using System.IO;
    using iTextSharp;
    using iTextSharp.text;
    using iTextSharp.text.pdf;

    Thanks,


     

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: export gridview to pdf

    06-09-2008, 10:22 PM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

     Hi Qin Dian Tang,

    I've done what you said and i always get the same error messages.

    Do you know what else could be causing this error?

    Thanks.

    Nuno 

  • Re: export gridview to pdf

    06-09-2008, 10:34 PM

    Hi wop_nuno,

    You use vb code, so it should be:

    Imports System.IO
    Imports iTextSharp
    Imports iTextSharp.text
    Imports iTextSharp.text.pdf

    Make sure you have added ITextSharp.DLL as a reference as HeartattacK and blurearc said in above replies.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: export gridview to pdf

    06-10-2008, 8:15 AM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

    Hi Qin Dian Tang,

     thanks for the reply, but like i said in my previous post i've already done that (even with the VB code) and still doesn't work.

    So your post didn't solve my problem, therefore it's not an answer.

    Thanks.
     

  • Re: export gridview to pdf

    06-10-2008, 9:31 PM

    Hi wop_nuno,

    Have you put dll file into bin folder in your web application? Based on my knowledge if you do everything I told you, it should work fine. You can check whether you download the right version of itextsharp.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: export gridview to pdf

    06-11-2008, 5:07 AM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286


    Hi Qin Dian Tang

     

    Yes i've put the dll in the bin folder. I've downloaded the dll from here http://itextsharp.sourceforge.net/  

     Now i only have 2 errors:

     

      Response.ContentType = "application/pdf"

            'Create pdf document
            Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)

            'Create pdf writer, output directly to OutputStream
            Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
            document.Open()
            'Create tempfile to hold the HTML:
            Dim tempFile As String = Path.GetTempFileName()
            Using tempwriter As New IO.StreamWriter(tempFile, False)
                tempwriter.Write(html)  --> 'iTextSharp.text.html' is a namespace and cannot be used as an expression
            End Using

            'Parse the HTML into the document
            HtmlParser.Parse(document, tempFile)  -->  Name 'HtmlParser' is not declared.

            'Cleanup
            document.Close()
            writer.Close()

            'Delete the tempfile:
            File.Delete(tempFile)

            writer = Nothing
            document = Nothing
            Response.[End]()
     

    Does any one knows why i'm having this errors? 



    Thanks. 

  • Re: export gridview to pdf

    06-11-2008, 5:40 AM

    Hi wop_nuno,

    Add namespace "iTextSharp.Text.Html" into your application.

    Thanks,

    Qin Dian Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: export gridview to pdf

    06-11-2008, 6:28 AM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

    Hi

    I've added the namespace  but i still getone error. My code is this:

          Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            'Get the HTML from GridView1
            Dim sw As New IO.StringWriter()
            Dim htw As New HtmlTextWriter(sw)
            GridView1.RenderControl(htw)
            Dim html As String = "<html><body>" + sw.ToString() + "</body></html>"

            'Set up the response
            Response.Clear()
            Response.ContentType = "application/pdf"

            'Create pdf document
            Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)

            'Create pdf writer, output directly to OutputStream
            Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
            Document.Open()
            'Create tempfile to hold the HTML:
            Dim tempFile As String = Path.GetTempFileName()
            Using tempwriter As New IO.StreamWriter(tempFile, False)
                tempwriter.Write(html)
            End Using

            'Parse the HTML into the document
            HtmlParser.Parse(Document, tempFile)

            'Cleanup
            Document.Close()
            writer.Close()

            'Delete the tempfile:
            File.Delete(tempFile)

            writer = Nothing
            Document = Nothing
            Response.[End]()


      End Sub


     The error is this:

    Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

     

    On this  line

    GridView1.RenderControl(htw)

    What else do you suggest?

    Thanks for all the help. 

  • Re: export gridview to pdf

    06-11-2008, 8:16 AM
    • Member
      64 point Member
    • wop_nuno
    • Member since 05-08-2007, 11:02 AM
    • Posts 286

     Hi all,

    I've found a way to get this working. I have to add two things.

    First this code:

    The code for the VerifyRenderingInServerForm is just this:

     

     Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
            Return

        End Sub

    Second:  i had to EnableEventValidation = "false" 

     

    Now i have one more question: 

    1) This code opens de PDF document in a window. What do i have to do to "save the document" automatically to the client? (i mean asking the user if he wants to save, etc)
     


    Thanks. 

     

Page 1 of 2 (19 items) 1 2 Next >