Fir*_*zen 5 java barcode itext
我需要设置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);
Run Code Online (Sandbox Code Playgroud)
有没有办法如何设置宽度而不缩放生成的图像?
用它来设置BarCode的宽度
code128.setX(10.0f) ;// Sets the minimum bar width.
Run Code Online (Sandbox Code Playgroud)
方法签名
public void setX(float x)
Sets the minimum bar width.
Parameters:
x - the minimum bar width
Run Code Online (Sandbox Code Playgroud)
编辑
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();
}
}
Run Code Online (Sandbox Code Playgroud)
使用最小值setX(1f);可以看出差异.
| 归档时间: |
|
| 查看次数: |
11785 次 |
| 最近记录: |