PDF to BLOB with VB6

  • Hi,

    I am trying to put a pdf into a blob field of a sql server. But when i do this i get only the pathname and filename in this field instead of the real pdf image. How can i make clear to VB6 that i want the actual file into this blob field?

    This is the code i use maybe some of you know the software called kofax, where it is possible to make your own script.

    grsDocTable.Fields(TheData.CustomProperties(KEY_DOCDBSTORAGE).Value) = TheData.KofaxPDFFileName

    Greetings,

    Johan  

  • Not familiar with kofax, but if you're using "pure" VB6 and ADO to write to SQL Server, open the PDF file into an ADO Stream object, then write to an IMAGE field via a stored procedure, providing the contents of the stream as an IMAGE parameter of the SP. Inside the SP you can easily INSERT the parameter into the corresponding IMAGE field in your table.

  • I haven't done anything with blobs in VB6, but I have in VB7 (visual studio 2003).  You need to think of the blob as an array of bytes.  That is how I got it to work.  I first converted the file into an array of bytes, and then I inserted it into the database by setting the command objects parm to the array.  This is the function I used to convert the file into an array of bytes (and again, this is vb7 so you will most likely have to modify it)  Hope this helps.

    Private Function GetPhoto(ByVal filePath As String) As Byte()

    '***************************************************************************************************

    ' This method takes the file from the path parameter and returns it in the form of a byte array.

    '***************************************************************************************************

    Dim fs As System.IO.FileStream = New System.IO.FileStream(filePath, IO.FileMode.Open, IO.FileAccess.Read)

    Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs)

    Dim photo() As Byte = br.ReadBytes(fs.Length)

    br.Close()

    fs.Close()

    Return photo

    End Function

     

     

  • Here's some VB6 code. This is cut-and-pasted, slightly modified, from something I've done, so it might not be 100% right...

    SQL TABLE

    ---------

    FileID uniqueidentifier

    FileNM varchar(255)

    FileDT datetime

    ContentTypeID varchar(100)

    SizeDM int

    WidthDM int

    HeightDM int

    ContentBD image

    ExtensionCD varchar(3)

    Stored procedure

    ----------------

    CREATE PROCEDURE dbo.procFile_ADD

    @FileNM varchar(255),

    @FileDT datetime,

    @ContentTypeID varchar(100) = NULL,

    @SizeDM int,

    @WidthDM int = NULL,

    @HeightDM int = NULL,

    @ContentBD image,

    @FileID uniqueidentifier OUTPUT

    AS

    SET NOCOUNT ON

    BEGIN

    SET @FileID = NEWID()

    INSERT INTO tblFile (FileID, FileNM, FileDT, ContentTypeID, SizeDM, WidthDM, HeightDM, ContentBD)

    VALUES (@FileID, @FileNM, @FileDT, @ContentTypeID, @SizeDM, @WidthDM, @HeightDM, @ContentBD)

    END

    GO

    Code

    ----

    Private Sub AddFile(ByVal inFilePath As String)

    Dim cmd As New ADODB.Command

    Dim aStr As New ADODB.Stream

    Dim fil As Scripting.File

    Dim fso As Scripting.FileSystemObject

    Set fso = New Scripting.FileSystemObject

    Set fil = fso.GetFile(FilePath)

    With aStr

    .Type = adTypeBinary

    Call .open

    Call .LoadFromFile(inFilePath)

    End With

    With cmd

    .CommandText = "procFile_ADD"

    .Parameters("@FileNM") = .LoadFromFile(inFilePath)

    .Parameters("@FileDT") = fil.DateLastModified

    .Parameters("@SizeDM") = fil.Size

    .Parameters("@ContentBD") = aStr.Read(adReadAll)

    .Execute

    End With

    Set cmd = Nothing

    Set aStr = Nothing

    Set fil = Nothing

    End Sub

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply