advhc39b字体库 怎么生成条形码

advhc39b字体库 怎么生成条形码
要求是这种的 现在在使用itextpdf生成pdf

img

public static void main(String[] args) {
        String data = "222520231000062197";
        String fileName = "生成图片.png";

        BufferedImage barcodeImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = barcodeImage.createGraphics();
        Font barcodeFont = new Font("AdvHC39B", Font.PLAIN, 30);
        g2d.setFont(barcodeFont);

        int barcodeWidth = g2d.getFontMetrics().stringWidth("*" + data + "*");
        barcodeImage = new BufferedImage(barcodeWidth + 20, 40, BufferedImage.TYPE_INT_RGB);
        g2d = barcodeImage.createGraphics();
        g2d.setFont(barcodeFont);

        g2d.drawString("*" + data + "*",10, 40);
        g2d.dispose();

        try {
            ImageIO.write(barcodeImage, "png", new File(fileName));
            System.out.println("条形码已生成:" + fileName);
        } catch (IOException ex) {
            System.err.println("无法生成条形码:" + ex.getMessage());
        }
    }