(PHP ActiveX) 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
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.JsonObject')
$json = new COM("Chilkat.JsonObject");
// Load the JSON.
$success = $json->LoadFile('qa_data/json/JSR5U.json');
if ($success != 1) {
print $json->LastErrorText . "\n";
exit;
}
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.StringBuilder')
$sb = new COM("Chilkat.StringBuilder");
$json->StringOfSb('data.content',$sb);
// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.BinData')
$bd = new COM("Chilkat.BinData");
$bd->AppendEncodedSb($sb,'base64');
$success = $bd->WriteFile('qa_output/a0015.pdf');
?>
|