Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
local json = chilkat.JsonObject.new()
-- Load the JSON.
local success = json:load_file("qa_data/json/JSR5U.json")
if not success then
print(json.last_error_text)
return
end
-- The JSON we loaded contains this:
-- {
-- ...
-- ...
-- "data": {
-- "content": "JVBERi0xLjQ..."
-- }
-- ...
-- ...
-- }
local sb = chilkat.StringBuilder.new()
json:string_of_sb("data.content", sb)
local bd = chilkat.BinData.new()
bd:append_encoded_sb(sb, "base64")
success = bd:write_file("qa_output/a0015.pdf")