Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
let json = CkoJsonObject()!
// Load the JSON.
success = json.loadFile(path: "qa_data/json/JSR5U.json")
if success != true {
print("\(json.lastErrorText!)")
return
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
let sb = CkoStringBuilder()!
json.string(ofSb: "data.content", sb: sb)
let bd = CkoBinData()!
bd.appendEncodedSb(sb: sb, encoding: "base64")
success = bd.writeFile(path: "qa_output/a0015.pdf")
}