Solved

Convert Binary Data to PDF

Posted on 2016-07-19
8
47 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 143

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 54

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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 11

Author Comment

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

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 54

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Conditional Format if Between Dates 9 45
usage of ms/excell 3d maps in ms/access 2016 6 43
GA Ribbon creator 9 61
question about a text field with default value 5 31
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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 …

734 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