class HexaPDF::Extras::GraphicObject::Zint
Generates a barcode using the ruby-zint library that uses the libzint barcode generation library.
It implements the HexaPDF graphic object interface and can therefore easily be used via the :barcode
name:
canvas.draw(:barcode, width: 50, at: [10, 40], value: 'Hello!', symbology: :code128)
Except for a few keyword arguments all are passed through to ruby-zint, so everything that is supported by Zint::Barcode can be used. To make specifying symbologies easier, it is possible to use symbolic names instead of the constants, see configure
.
Examples¶ ↑
-
Linear barcode
canvas.draw(:barcode, width: 60, at: [20, 45], value: '1123456', symbology: :upce) canvas.draw(:barcode, width: 60, at: [20, 5], value: 'Hello!', symbology: :code128)
-
Stacked barcode
canvas.draw(:barcode, width: 80, at: [10, 40], symbology: :codablockf, value: 'Hello HexaPDF!', option_1: 3)
-
Composite barcode
canvas.draw(:barcode, width: 80, at: [10, 20], symbology: :gs1_128_cc, value: '[99]1234-abcd', primary: "[01]03312345678903", option_1: 3)
-
2D barcode
canvas.draw(:barcode, width: 80, at: [10, 10], symbology: :datamatrix, value: 'Hello HexaPDF!', option_3: 100, output_options: 0x0100)
Constants
Attributes
The width of resulting barcode.
The resulting size of the barcode depends on whether width and height
are set:
-
If neither width nor height are set, the barcode uses the size returned by ruby-zint.
-
If both are set, the barcode is fit exactly into the given rectangle.
-
If either width or height is set, the other dimension is based on the set dimension so that the original aspect ratio is maintained.
Default: nil.
Examples:
-
No dimension set
canvas.draw(:barcode, value: 'test', symbology: :code128)
-
One dimension set
canvas.draw(:barcode, width: 60, value: 'test', symbology: :code128) canvas.draw(:barcode, height: 50, value: 'test', symbology: :code128, at: [0, 50])
-
Both dimensions set
canvas.draw(:barcode, width: 60, height: 60, value: 'test', symbology: :code128)
The keyword arguments that are passed on to Zint::Barcode.new.
Default: {}.
Public Class Methods
Creates a Zint
graphic object.
Public Instance Methods
Configures the Zint
graphic object and returns self.
The following arguments are allowed:
- :at
-
The position of the bottom-left corner (see
at
). - :width
-
The width of the barcode (see
width
). - :height
-
The height of the barcode (see
height
). - :font
-
The font to use when outputting strings (see
font
). - :symbology
-
The type of barcode. Supports using symbols instead of constants, e.g.
:code128
instead of Zint::BARCODE_CODE128. - :zint_kws
-
Keyword arguments that are passed on to ruby-zint.
Any arguments not specified are not modified and retain their old value, see the attribute methods for the inital default values.
Creates a Form XObject for the given HexaPDF::Document that contains the visual representation of the barcode.