Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

set json [new_CkJsonObject]

# Load the JSON.
set success [CkJsonObject_LoadFile $json "qa_data/json/JSR5U.json"]
if {$success != 1} then {
    puts [CkJsonObject_lastErrorText $json]
    delete_CkJsonObject $json
    exit
}

# The JSON we loaded contains this:

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

set sb [new_CkStringBuilder]

CkJsonObject_StringOfSb $json "data.content" $sb

set bd [new_CkBinData]

CkBinData_AppendEncodedSb $bd $sb "base64"

set success [CkBinData_WriteFile $bd "qa_output/a0015.pdf"]

delete_CkJsonObject $json
delete_CkStringBuilder $sb
delete_CkBinData $bd