(PHP Extension) Extract PDF from JSON
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.
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
$json = new CkJsonObject();
// Load the JSON.
$success = $json->LoadFile('qa_data/json/JSR5U.json');
if ($success != true) {
print $json->lastErrorText() . "\n";
exit;
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
$sb = new CkStringBuilder();
$json->StringOfSb('data.content',$sb);
$bd = new CkBinData();
$bd->AppendEncodedSb($sb,'base64');
$success = $bd->WriteFile('qa_output/a0015.pdf');
?>
|