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 (www.motobit.com/util/base64-decoder-encoder.asp) 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.
Thanks
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 (www.motobit.com/util/base64-decoder-encoder.asp) 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.
Thanks
You need to show us your code. It is obviously a bug somewhere
ASKER
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
Decrypt_Data = Decrypt.DecryptStringENC(L ine_From_F ile)
'write to file
Print #2, Decrypt_Data
Close #1
Close #2
MsgBox ("completed")
End
End Sub
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
Decrypt_Data = Decrypt.DecryptStringENC(L
'write to file
Print #2, Decrypt_Data
Close #1
Close #2
MsgBox ("completed")
End
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked! Thanks.
I used the strcovr function to write the byte array and it worked like a charm.
I used the strcovr function to write the byte array and it worked like a charm.