Solved

Convert Binary Data to PDF

Posted on 2016-07-19
8
18 Views
Last Modified: 2016-09-28
Good day all,

I have a field in a SQL table that contains binary data that I need to convert to a PDF. All recommendations are appreciated.
0
Comment
Question by:EMCIT
  • 3
  • 3
8 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41719533
and what is that binary data?
and do you plan to "display" the data/pdf?
0
 
LVL 11

Author Comment

by:EMCIT
ID: 41719550
The binary is a converted PDF.  I need to convert it back to pdf to save as a .pdf.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41719565
What is the data type of the field that the binary data (PDF data) is stored in?

~bp
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 11

Author Comment

by:EMCIT
ID: 41719567
The field is varbinary(MAX)
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 41719597
Okay, what do you have so far?  Are you working in Access using VBA, or in VBScript?  Can you share the code you have that connects to the data base and does a query, etc?

~bp
0
 
LVL 11

Author Comment

by:EMCIT
ID: 41719603
I'm building an Access front end (VB) that will connect to SQL via ODBC. A variable will be passed that will identify the record to be retrieved. The PDF (Binary) will be saved to a network location.
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points (awarded by participants)
ID: 41719628
Okay, here are a couple of examples of what you need to do I believe. The basic idea is to query the table as you would normally to get the column that has the binary data, then store that in a file using an ADO stream.  Hope these help.

See routines shared here:

https://usefulgyaan.wordpress.com/2014/09/30/store-and-fetch-files-sql-server-tables/

I also found this code snippet that is the same idea:

Dim cn  As ADODB.Connection
Dim rs  As ADODB.Recordset
Dim sql As String
Dim oStream As ADODB.Stream

Set cn = New ADODB.Connection

'Here I use default admin user 'sa' and password is blank
cn.Open "Provider = sqloledb;" & _
        "Data Source=ServerNameOrIP;" & _
        "Initial Catalog=DBName;" & _
        "User ID=sa;" & _
        "Password=;"""

'your sql statment including varbinary max field here it is FILEDATA
sql = " select EMAILID,EMAILFROM,EMAILTO,EMAILSUBJECT,FILEDATA from Tbl "


Set rs = New ADODB.Recordset

rs.Open sql, cn

Do Until rs.EOF
    Set oStream = New ADODB.Stream
    With oStream
         .Type = adTypeBinary
         .Open
         .Write rs.Fields(4).Value
         'Here I use 1st field value as file name i.e. rs.fiedls(0).value 
         'In addition you can join drive and/or folder path to save another location
         .SaveToFile rs.Fields(0).Value & ".pdf", adSaveCreateOverWrite
         .Close
    End With
    Set oStream = Nothing
    rs.MoveNext
Loop

Open in new window

~bp
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now