Written by

Question water huang · Mar 3, 2024

base64 data to pdf

hi there , when i convert a pdf to base64 data, and then restore the data to pdf,i find that ,i must read the same  as length of base64 data every time convert ,or i can't get the right pdf. the code is:

s pdf= ##class(%FileBinaryStream).%New()
pdf.Filename = $g(path)
len=24*30*2
byteList = pdf.Read(len)
while(byteList'=""){
baseStr = ##class(%SYSTEM.Encryption).Base64Encode(byteList)

length of baseStr  is 1970,

if len=24*30 length of baseStr  is 984,

when i covert the base64 data to pdf, the code is: 

pdf= ##class(%FileBinaryStream).%New()
pdf.Filename = $g(path)
while ('sgc.AtEnd){
baseStr = sgc.Read(len1)
byteList = ##class(%SYSTEM.Encryption).Base64Decode(baseStr)
img.Write(byteList)

when len is 24*30*2, len1 is 1970,when len is 24*30,len1 is 984, and i can get the right pdf,if the base64 data comes from others, how can i know the num of len1?

Product version: Ensemble 2016.1
$ZV: Cache for Windows (x86-64) 2016.2.3 (Build 907_11_20446U) Thu Nov 12 2020 16:56:45 EST

Comments

water huang  Mar 3, 2024 to Enrico Parisi

yes, i konw it, if not Insert CR/LF after every 76 characters,when len is 24*30*2, len1 is 1920,when len is 24*30,len1 is 960, and i can get the right pdf,if the base64 data comes from others, how can i know the num of len1?

0
water huang · Mar 3, 2024

i got it,the code must like this "baseStr = ##class(%SYSTEM.Encryption).Base64Encode(byteList,1)",len must be 24*n,and len1 must be 8*n

0