Sample code for 30+ languages & platforms
C++

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 C++ Downloads

C++
#include <CkJsonObject.h>
#include <CkStringBuilder.h>
#include <CkBinData.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkJsonObject json;

    //  Load the JSON.
    success = json.LoadFile("qa_data/json/JSR5U.json");
    if (success != true) {
        std::cout << json.lastErrorText() << "\r\n";
        return;
    }

    //  The JSON we loaded contains this:

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

    CkStringBuilder sb;
    json.StringOfSb("data.content",sb);

    CkBinData bd;
    bd.AppendEncodedSb(sb,"base64");

    success = bd.WriteFile("qa_output/a0015.pdf");
    }