Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
uk.org.okapibarcode:okapibarcode
Advanced tools
An open-source barcode generator written entirely in Java, supporting over 50 encoding standards including all ISO standards.
Okapi Barcode is an open-source barcode generator written entirely in Java, supporting over 50 encoding standards, including all ISO standards. Okapi Barcode is based on Zint, an open-source barcode encoding library developed in C, and builds on the years of work that have been invested in that project.
Okapi Barcode JARs are available for download from Maven Central.
To generate barcode images in your own code using the Okapi Barcode library, use one of the symbology classes linked above:
setContent(String)
, and thenCode128 barcode = new Code128();
barcode.setFontName("Monospaced");
barcode.setFontSize(16);
barcode.setModuleWidth(2);
barcode.setBarHeight(50);
barcode.setHumanReadableLocation(HumanReadableLocation.BOTTOM);
barcode.setContent("123456789");
int width = barcode.getWidth();
int height = barcode.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g2d = image.createGraphics();
Java2DRenderer renderer = new Java2DRenderer(g2d, 1, Color.WHITE, Color.BLACK);
renderer.render(barcode);
ImageIO.write(image, "png", new File("code128.png"));
If you'd like to use Okapi Barcode on the Android platform, the easiest approach is to use the
SVG renderer to render your barcode
to SVG, and then use a library like AndroidSVG to
draw the resultant SVG image on an Android Bitmap
or Canvas
:
Code128 barcode = new Code128();
barcode.setFontName("Monospaced");
barcode.setFontSize(16);
barcode.setModuleWidth(2);
barcode.setBarHeight(50);
barcode.setHumanReadableLocation(HumanReadableLocation.BOTTOM);
barcode.setContent("123456789");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
SvgRenderer renderer = new SvgRenderer(stream, 1, Color.WHITE, Color.BLACK, true);
renderer.render(barcode);
String content = new String(stream.toByteArray(), StandardCharsets.UTF_8);
SVG svg = SVG.getFromString(content);
svg.renderToCanvas(canvas);
To use the Swing GUI, just run the OkapiUI class. The GUI allows you to explore the supported barcode symbologies and test them with different configurations and data.
gradlew check
: Compiles and runs all quality checks, including the unit tests.
gradlew fuzz
: Runs barcode encoding fuzz tests using Jazzer.
gradlew jar
: Builds the JAR file.
gradlew publish
: Deploys to Maven Central (requires a modified gradle.properties file).
OkapiInputException
and OkapiInternalException
, to distinguish user vs. library errorsNullPointerException
when channel count not specifiedJava2DRenderer
HumanReadableAlignment
to TextAlignment
, move it to graphics
package (for Android users)setContent(byte[])
method for binary dataFAQs
Unknown package
We found that uk.org.okapibarcode:okapibarcode demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.