private static void generateCode128Barcode(String filePath, String code, Double height, Double moduleWidth, Double fontSize, Boolean isShowNo) {
File file = new File(filePath);
Code128Bean bean = new Code128Bean();
final int dpi = 150;
//barcode
bean.setModuleWidth(moduleWidth);
bean.setHeight(height);
bean.doQuietZone(true);
bean.setQuietZone(2);//两边空白区
bean.setVerticalQuietZone(0.5);
//human-readable
bean.setFontName("Helvetica");
bean.setFontSize(fontSize);
// 不展示单号
if (!isShowNo){
bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);
}
// bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);
OutputStream out = null;
try {
out = new FileOutputStream(file);
BitmapCanvasProvider canvas = new BitmapCanvasProvider(out,"image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
bean.generateBarcode(canvas, code);
canvas.finish();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}