Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const json = try chilkat.JsonObject.init();
defer json.deinit();
// Load the JSON.
json.loadFile("qa_data/json/JSR5U.json") catch {
std.debug.print("{s}\n", .{try json.getLastErrorText(alloc)});
return;
};
// The JSON we loaded contains this:
// {
// ...
// ...
// "data": {
// "content": "JVBERi0xLjQ..."
// }
// ...
// ...
// }
const sb = try chilkat.StringBuilder.init();
defer sb.deinit();
json.stringOfSb("data.content", sb) catch {};
const bd = try chilkat.BinData.init();
defer bd.deinit();
bd.appendEncodedSb(sb, "base64") catch {};
try bd.writeFile("qa_output/a0015.pdf");
}