HexaPDF Extras

class HexaPDF::Extras::GraphicObject::QRCode

Generates a QR code and renders it using simple PDF canvas graphics.

It implements the HexaPDF graphic object interface and can therefore easily be used via the :qrcode name:

canvas.draw(:qrcode, data: 'hello', size: 100)

This class relies on rqrcode_core to generate the QR code from the given data. All options of rqrcode_core are supported, have a look at their documentation to see the allowed values.

Attributes

at[RW]

The position of the bottom-left corner of the QR code.

Default: [0, 0].

Examples:

canvas.draw(:qrcode, data: 'test', size: 30)
canvas.draw(:qrcode, data: 'test', size: 20, at: [50, 50])

code_size[RW]

The code size of the the QR code (normally called ‘version’).

This is directly passed to rqrcode_core as the size argument.

Default: nil (i.e. let rqrcode_core decide)

Examples:

canvas.draw(:qrcode, data: 'test', size: 100, code_size: 10)

dark_color[RW]

The color for the dark QR code modules (‘pixels’)

Default: ‘black’.

Examples:

canvas.draw(:qrcode, data: 'test', size: 100, dark_color: 'green')

data[RW]

The data for which the QR code should be generated.

This is directly passed to rqrcode_core as the data argument.

Default: none

level[RW]

The error correction level of the QR code.

This is directly passed to rqrcode_core as the level argument.

Default: nil (i.e. let rqrcode_core decide)

Examples:

canvas.draw(:qrcode, data: 'test', size: 100, level: :l)

light_color[RW]

The color for the light QR code modules (‘pixels’).

Default: none (i.e. they are not drawn).

Examples:

canvas.draw(:qrcode, data: 'test', size: 100, light_color: 'yellow')

max_code_size[RW]

The maximum code size of the QR code.

This is directly passed to rqrcode_core as the max_size argument.

Default: nil (i.e. let rqrcode_core decide)

Examples:

canvas.draw(:qrcode, data: 't'*100, size: 100, max_code_size: 10)

mode[RW]

The mode of the QR code, i.e. which data it holds.

This is directly passed to rqrcode_core as the mode argument.

Default: nil (i.e. let rqrcode_core decide)

Examples:

canvas.draw(:qrcode, data: 'test', size: 100, mode: :kanji)

size[RW]

The size of the whole rendered QR code.

Default: none

Examples:

canvas.draw(:qrcode, data: 'test', size: 80, at: [10, 10])

Public Class Methods

configure(**kwargs)

Creates and configures a new QRCode drawing support object.

See configure for the allowed keyword arguments.

new()

Creates a QRCode object.

Public Instance Methods

configure(at: nil, size: nil, dark_color: nil, light_color: nil, data: nil, code_size: nil, max_code_size: nil, level: nil, mode: nil)

Configures the QRCode object and returns self.

The following arguments are allowed:

:at

The position of the bottom-left corner.

:size

The size of the whole rendered QR code.

:dark_color

The color used for the dark QR code modules (‘pixels’).

:light_color

The color used for the light QR code modules (‘pixels’).

:data

The data for the QR code.

:code_size

The code size of the QR code.

:max_code_size

The maximum code size of the QR code.

:level

The error correction level of the QR code

:mode

The mode of the of the QR code.

Any arguments not specified are not modified and retain their old value, see the attribute methods for the inital default values.

draw(canvas)

Draws the QRCode object onto the given Canvas, with the bottom-left corner at the position specified by at and the size specified by size.