Sample code for 30+ languages & platforms
Dart

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

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  final json = CkJsonObject();

  // Load the JSON.
  try {
    json.loadFile('qa_data/json/JSR5U.json');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // The JSON we loaded contains this:

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

  final sb = CkStringBuilder();
  json.stringOfSb('data.content', sb);

  final bd = CkBinData();
  bd.appendEncodedSb(sb, 'base64');

  bd.writeFile('qa_output/a0015.pdf');
}