Conversion

Marco Dell'Oca

New member
Local time
Today, 20:22
Joined
May 26, 2015
Messages
3
I have a longtext field in an Access 2013 table with .PDF document in it.
I would like to export this field converted in Base64Binary format in an XML <[CDATA[ ]]> tag.
Is it possible?
How can I do?

Many thanks in advance to anybody.

Marco Dell’Oca
 
Hello Marco!

Yes, it's possible but why do you have PDF format in your field? If you have full PDF, save your file using whatever character set and then load it in your DB. XML file will be easily done using VBA...

Good luck, JLCantara.
 
Hi JLCantara
I did'nt andestand Your post.
Anyway I have solved my problem with this code:

Public Function EncodeFileToBase64Binary(strPicPath As String) As String
' read the filestream from filesystem

Const adTypeBinary = 1 ' Binary file is encoded
' Variables for encoding
Dim objXML
Dim objDocElem
' Variable for reading binary picture
Dim objStream As New ADODB.Stream

' Open data stream from picture
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile strPicPath
' Create XML Document object and root node
' that will contain the data
Set objXML = CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"
' Set binary value
objDocElem.nodeTypedValue = objStream.Read()
' Get base64 value
EncodeFileToBase64Binary = objDocElem.Text
' Clean all
Set objXML = Nothing
Set objDocElem = Nothing
Set objStream = Nothing
End Function


Public Function decodefromBase64Binary(GetFilePath As String, OutFilePath As String) As Boolean
' read the base64binary from the filesystem
' write the filestrem to filesystem
Const foForReading = 1 ' Open base 64 code file for reading
Const foAsASCII = 0 ' Open base 64 code file as ASCII file
Const adSaveCreateOverWrite = 2 ' Mode for ADODB.Stream
Const adTypeBinary = 1 ' Binary file is encoded

' Variables for reading base64 code from file
Dim objFSO
Dim objFileIn
Dim objStreamIn

' Variables for decoding
Dim objXML
Dim objDocElem

' Variable for write binary picture
Dim objStream

On Error GoTo decodefromBase64Binary_err

' Open data stream from base64 code filr
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileIn = objFSO.GetFile(GetFilePath)
Set objStreamIn = objFileIn.OpenAsTextStream(foForReading, foAsASCII)

' Create XML Document object and root node
' that will contain the data
Set objXML = CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"

' Set text value
objDocElem.Text = objStreamIn.ReadAll()

' Open data stream to picture file
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open

' Get binary value and write to file
objStream.Write objDocElem.nodeTypedValue
objStream.SaveToFile OutFilePath, adSaveCreateOverWrite

' Clean all
Set objFSO = Nothing
Set objFileIn = Nothing
Set objStreamIn = Nothing
Set objXML = Nothing
Set objDocElem = Nothing
Set objStream = Nothing
decodefromBase64Binary = True
Exit Function

decodefromBase64Binary_err:
decodefromBase64Binary = False
End Function

Regard
Marco Dell'Oca
 
Hello Marco!

Your definitely not a beginner with VBA! My question was probably formulated improperly. Why do you need to SAVE PDF format. Your solution is a valuable masterpiece of VBA coding but if you have a full version of your PDF reader you can save the file using standard character sets... unless you have pictures in it!

Good day, JLC.
 
Hi JLCantara
>Why do you need to SAVE PDF format.
>but if you have a full version of your PDF reader you
>can save the file using standard character sets...
>unless you have pictures in it!

I do not need to save file in PDF format.
I have the same problem with all type of pictures.
I need to save them in base64binary format.
So if I have the full version of the PDF reader the problem is the same.

Regards
Marco Dell'Oca
 
Hi Marco!
Since in your initial post you were talking about PDF documents, I taught you had PDF books or chapter and wanted to change there format. Any way, superb job with the procs!!! I will test them ASAP.

Many thanks, JLC.
 

Users who are viewing this thread

Back
Top Bottom