Sample code for 30+ languages & platforms
Rust

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

Rust

let json = chilkat::JsonObject::new();

// Load the JSON.
if json.load_file("qa_data/json/JSR5U.json").is_err() {
    println!("{}", json.last_error_text());
    return;
}

// The JSON we loaded contains this:

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

let sb = chilkat::StringBuilder::new();
let _ = json.string_of_sb("data.content", &sb);

let bd = chilkat::BinData::new();
let _ = bd.append_encoded_sb(&sb, "base64");

let _ = bd.write_file("qa_output/a0015.pdf").is_ok();