Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置iText条码宽度?_Java_Itext_Barcode - Fatal编程技术网

Java 如何设置iText条码宽度?

Java 如何设置iText条码宽度?,java,itext,barcode,Java,Itext,Barcode,我需要设置iText生成的条形码的宽度。我正在使用以下代码: Barcode128 code128 = new Barcode128(); code128.setCode("P662130002"); code128.setBarHeight(80f); // great! but what about width??? java.awt.Image awtImage = code128.createAwtImage(Color.WHITE, Color.BLACK); 有没有办法在不缩放结

我需要设置iText生成的条形码的宽度。我正在使用以下代码:

Barcode128 code128 = new Barcode128();
code128.setCode("P662130002");
code128.setBarHeight(80f); // great! but what about width???

java.awt.Image awtImage = code128.createAwtImage(Color.WHITE, Color.BLACK);

有没有办法在不缩放结果图像的情况下设置宽度?

使用此设置条形码的宽度

code128.setX(10.0f) ;//  Sets the minimum bar width.
方法签名

public void setX(float x)

Sets the minimum bar width.

Parameters:
    x - the minimum bar width
编辑

public class BarCodeTest {

    public static void main(String[] a) throws FileNotFoundException, DocumentException {
        Barcode128 code128 = new Barcode128();
        code128.setCode("P662130002");
        code128.setBarHeight(80f); // great! but what about width???
        code128.setX(1f);
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("hello.pdf"));
        document.open();

        PdfContentByte cb = writer.getDirectContent();

        Image barcodeimage = code128.createImageWithBarcode(cb, Color.BLACK, Color.WHITE);
        document.add(barcodeimage);

        document.close();

    }

}

使用
setX(1f)的最小值可以看出区别。

我尝试过这个,但没有成功。对于code128.setX(50f)、code128.setX(300f)甚至code128.setX(500f),结果仍然相同。。