Results 1 to 6 of 6

Thread: get PDF from SQL and view it?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    get PDF from SQL and view it?

    How can i get a PDF from a SQL table and view it in the Adobe control?

    I found this code but i dont know how to pass the data from SQL into the control.

    Code:
            Me.AxPdf1.Visible = True
            Me.AxPdf1.setCurrentPage(1)
            Me.AxPdf1.LoadFile("C:\MyFile.pdf")
            Me.AxPdf1.gotoFirstPage()
            Me.AxPdf1.Enabled = True
            Me.AxPdf1.Select()
            Me.AxPdf1.Show()

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: get PDF from SQL and view it?

    Check out "How to read and write BLOB Data" at http://support.microsoft.com/default...b;en-us;308042

    USing that to save the PDF localy .... then you can use your code there to point to the file & display it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    Re: get PDF from SQL and view it?

    Your idea works... but it only pulls one record at a time.

    Any idea how i can pull all the records from the table?

    Code:
            strSQL = "SELECT dbo.StoredDocument.Doc " _
            & "FROM dbo.LetterQueue INNER JOIN " _
            & "dbo.StoredDocument ON dbo.LetterQueue.DocID = dbo.StoredDocument.DocID " _
            & "WHERE  (dbo.LetterQueue.DatePrinted IS NULL)"
    
            OpenDataSet(dsData, strSQL, "MyImages")
    
            Dim x As String = dsData.Tables("MyImages").Rows.Count - 1
            Dim i As Integer
    
            For i = 0 To x
                Dim myRow As DataRow
                myRow = dsData.Tables("MyImages").Rows(i)
    
                Dim MyData() As Byte
                MyData = myRow("Doc")
                Dim K As Long
                K = UBound(MyData)
    
                Dim fs As New FileStream _
                 ("C:\MyNewPDF.PDF", FileMode.Append, _
                  FileAccess.Write)
    
                fs.Write(MyData, 0, K)
    
                fs.Close()
                fs = Nothing
    
            Next
    
            Me.AxPdf1.Visible = True
            Me.AxPdf1.setCurrentPage(1)
            Me.AxPdf1.LoadFile("C:\MyNewPDF.PDF")
            Me.AxPdf1.gotoFirstPage()
            Me.AxPdf1.Enabled = True
            Me.AxPdf1.Select()
            Me.AxPdf1.Show()

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: get PDF from SQL and view it?

    That IS retrieving all the records. It's just creating a single PDF file and overwriting it each time through the loop. If you want to see all the files then you need to save the field contents from each record to a different file name.

    Also, I think you need to declare your 'x' variable as Integer, not String.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    Re: get PDF from SQL and view it?

    is there a way to append each record to the same file?

    if i have three records in the table i will have three pages in the PDF.

    -----
    what i'm trying to do.

    i have a 'print queue' that is sql table. this table stores all the pdf files that need to be printed each day. at the end of the day a user will open this winform app and see if there are any files that need to be printed...

    if there is a better way of doing this please let me know because i walked into this process late in the game.
    Last edited by texas; Mar 30th, 2006 at 06:24 PM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: get PDF from SQL and view it?

    You'd either need to know the binary format of PDF files or else have some component that could do it for you. There's a link to a PDF component in my signature but I'm not sure if it can do what you're asking as I've never actually used it myself.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width