Click here to Skip to main content
14,920,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im currently developing "document management system" for now, im using picturebox convert to binary and save to sql. but I want to give them options to import pdf file.
here's my code for converting my photo to binary

i dont know how to convert pdf. can someone help me? thankx alot

What I have tried:

Dim arrImage() As Byte
      Dim strImage As String

If Not IsNothing(Me.PictureBox2.Image) Then
              Me.PictureBox2.Image.Save(myMs, Me.PictureBox2.Image.RawFormat)
              arrImage = myMs.GetBuffer
              strImage = "?"
              arrImage = Nothing
              strImage = "NULL"
          End If
Updated 6-Oct-20 18:38pm

1 solution

Don't think there would be much of a code difference other than ContentType. All such data - image, PDF will be stored in binary format - code remain same - read data in bytes and store it.

The additional information you need to store in DB along with bytes is the content type (if you plan to store multiple forms of data) such that while you retrieve back you know what that byte data is for and then make use of it to display back as an image or a pdf.

Sample code if it's only PDF then you know content type is fixed so no need to store:
Dim filebytes As Byte() = File.ReadAllBytes(pathToFile)

Using con As SqlConnection = New SqlConnection(strConnect)

    Using cmd As SqlCommand = New SqlCommand("INSERT INTO MyTable (PDFData) VALUES (@PDFFile)", con)
        cmd.Parameters.AddWithValue("@PDFFile", filebytes)
    End Using
End Using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900