Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

loJson = createobject("CkJsonObject")

// Load the JSON.
llSuccess = loJson.LoadFile("qa_data/json/JSR5U.json")
if (llSuccess <> .T.) then
    ? loJson.LastErrorText
    release loJson
    return
endif

// The JSON we loaded contains this:

// 	{
// 	...
// 	...
// 	  "data": {
// 	    "content": "JVBERi0xLjQ..."
// 	  }
// 	...
// 	...
// 	}

loSb = createobject("CkStringBuilder")
loJson.StringOfSb("data.content",loSb)

loBd = createobject("CkBinData")
loBd.AppendEncodedSb(loSb,"base64")

llSuccess = loBd.WriteFile("qa_output/a0015.pdf")


release loJson
release loSb
release loBd