Lua Requires Chilkat v11.7.0+
Lua
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- The second argument of AppendLine is cktrue to end each line with CRLF.
local sbCard = chilkat.StringBuilder.new()
sbCard:append_line("BEGIN:VCARD", true)
sbCard:append_line("VERSION:3.0", true)
sbCard:append_line("N:Smith;Alex;;;", true)
sbCard:append_line("FN:Alex Smith", true)
sbCard:append_line("ORG:Example Company", true)
sbCard:append_line("TITLE:Sales Manager", true)
sbCard:append_line("TEL;TYPE=CELL:+1-555-0100", true)
sbCard:append_line("EMAIL:alex.smith@example.com", true)
sbCard:append_line("URL:https://www.example.com", true)
sbCard:append_line("END:VCARD", true)
local json = chilkat.JsonObject.new()
json:update_sb("payload.text", sbCard)
json:update_int("render.moduleSize", 6)
json:update_string("output.path", "qa_output/qr_vcard.png")
json:update_bool("output.overwrite", true)
json:update_string("output.return", "none")
local fmt = chilkat.Formats.new()
local jsonOut = chilkat.JsonObject.new()
local success = fmt:qr_code("generate", json, jsonOut)
if not success then
print(fmt.last_error_text)
return
end
print("vCard length: " .. sbCard.length)
print("QR version: " .. jsonOut:int_of("symbols[0].selectedEncoding.version"))
print("modules: " .. jsonOut:int_of("symbols[0].dimensions.modulesWide") .. " x " .. jsonOut:int_of("symbols[0].dimensions.modulesHigh"))
print("image: " .. jsonOut:int_of("outputs[0].width") .. " x " .. jsonOut:int_of("outputs[0].height") .. " pixels")
-- The image written to qa_output/qr_vcard.png:
--
-- Sample output:
-- vCard length: 197
-- QR version: 10
-- modules: 57 x 57
-- image: 390 x 390 pixels