Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.7.0+

Split Data across Several QR Codes (Structured Append)

See more QR Code Examples

Demonstrates structured append, the QR feature for data too large for one symbol of the size wanted. The data is divided over up to 16 symbols, and each carries its position, the total, and a parity byte that ties the set together. With encoding.structuredAppend.enabled, QrCode uses as few symbols as it can. output.pathTemplate writes one file per symbol, with {index} replaced by 1, 2, 3 and so on. The reader must support structured append to put the parts back together. Many phone camera apps do not, and show each part separately.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vSbText
    Handle hoSbText
    Integer i
    Variant vJson
    Handle hoJson
    Handle hoFmt
    Variant vJsonOut
    Handle hoJsonOut
    Integer iNumSymbols
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Integer iTemp3
    Integer iTemp4

    Move False To iSuccess

    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  Some text that is too long for one symbol of the size allowed below.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbText
    If (Not(IsComObjectCreated(hoSbText))) Begin
        Send CreateComObject of hoSbText
    End

    For i From 1 To 20
        Get ComAppend Of hoSbText "Line " To iSuccess
        Get ComAppendInt Of hoSbText i To iSuccess
        Get ComAppendLine Of hoSbText " of a message that is too long for one small QR code." True To iSuccess
    Loop

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbText to vSbText
    Get ComUpdateSb Of hoJson "payload.text" vSbText To iSuccess

    //  Keep each symbol small (version 10 is 57 modules wide) and allow a set of symbols.
    Get ComUpdateInt Of hoJson "encoding.qr.maxVersion" 10 To iSuccess
    Get ComUpdateBool Of hoJson "encoding.structuredAppend.enabled" True To iSuccess

    //  One file for each symbol: qr_part_1.png, qr_part_2.png, ...
    Get ComUpdateString Of hoJson "output.pathTemplate" "qa_output/qr_part_{index}.png" To iSuccess
    Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
    Get ComUpdateString Of hoJson "output.return" "none" To iSuccess

    Get Create (RefClass(cComChilkatFormats)) To hoFmt
    If (Not(IsComObjectCreated(hoFmt))) Begin
        Send CreateComObject of hoFmt
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComLength Of hoSbText To iTemp1
    Showln "text length: " iTemp1
    Get ComSizeOfArray Of hoJsonOut "symbols" To iNumSymbols
    Showln "symbols: " iNumSymbols
    For i From 0 To (iNumSymbols - 1)
        Set ComI Of hoJsonOut To i
        //  structuredAppend.index counts from 0.
        Get ComStringOf Of hoJsonOut "outputs[i].path" To sTemp1
        Get ComIntOf Of hoJsonOut "symbols[i].structuredAppend.index" To iTemp1
        Get ComIntOf Of hoJsonOut "symbols[i].structuredAppend.total" To iTemp2
        Get ComIntOf Of hoJsonOut "symbols[i].selectedEncoding.version" To iTemp3
        Get ComIntOf Of hoJsonOut "symbols[i].payloadBytes" To iTemp4
        Showln sTemp1 ": symbol " ((iTemp1 + 1)) " of " iTemp2 ", version " iTemp3 ", " iTemp4 " bytes"
    Loop

    //  Every symbol of a set carries the same parity byte, which is how a reader knows they belong together.
    Get ComIntOf Of hoJsonOut "symbols[0].structuredAppend.parity" To iTemp1
    Showln "parity: " iTemp1

    //  The six symbols:

    //  image

    //  Sample output:

    //  text length: 1231
    //  symbols: 6
    //  qa_output/qr_part_1.png: symbol 1 of 6, version 10, 206 bytes
    //  qa_output/qr_part_2.png: symbol 2 of 6, version 10, 205 bytes
    //  qa_output/qr_part_3.png: symbol 3 of 6, version 10, 205 bytes
    //  qa_output/qr_part_4.png: symbol 4 of 6, version 10, 205 bytes
    //  qa_output/qr_part_5.png: symbol 5 of 6, version 10, 205 bytes
    //  qa_output/qr_part_6.png: symbol 6 of 6, version 10, 205 bytes
    //  parity: 50


End_Procedure