Sample code for 30+ languages & platforms
Lua

PDF File Encoding to Base64

See more Base64 Examples

Demonstrates how to encode a PDF file to base64, and then decode.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local pdfData = chilkat.BinData.new()

local success = pdfData:load_file("qa_data/helloWorld.pdf")
if not success then
    print("failed to load PDF file.")
    return
end

-- Encode the PDF to base64
-- Note: to produce base64 on multiple lines (as it would appear in the MIME of an email),
-- pass the string "base64_mime" instead of "base64".
local b64 = pdfData:get_encoded("base64")
print(b64)

-- Decode from base64 PDF.
local pdfData2 = chilkat.BinData.new()
pdfData2:append_encoded(b64, "base64")
success = pdfData2:write_file("qa_output/helloWorld2.pdf")
if not success then
    print("failed to write PDF file.")
    return
end