pgzint 0.2.0
PostgreSQL extension for the Zint Barcode library
This extension adds support for generating barcodes via database functions, to allow any application that can display PNG images to have barcode generation support without directly integrating with Zint. The images are returned via a bytea result.
It adds a function:
bc_generate(
pinput text,
psymbology integer,
pheight float8,
pscale float8,
pwhitespacewidth integer,
pborderwidth integer,
poutputoptions integer,
pfgcolor text,
pbgcolor text,
pshowtext boolean,
poption1 integer,
poption2 integer,
poption3 integer,
protation integer = 0
)
A table called bc_symbols contains the mappings between the Zint symbol constants and their
IDs. Two functions, getzintsymbolconstant(integer) and getzintsymbolid(text) can be
used to make passing barcode names to the generation function easier.
Prior to version 0.2.0 (0.1.4 and lower), pgzint used Zint to render the barcode as a BMP in
memory, and then converted that bitmap to a PNG using libpng itself. Zint version 2.14.0 added
output option BARCODE_MEMORY_FILE, which will render the PNG image into memory directly
(previously, it would only render PNG to a file on disk). This option allows pgzint to drop
the manual PNG generation and greatly simplifies the extension.
As part of the bump to 0.2.0, several columns have been removed from the bc_symbols table.
They are: bc_symbol_dim bc_symbol_minlength bc_symbol_numeric bc_symbol_parity bc_symbol_checkdigit bc_symbol_notes
I added them because they felt useful at the time, but never once used them and the info is largely duplicate of their website.
Usage
To generate a QR code with default values:
SELECT bc_qrcode('SAMPLE');
Which is the equivalent of calling:
SELECT bc_generate('SAMPLE', 58, NULL, 2, 0, NULL, NULL, NULL, NULL, NULL, NULL, 14, NULL);
It will generate a barcode with Symbology 58, a scale factor of 2, and value 14 creates a 73x73 image
according to section 6.6.3 of the Zint docs. I felt these were
sane values, always feel free to call bc_generate directly with your own choices. bc_generate is the
only function directly implemented in C, the other convenience functions are just wrappers
for bc_generate.
Currently implemented convenience functions:
bc_qrcode(pinput text)
bc_excode39(pinput text)
bc_pdf417(pinput text)
bc_maxicode(pinput text)
bc_code128(pinput text)
Installation
To build it:
make
make installcheck
make install
If you are updating from a version prior to 0.2.0, after you make/make install issue the following to each database that has pgzint installed:
`ALTER EXTENSION pgzint UPDATE TO '0.2.0';`
If you encounter an error such as:
make: pg_config: Command not found
Be sure that you have pg_config installed and in your path. If you used a
package management system such as RPM to install PostgreSQL, be sure that the
-devel package is also installed. If necessary tell the build process where
to find it:
env PG_CONFIG=/path/to/pg_config make && make installcheck && make install
If you encounter an error such as:
ERROR: must be owner of database contrib_regression
You need to run the test suite using a super user, such as the default “postgres” super user:
make installcheck PGUSER=postgres
Once pgzint is installed, you can add it to a database. Connect to a database
as a super user and run:
CREATE EXTENSION pgzint;
Dependencies
The pgzint extension requires PostgreSQL 9.4 or greater and libzint compiled with PNG support.
Copyright and License
pgzint written by David Beauchamp, Released under the MIT license.
libzint license