PowerBuilder
PowerBuilder
Extract PDF from JSON
See more JSON Examples
Demonstrates how to extract a PDF file contained within JSON. The file is represented as a base64 string within the JSON. Note: This example can extract any type of file, not just a PDF file.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Json
oleobject loo_Sb
oleobject loo_Bd
li_Success = 0
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_Json
MessageBox("Error","Connecting to COM object failed")
return
end if
// Load the JSON.
li_Success = loo_Json.LoadFile("qa_data/json/JSR5U.json")
if li_Success <> 1 then
Write-Debug loo_Json.LastErrorText
destroy loo_Json
return
end if
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.StringOfSb("data.content",loo_Sb)
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")
loo_Bd.AppendEncodedSb(loo_Sb,"base64")
li_Success = loo_Bd.WriteFile("qa_output/a0015.pdf")
destroy loo_Json
destroy loo_Sb
destroy loo_Bd