Link to home
Start Free TrialLog in
Avatar of ADEZOYSA1

asked on

VB6 saving file to make .pdf file

I am receiving a Base64 file (which is actually a .pdf file).  I am successfully decoding the Base64 ascii file that I am receiving.  

 However, when I go to save the file, it doesn't seem to open in .pdf (recognisizes it as a damaged file).  I am trying to save the file in VB6 as a binary file.

The way I am verifying this is that I take the .pdf file (the original from which the person used a Base64 to encode it) and then use WORDPAD to view it.  I see the familiar %PDF-1.2 etc in the file.  this is the same starting string that I get when I decode the Base64 string in VB6.  I even matched every line from the .pdf vs the file that I saved in VB6.  The file size is slightly off (the VB6 is larger), don't know if there is a header of some sort that I am missing for Adobe Reader to recognize the file I save in VB6.

I used a free online Base64 decoder ( and cut/paste the string that is sent to me, and then used the option to save the file as a binary file.  when I renamed the extension of the saved binary file to .pdf, it opened perfectly in Adobe reader.

Any ideas on what I am doing wrong?  My guess is that I am not using VB6 to save to binary correctly.

Avatar of chaau
Flag of Australia image

You need to show us your code. It is obviously a bug somewhere
Avatar of ADEZOYSA1


find below the coding that I have in place.  I am using Chilkat's activex to do the decoding.

Private Sub Command2_Click()
    Dim Decrypt As New ChilkatCrypt2
    Dim Line_From_File As String
    Dim Decrypt_Data As String
    'open the file
    Open "c:\originals\base64\raw data\test.txt" For Input As 1
    Open "c:\originals\base64\raw data\test1.pdf" For Output As 2
    Dim success As Long
    success = Decrypt.UnlockComponent("?????")
    If (success <> 1) Then
        Text1.Text = Text1.Text & crypt.LastErrorText & vbCrLf
        Exit Sub
    End If
    'get the base64 file
    Line Input #1, Line_From_File
    Decrypt.CryptAlgorithm = "none"
    Decrypt.EncodingMode = "base64"
    Decrypt_Data = Decrypt.DecryptStringENC(Line_From_File)
    'write to file
    Print #2, Decrypt_Data
    Close #1
    Close #2

    MsgBox ("completed")

End Sub
Avatar of chaau
Flag of Australia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked!  Thanks.

I used the strcovr function to write the byte array and it worked like a charm.