Convert PDF to Base64

Xbase++ 2.0 Build 554 or later
Message
Author
User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Convert PDF to Base64

#1 Post by PedroAlex »

Hey guys.
Does anyone have an example of how to convert a PDF file to Base64 String.

Many Thanks.
Pedro Alexandre

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert PDF to Base64

#2 Post by Tom »

Load the File (Memoread, FileStr) as a binary string, apply a conversion function (xbBase64Encode from Xb2.Net, Xbase++ has a function aswell) to that string, that's it.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert PDF to Base64

#3 Post by PedroAlex »

Tom, I did that, too, but it's not that simple.
This sample does not work.
xBase 2.0.1176.
Can you check if it works with your version?

Code: Select all


//=====================================================================
Function PDF2Base64()
Local cFile := Dc_popFile()

MsgBox(cFile,'The  PDF' File)

cStream := FileStr(cFile)

MsgBox( cStream,'FileStr() do PDF' )

cB64 := Bin2Base64( cStream )

MsgBox( 'CB64 ' + cB64 ,'PDF to Base64')

Return NIL

Something doesn't work well
Pedro Alexandre

gradosic
Posts: 45
Joined: Tue Dec 07, 2010 2:11 pm
Location: Croatia - Europe
Contact:

Re: Convert PDF to Base64

#4 Post by gradosic »

Hi!

I do it thisway:


cFile = PDF file...
Base64Coded:=ToBase64(MEMOREAD(cFile))

then you can use this "Base64Coded" how you want (in XML, SOAP, etc...)

Goran
Goran Radosic

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert PDF to Base64

#5 Post by PedroAlex »

Hi,
Tobase64() ?? It is Alaska xbase ??


I think the problem is in the way of reading the Pdf.
Memoread () and FileStr () don't seem to be the right way ...
Pedro Alexandre

gradosic
Posts: 45
Joined: Tue Dec 07, 2010 2:11 pm
Location: Croatia - Europe
Contact:

Re: Convert PDF to Base64

#6 Post by gradosic »

It's ot4xb library, you can find it on https://www.dll-files.com/ot4xb.dll.html..

this is working 100%, we send thousands of PDF files thisway.

br
Goran Radosic

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert PDF to Base64

#7 Post by Tom »

Or use the functions from Xb2.Net.

Code: Select all

cBase64 := xbBase64Encode(FileStr(cFileName))
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert PDF to Base64

#8 Post by PedroAlex »

Goran,

Can you post (in a Txt file) the result of ToBase64() the anexed pdf?
Attachments
FATURA_FT_1_768.rar
(165.55 KiB) Downloaded 738 times
Pedro Alexandre

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Convert PDF to Base64

#9 Post by Tom »

Hi, Pedro.

See Attachment. Result of xbBase64Encode(FileStr("FATURA_FT_1_768.pdf")).
Attachments
base64.zip
(171.86 KiB) Downloaded 743 times
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

User avatar
PedroAlex
Posts: 234
Joined: Tue Feb 09, 2010 3:06 am

Re: Convert PDF to Base64

#10 Post by PedroAlex »

Hi, Tom.

Many Thanks .

The result of your sample is correct. But I have not Xb2net.

I cannot get this result with the Alaska Function Bin2Base64().

Have you tried this feature in your Alaska version?

Just for confirm..

cB64 := Bin2Base64(FileStr("FATURA_FT_1_768.pdf"))

Thanks..
Pedro Alexandre

Post Reply