I am using barcode4j to generate some barcode image, which works fine.
But the UI team wanna me to write some service to return the barcode number in String for them for some strange reasons. I can't figure out how to do this.
Below is the code snippet for how to generate the Barcode Image.
final File outputFile = new File(folderPath + "/" + TgtCoreConstants.TARGET_BARCODE_FILE_PREFIX
+ orderId + BARCODE_FILENAME_EXTENSION);
OutputStream out = null;
try {
out = new FileOutputStream(outputFile);
final BitmapCanvasProvider canvas = new BitmapCanvasProvider(
out, BARCODE_MIME_TYPE, cncBarcodeDpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
bean.generateBarcode(canvas, (storeNumber + orderId));
canvas.finish();
}
catch (final FileNotFoundException e) {
LOG.error("Error while generating the barcode file for order: " + orderId, e);
throw new GenerateBarCodeFailedException(e);
}
catch (final IOException e) {
LOG.error("Error while generating the barcode file for order: " + orderId, e);
throw new GenerateBarCodeFailedException(e);
}
The above snippet tells barcode4j to encode, render as bitmap and write in
outputFile
the stringstoreNumber + orderId
, so the requested service needs just toIf you need to decode the barcode given just the
outputFile
, then look at the ZXing project.