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.
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"));
Okapi Barcode JARs are available for download from Maven Central.
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 jar
: Builds the JAR file.
gradlew uploadArchives
: Deploys to Maven Central (requires a modified gradle.properties file).
NOTE: The unit tests should all pass under Oracle JDK, but will probably not all pass under OpenJDK. The tests verify barcode rendering image output, and the output images generated by OpenJDK are a bit different from the output images generated by the Oracle JDK (because their 2D graphics and font subsystems are slightly different).