[英]how can i remove text from barcode image in javascript or typescript?
这是我的 html
<div class="pr-2" style="width: 130px">
<div *ngIf="!element.editing" >
<span class="ss">{{element.barcode}}</span>
</div>
<div *ngIf="element.editing" >
<input type="text" [(ngModel)]="element.barcode" style="width: 130px"/>
</div>
</div>
这是我的 css
.ss {
font-family: 'Libre Barcode 128 Text', cursive;
font-size: 22px;
}
这是我的 javascript function
barcodeGenerator(value){
let x = value
let i, j, intWeight, intLength, intWtProd = 0, arrayData = [];
let arraySubst = [ "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê" ];
/*
* Checksum Calculation for Code 128 B
*/
intLength = x.length;
arrayData[0] = 104; // Assume Code 128B, Will revise to support A, C and switching.
intWtProd = 104;
for (j = 0; j < intLength; j += 1) {
arrayData[j + 1] = x.charCodeAt(j) - 32; // Have to convert to Code 128 encoding
intWeight = j + 1; // to generate the checksum
intWtProd += intWeight * arrayData[j + 1]; // Just a weighted sum
}
arrayData[j + 1] = intWtProd % 103; // Modulo 103 on weighted sum
arrayData[j + 2] = 106; // Code 128 Stop character
const chr = parseInt(arrayData[j + 1], 10); // Gotta convert from character to a number
if (chr > 94) {
var chrString = arraySubst[chr - 95];
} else {
chrString = String.fromCharCode(chr + 32);
}
// document.getElementById(id).innerHTML =
return 'Ì' + // Start Code B
x + // The originally typed string
chrString + // The generated checksum
'Î'; // Stop Code
// return `<span class="ss">${x}</span>`;
}
这是 Output在这里输入图片描述
但我想隐藏/删除条形码下的文本。
像这样在这里输入图片描述
您应该使用其他条码字体,不带文本。
首先包括正确的网络字体:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Libre+Barcode+128">
然后更改 css:
.ss {
font-family: 'Libre Barcode 128', cursive;
font-size: 22px;
}
作为备选
将 html 更改为此(额外跨度):
<div class="pr-2" style="width: 130px">
<div *ngIf="!element.editing" >
<span class="ss"><span>{{element.barcode}}</span></span>
</div>
<div *ngIf="element.editing" >
<input type="text" [(ngModel)]="element.barcode" style="width: 130px"/>
</div>
</div>
和 css 到这个:
.ss span{
font-family: 'Libre Barcode 128 Text', cursive;
font-size: 22px;
display: inline-block;
transform: scaleY(3);
}
.ss {height: 22px;
overflow: hidden;
display: inline-block;
}
这将隐藏条形码下方的字母。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.